Ouvrir le menu principal

 Documentation[créer] [purger]
local p = {}
local generic = require('Module:Infobox/Fonctions')
local linguistic = require('Module:Linguistique')
local wikidata = require('Module:Wikidata')

local function dimensions( localdata )
	local dimensions = {
		-- paramètre, abréviation à afficher dans l'en tête, prorpriété Wikidata, nom complet à afficher dans l'entête, stop
		{'diamètre', '∅', 'P2386', 'Diamètre'},
		{'longueur', 'L', 'P2043', 'Longueur'},
		{'largeur', 'l', 'P2049', 'Largeur'},
		{'hauteur', 'H', 'P2048', 'Hauteur'},
	}
	local data, dims = {}, {}
	local label = 'Dimensions'
	local unit = localdata['unité'] or 'mm'
	
	local wikidataval = function(d)
		return wikidata.formatStatements{
			entity = localdata.item,
			showunit = '-',
			targetunit = unit,
			addcat = true,
			property = d
		}
	end
	local propertyused = nil
	
	for i, j in pairs(dimensions) do
		local val = localdata[j[1]]
		if localdata.item and j[3] and not val then
			val = wikidataval(j[3])
			if val then
				propertyused = j[3]
			end
		end
		if val then
			table.insert(data, val)
			table.insert(dims, i)
		end
	end
	if #data == 0 then
		return nil
	end
	if #data == 1 then
		label = dimensions[dims[1]][4] 
	else
		for i, j in pairs(dims) do dims[i] = dimensions[j][2] end
		label = label .. linguistic.inparentheses(linguistic.conj(dims, ' × '))
	end

	local val = linguistic.conj(data, ' × ') .. ' ' .. unit
	if propertyused then
		val = wikidata.formatAndCat{entity = localdata.item, property = propertyused, value = val}
	end
		
	return {
		type = 'mixed',
		label = label,
		value = function() return val end
	}
end

return {
	maincolor = '#00507F',
	parts = {
		generic.title(nil, {color = 'white'}),
		generic.mainimage('Article à illustrer Moteur'),
		{type = 'table', separator = true, rows = {
			{type = 'mixed',
				label = 'Autres noms',
				value = 'autres noms',
				},
			{type = 'mixed',
				label = 'Constructeur',
				plurallabel = 'Constructeurs',
				value = 'constructeur',
				wikidata = {property = 'P176', conjtype = '<br />'},
				},
			{type = 'mixed',
				label = 'Années de production',
				value = 'année',
				wikidata = function ( item ) return wikidata.mainDate(item) end,
				},
			{type = 'mixed',
				label = 'Production',
				value = 'quantité produite',
				property = 'P1092',
				},
			{type = 'mixed',
				label = 'Application',
				plurallabel = 'Applications',
				value = 'applications',
				property = 'P366',
				},
			},
		},
		{type = 'table', title = 'Caractéristiques techniques', titlestyle={color='white'}, rows = {
			{type = 'mixed',
				label = 'Cylindrée',
				plurallabel = 'Cylindrées',
				value = 'cylindrée',
				wikidata = {property = 'P2234', targetunit = 'cm3', rounding = '0'},
				},
			--{type = 'mixed',
				--label = 'Nombre de cylindres',
				--value = 'nombre cylindres',
				--property = 'P1100',
				--},
			{type = 'mixed',
				label = 'Disposition',
				value = 'disposition cylindres',
				property = 'P1002',
				},
			{type = 'mixed',
				label = 'Angle des cylindres',
				value = 'angle cylindres',
				},
			{type = 'mixed',
				label = 'Alésage',
				value = 'alésage',
				wikidata = {property = 'P2556', targetunit = 'mm', rounding = '2'},
				},
			{type = 'mixed',
				label = 'Course',
				value = 'course',
				wikidata = {property = 'P2557', targetunit = 'mm', rounding = '2'},
				},
			{type = 'mixed',
				label = 'Refroidissement',
				value = 'refroidissement',
				property = 'P588',
				},
			{type = 'mixed',
				label = 'Combustible',
				plurallabel = 'Combustibles',
				value = 'combustible',
				property = 'P618',
				},
			{type = 'mixed',
				label = 'Allumage',
				value = 'allumage',
				},
			},
		},
		{type = 'table', title = 'Performances', titlestyle={color='white'}, rows = {
			{type = 'mixed',
				label = 'Puissance max.',
				plurallabel = 'Puissances max.',
				value = 'puissance maximale',
				wikidata = {property = 'P2109', showqualifiers = {'P2052', 'P2044'}, targetunit = 'kw', conjtype = '<br />'},
				},
			{type = 'mixed',
				label = 'Couple max.',
				plurallabel = 'Couples max.',
				value = 'couple maximum',
				wikidata = {property = 'P2230', showqualifiers = {'P2052'}, targetunit = 'N', conjtype = '<br />'},
				},
			{type = 'mixed',
				label = 'Puissance massique',
				value = 'puissance massique',
				--wikidata = {}, -- peut se calculer en divisant la valeur P1100 par P2556
				},
			{type = 'mixed',
				label = 'Taux de compression',
				value = 'taux de compression',
				wikidata = function ( item )
					local claims = wikidata.getClaims{
						entity = item,
						property = 'P1247',
						conjtype = '<br />',
					}
					if not claims then
						return nil
					end
					return wikidata.formatAndCat{
						entity = item,
						property = 'P1247',
						linktopic = ':55-',
					} .. ':1'
					end,
				},
			{type = 'mixed',
				label = 'Consommation',
				value = 'consommation'
				},
			},
		},
		{type = 'table', title = 'Dimensions', titlestyle={color='white'}, rows = {
			dimensions,
			{type = 'mixed',
				label = 'Masse',
				plurallabel = 'Masses',
				value = 'masse',
				wikidata = {property = 'P2067', targetunit = 'kg', rounding = '2'},
				},
			},
		},
		{type = 'navbox',
			separated = true,
			color = 'default',
			previousparameter = 'moteur précédent',
			previouswikidata = {property = 'P155', excludespecial = true},
			nextparameter = 'moteur suivant',
			nextwikidata = {property = 'P156', excludespecial = true}
			},
		},
	}