Module:Sandbox/Habst/Athletics results year

This is the current revision of this page, as edited by imported>Habst at 20:43, 4 July 2019 (save). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
p = {}

local P_POINTINTIME = 'P585'
local P_PARTICIPANTOF = 'P1344'
local P_SPORTSDISCIPLINE = 'P2416'
local P_COUNTRY = 'P17'
local P_PARTOF = 'P361'
local P_RANKING = 'P1352'

local P_RACETIME = 'P2781'
local P_POINTS = 'P1358'
local P_DISTANCE = 'P2043'
local marks = { P_RACETIME, P_POINTS, P_DISTANCE }

p.athleticsResults = function(frame)
	local qid = frame.args[1]
	local yearArg = frame.args[2]
	local ent = mw.wikibase.getEntity(qid)
	local participantOfClaims = ent['claims'][P_PARTICIPANTOF]
	local output = ''
	output = output .. '|-\n'
	output = output .. '|colspan=11 style="text-align:center; margin:0; padding:0;"|\n'
	output = output .. '{| class="wikitable mw-collapsible mw-collapsed" border="1" style="border-collapse:collapse; width:100%; margin:0;"\n'
	output = output .. '!colspan=11|2001\n'
	for i, pc in ipairs(participantOfClaims) do
		mw.logObject(mw.wikibase.renderSnak(pc['mainsnak']))
		if pc['qualifiers'] then
			local fulldate = pc['qualifiers'][P_POINTINTIME][1]['datavalue']['value']['time']
			local year = fulldate:sub(2, 5)
			if year == yearArg then
				local markProperty = nil
				for j, pm in ipairs(marks) do
					if pc['qualifiers'][pm] then
						markProperty = pm
					end
				end
				local mark = mw.wikibase.renderSnak(pc['qualifiers'][markProperty][1]):match('([^±]*)')
				--local meetname = mw.wikibase.renderSnak(pc['mainsnak'])
				output = output .. '|-\n'
				output = output .. '|style="width:5%;"|' .. fulldate:sub(7, 11)
				local meetname = mw.wikibase.renderSnak(pc['qualifiers'][P_PARTOF][1])
				output = output .. '||style="width:30%;"|' .. meetname
				local country = mw.wikibase.renderSnak(pc['qualifiers'][P_COUNTRY][1])
				output = output .. '||style="width:10%;"|' .. country
				output = output .. '||style="width:5%;"|' .. 'F'
				local discipline = mw.wikibase.renderSnak(pc['qualifiers'][P_SPORTSDISCIPLINE][1])
				output = output .. '||style="width:10%;"|' .. discipline
				output = output .. '||style="width:5%;"|' .. 'SF2'
				local ranking = 'NR'
				if pc['qualifiers'][P_RANKING] then
					ranking = pc['qualifiers'][P_RANKING][1]['datavalue']['value']['amount']:sub(2)
				end
				output = output .. '||style="width:5%;"|' .. ranking
				output = output .. '||style="width:5%;"|' .. mark
				output = output .. '||style="width:5%;"|' .. '<small>0.0</small>'
				output = output .. '\n'
			end
		end
	end
	return output
end
return p