Module:Sandbox/Habst/Athletics results

p = {}

local P_POINTINTIME = 'P585' local P_PARTICIPANTOF = 'P1344' local P_SPORTSDISCIPLINE = 'P2416'

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 ent = mw.wikibase.getEntity(qid) local participantOfClaims = ent['claims'][P_PARTICIPANTOF] local years = {} local output = '' output = output .. '{| class="wikitable mw-collapsible" border="1" style="border-collapse:collapse; width:100%; font-size:90%;"\n' output = output .. '!colspan=11|Results for Usain Bolt\n' output = output .. '|-\n' output = output .. '!scope="col" style="width:5%;"|Date!!scope="col" style="width:20%;"|Meeting!!scope="col" style="width:10%;"|Location!!scope="col" style="width:10%;"|Ctry.!!scope="col" style="width:5%;"|Cat.!!scope="col" style="width:10%;"|Event!!scope="col" style="width:5%;"|H!!scope="col" style="width:5%;"|Pl.!!scope="col" style="width:10%;"|Perf.!!scope="col" style="width:5%;"|W!!scope="col" style="width:5%;"|N\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) local serialized = fulldate -- e.g. "+2017-06-28T00:00:00Z" 21 characters long if pc['qualifiers'][P_SPORTSDISCIPLINE] then serialized = serialized .. '\'\'\'' .. mw.wikibase.renderSnak(pc['qualifiers'][P_SPORTSDISCIPLINE][1]) .. ':\'\'\' '			end local markProperty = nil for j, pm in ipairs(marks) do				if pc['qualifiers'][pm] then markProperty = pm				end end if markProperty ~= nil then -- mw.logObject(pc['qualifiers'][markProperty]) serialized = serialized .. mw.wikibase.renderSnak(pc['qualifiers'][markProperty][1]):match('([^±]*)') end meetname = mw.wikibase.renderSnak(pc['mainsnak']) if meetname ~= 'no value' then serialized = serialized .. ' at ' .. meetname .. '' end if not years[year] then years[year] = {} end table.insert(years[year], serialized) end end yearsort = {} for n in pairs(years) do table.insert(yearsort, n) end table.sort(yearsort) for i, year in ipairs(yearsort) do		--results = years[year] --ressort = {} --for k, v in pairs(results) do table.insert(ressort, v) end --table.sort(ressort) 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|' .. year .. '\n' for i, res in ipairs(years[year]) do output = output .. '|-\n' output = output .. '|style="width:5%;"|' .. res:sub(7,11) output = output .. '||style="width:20%;"|test' .. '||style="width:10%;"|Kingston||style="width:10%;"|Jamaica||style="width:5%;"|F' output = output .. '||style="width:10%;"|' .. '200 m' output = output .. '||style="width:5%;"|SF2||style="width:5%;"|1||style="width:10%;"|22.08||style="width:5%;"|0.0||style="width:5%;"|PB\n' -- output = output .. ' | ' .. res:sub(22) .. '\n' end output = output .. ' |}\n' end output = output .. '|}\n' return output end return p