Benutzer:Guternachbar/Spielwiese/Modul:Vorlage:Tennisturniere-Dameneinzel
Erscheinungsbild
local p = {}
local function getCell(championships, tournament, year, result)
local cell local link
link = championships .. ' ' .. year if tournament and tournament ~= then link = link .. '/' .. tournament end
if result == '-' then result = '–' end
if result == 'S' then cell = mw.html.create('td'):wikitext('S'):css('background-color', '#FFF68F'):css('font-weight', 'bold') elseif result == 'F' then cell = mw.html.create('td'):wikitext('F'):css('background-color', '#BFEFFF') elseif result == 'HF' then cell = mw.html.create('td'):wikitext('HF'):css('background-color', '#FFE7BA') elseif result == ' ' or not result then cell = mw.html.create('td'):wikitext(' ') else cell = mw.html.create('td'):wikitext('' .. result .. '') end
return tostring(cell)
end
local function isUsed(frame, firstYear, lastYear, prefix)
local used=false local year
for year = firstYear, lastYear do if frame:getParent().args[prefix .. year] then used = true
break
end end
return used
end
local function wasHeld(championships, tournament, year)
local held = false
if championships == 'Australian Open' then held = true elseif championships == 'French Open' then held = true elseif championships == 'Wimbledon Championships' then if year ~= 2020 then held = true end elseif championships == 'US Open' then held = true elseif championships == 'WTA Championships' then if year ~= 2020 then held = true end elseif championships == 'WTA Chicago' then if year == 1990 then held = true end elseif championships == 'WTA Boca Raton' then if year >= 1989 and year < 1993 then held = true end elseif championships == 'Qatar Total Open' then if year > 2000 and year ~= 2009 and year ~= 2010 then held = true end elseif championships == 'Dubai Duty Free Tennis Championships' then if year > 2001 then held = true end end
return held
end
local function differentCategory(championships, tournament, year)
local diff = true
if championships == 'Australian Open' or championships == 'French Open' or championships == 'Wimbledon Championships' or championships == 'US Open' then diff = false elseif championships == 'WTA Championships' then diff = false elseif championships == 'WTA Chicago' then if year >= 1990 then diff = false end elseif championships == 'Qatar Total Open' then if year == 2008 or (year >= 2012 and year <= 2014) or (year > 2015 and (year % 2) == 0) then diff = false end elseif championships == 'Dubai Duty Free Tennis Championships' then if (year >= 2009 and year <= 2011) or (year >= 2015 and (year % 2) == 1) then diff = false end end
return diff
end
local function getRow(frame, overviewArticle , bgColor, prefix, championships, tournament, firstYear, lastYear)
local row local sum local year local result
row = mw.html.create('tr'):css('background-color', bgColor) row:node(mw.html.create('td'):wikitext('' .. overviewArticle .. ''):css('text-align', 'left')) sum = 0 for year = firstYear, lastYear do if wasHeld(championships, tournament, year) then if differentCategory(championships, tournament, year) then
cell = mw.html.create('td'):wikitext('a. K.') else
result = frame:getParent().args[prefix .. year] or cell = getCell(championships, tournament, year, result) if (result == 'S') then sum = sum + 1 end
end
else cell = mw.html.create('td'):wikitext('n. a.') end row:node(cell) end row:node(mw.html.create('td'):wikitext(sum))
return row
end
function p.TennisturniereDameneinzel(frame)
local firstYear = frame:getParent().args['ErstesJahr'] local lastYear = frame:getParent().args['LetztesJahr'] local result local table local head local row local year
if not firstYear or not lastYear then return 'Die Parameter ErstesJahr und LetztesJahr sind mandatory!' end
-- create wikitable table = mw.html.create('table'):addClass('wikitable'):css('text-align', 'center')
-- create table header and fill with links to all relevant WTA Tour articles head = mw.html.create('tr') head:node(mw.html.create('th'):wikitext('Turnier')) for year = firstYear, lastYear do head:node(mw.html.create('th'):wikitext('' .. year .. '')) end head:node(mw.html.create('th'):wikitext('Gesamt'))
-- add header to table table:node(head):newline()
if isUsed(frame, firstYear, lastYear, 'AUO') then table:node(getRow(frame, 'Australian Open', '#E5D1CB', 'AUO', 'Australian Open', 'Dameneinzel', firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'FRO') then table:node(getRow(frame, 'French Open', '#E5D1CB', 'FRO', 'French Open', 'Dameneinzel', firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'WIM') then table:node(getRow(frame, 'Wimbledon Championships', '#E5D1CB', 'WIM', 'Wimbledon Championships', 'Dameneinzel', firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'USO') then table:node(getRow(frame, 'US Open', '#E5D1CB', 'USO', 'US Open', 'Dameneinzel', firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'WTC') then table:node(getRow(frame, 'WTA Tour Championships', '#FFFFCC', 'WTC', 'WTA Championships', , firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'CHI') then table:node(getRow(frame, 'WTA Chicago', '#696969', 'CHI', 'Virginia Slims of Chicago', , firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'BOC') then table:node(getRow(frame, 'WTA Boca Raton', '#F7F8FF', 'BOC', 'Virginia Slims of Florida', , firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'DOH') then table:node(getRow(frame, 'WTA Doha', '#F7F8FF', 'DOH', 'Qatar Total Open', , firstYear, lastYear)):newline() end
if isUsed(frame, firstYear, lastYear, 'DUB') then table:node(getRow(frame, 'WTA Dubai', '#F7F8FF', 'DUB', 'Dubai Duty Free Tennis Championships', , firstYear, lastYear)):newline() end
return tostring(table)
end
return p