Jump to content

Module:Grand Slam Track/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix slams
combine slam/rg
Line 23: Line 23:
local output = ''
local output = ''
output = output .. '|-\n'
output = output .. '|-\n'
output = output .. '!scope="col" | Slam !!scope="col" | Race group !!scope="col" | Event !!scope="col" | <abbr title="Place">Pl.</abbr> !!scope="col" | Time\n'
output = output .. '!scope="col" | Slam !!scope="col" | Event !!scope="col" | <abbr title="Place">Pl.</abbr> !!scope="col" | Time\n'
local slamSet = {}
local slamSet = {}
Line 31: Line 31:


for i, pc in ipairs(participantOfClaims) do
for i, pc in ipairs(participantOfClaims) do
local mainsnak = pc.mainsnak
local mainsnak = pc.mainsnak


-- mw.logObject(mw.wikibase.renderSnak(pc['mainsnak']))
-- mw.logObject(mw.wikibase.renderSnak(pc['mainsnak']))
if mainsnak.snaktype == 'value' and slamSet[mainsnak.datavalue.value.id] and pc['qualifiers'] then
if mainsnak.snaktype == 'value' and slamSet[mainsnak.datavalue.value.id] and pc['qualifiers'] then
local qs = pc['qualifiers']
local qs = pc['qualifiers']
output = output .. '|-\n'
output = output .. '|-\n'
output = output .. '| '
output = output .. '| '


-- Slam
-- Slam
output = output .. 'rowspan=2| '
output = output .. 'rowspan=2| '
output = output .. '[[' .. mw.wikibase.renderSnak(pc['mainsnak']) .. ']]'
output = output .. '[[' .. mw.wikibase.renderSnak(pc['mainsnak']) .. ']]'
output = output .. ' || '


-- Race group
-- Race group
if qs[P_COMPETITIONCLASS] then
output = output .. 'rowspan=2| '
if qs[P_COMPETITIONCLASS] then
local cc = mw.wikibase.renderSnak(qs[P_COMPETITIONCLASS][1])
output = output .. '\n'
local cc = mw.wikibase.renderSnak(qs[P_COMPETITIONCLASS][1])
output = output .. cc:sub(1, 1):upper() .. cc:sub(2)
output = output .. cc:sub(1, 1):upper() .. cc:sub(2)
end
end
output = output .. '\n'
output = output .. '\n'


for j = 1,2 do
for j = 1,2 do
-- Event
-- Event
output = output .. '| '
output = output .. '| '
if qs[P_SPORTSDISCIPLINE] and qs[P_SPORTSDISCIPLINE][j] then
if qs[P_SPORTSDISCIPLINE] and qs[P_SPORTSDISCIPLINE][j] then
output = output .. mw.wikibase.renderSnak(qs[P_SPORTSDISCIPLINE][j])
output = output .. mw.wikibase.renderSnak(qs[P_SPORTSDISCIPLINE][j])
end
end
output = output .. ' || '
output = output .. ' || '


-- Place
-- Place
if qs[P_RANK] and qs[P_RANK][j] then
if qs[P_RANK] and qs[P_RANK][j] then
output = output .. mw.wikibase.renderSnak(qs[P_RANK][j])
output = output .. mw.wikibase.renderSnak(qs[P_RANK][j])
end
end
output = output .. ' || '
output = output .. ' || '
-- Time
-- Time
if qs[P_RACETIME] and qs[P_RACETIME][j] then
if qs[P_RACETIME] and qs[P_RACETIME][j] then
output = output .. mw.wikibase.renderSnak(qs[P_RACETIME][j])
output = output .. mw.wikibase.renderSnak(qs[P_RACETIME][j])
end
end
output = output .. '\n|-\n'
output = output .. '\n|-\n'
end
end
end
end
end
end
output = output .. '|}\n'
output = output .. '|}\n'

Revision as of 15:07, 5 April 2025

p = {}

local P_POINTINTIME = 'P585'
local P_PARTICIPANTOF = 'P1344'
local P_SPORTSDISCIPLINE = 'P2416'
local P_COMPETITIONCLASS = 'P2094'
local P_RANK = 'P1352'
local P_RACETIME = 'P2781'

local Q_SHORTSPRINTS = 'Q133805007'
local Q_LONGSPRINTS = 'Q133805012'
local Q_SHORTHURDLES = 'Q133805023'
local Q_LONGHURDLES = 'Q133805093'
local Q_SHORTDISTANCE = 'Q133805111'
local Q_LONGDISTANCE = 'Q133805125'

local slams = {'Q133804597'} -- in chronological order

p.gst = function(frame)
  local qid = frame.args[1]
  local ent = mw.wikibase.getEntity(qid)
  local participantOfClaims = ent['claims'][P_PARTICIPANTOF] or {}
  local output = ''
  output = output .. '|-\n'
  output = output .. '!scope="col" | Slam !!scope="col" | Event !!scope="col" | <abbr title="Place">Pl.</abbr> !!scope="col" | Time\n'
  
  local slamSet = {}
  for _, slamQid in ipairs(slams) do
      slamSet[slamQid] = true
  end

  for i, pc in ipairs(participantOfClaims) do
    local mainsnak = pc.mainsnak

    -- mw.logObject(mw.wikibase.renderSnak(pc['mainsnak']))
    if mainsnak.snaktype == 'value' and slamSet[mainsnak.datavalue.value.id] and pc['qualifiers'] then
      local qs = pc['qualifiers']
      output = output .. '|-\n'
      output = output .. '| '

      -- Slam
      output = output .. 'rowspan=2| '
      output = output .. '[[' .. mw.wikibase.renderSnak(pc['mainsnak']) .. ']]'

      -- Race group
      if qs[P_COMPETITIONCLASS] then
        local cc = mw.wikibase.renderSnak(qs[P_COMPETITIONCLASS][1])
        output = output .. '\n'
        output = output .. cc:sub(1, 1):upper() .. cc:sub(2)
      end
      output = output .. '\n'

      for j = 1,2 do
        -- Event
        output = output .. '| '
        if qs[P_SPORTSDISCIPLINE] and qs[P_SPORTSDISCIPLINE][j] then
          output = output .. mw.wikibase.renderSnak(qs[P_SPORTSDISCIPLINE][j])
        end
        output = output .. ' || '

        -- Place
        if qs[P_RANK] and qs[P_RANK][j] then
          output = output .. mw.wikibase.renderSnak(qs[P_RANK][j])
        end
        output = output .. ' || '
            
        -- Time
        if qs[P_RACETIME] and qs[P_RACETIME][j] then
          output = output .. mw.wikibase.renderSnak(qs[P_RACETIME][j])
        end
        output = output .. '\n|-\n'
      end
    end
  end
  output = output .. '|}\n'
  return output
end
return p