Modul:Sportdata
Utseende
Dokumentation [visa] [redigera] [historik] [rensa sidcachen]
Detta är en hjälpmodul som innehåller funktioner som används av flera andra moduler, som :
För att använda funktionerna behöver du skriva require( 'Modul:Sportdata') i modulen som använder funktionerna. Modulen utnyttjar själv modulerna Modul:Sportdata localisation (för att underlätta översättning till andra språk ligger alla textsträngar som är språkberoende här), Modul:Sportdata rankings (ranking för olika idrottstävlingar för att t.ex. prioritera VM & OS högre än spel i lägre divisionerna i den nationella ligan) samt Modul:Referenshantering (för att visa referenser).
Funktioner[redigera wikitext]
competitionData[redigera wikitext]
isClub[redigera wikitext]
- Syfte: Avgöra om en entitet är en klubb (till skillnad från ett landslag)
- Returnerar: sant/falskt
- Argument:
- id – id (Q följt av ett nummer, som t.ex. 'Q3149147') för för det objekt som du vill testa ifall den är en klubb (t.ex. Imoco Volley (Q3149147))
- txtProperty – den egenskap som du vill använda för utvärderingen. Ska sättas till 'P31' (instans av (P31)) vid anrop (däremot anropar funktionen sig själv med underklass till (P279))
- Vad funktionen gör: funktionen loopar igenom alla värden för objektets instans av (P31).
- Om landslag (Q1194951) returnerar den falskt.
- Om idrottsförening (Q847017), idrottslag (Q12973014), volleybollklubb (Q108395614) eller multisportklubb (Q13580678) returnerar den sant
- Om den har något annat värde anropar den funktionen sig själv för att undersöka om värdet är en underklass till (P279) till något av de ovanstående.
isNationalTeam[redigera wikitext]
- Syfte: Avgöra om en entitet är ett landslag (till skillnad från en klubb)
- Returnerar: sant/falskt
- Argument:
- id – id (Q följt av ett nummer, som t.ex. 'Q3873841') för det objekt som du vill testa ifall den är ett landslag (t.ex. Sveriges damlandslag i volleyboll (Q3873841))
- txtProperty – den egenskap som du vill använda för utvärderingen. Ska sättas till 'P31' (instans av (P31)) vid anrop (däremot anropar funktionen sig själv med underklass till (P279))
- Vad funktionen gör: funktionen loopar igenom alla värden för objektets instans av (P31).
- Om dess värde är landslag (Q1194951) returnerar den sant.
- Om den har något annat värde anropar den funktionen sig själv för att undersöka om värdet är en underklass till (P279) till landslag (Q1194951)
processDates[redigera wikitext]
tblSeasonData[redigera wikitext]
tblTeamInfo[redigera wikitext]
txtDate[redigera wikitext]
txtPosition[redigera wikitext]
- Syfte: Skapa tabellcell med en person/ett lags placering i en tävling, som är färgsatt om de kom på medaljplats
- Returnerar: textsträng (html-kod för cellen)
- Argument:
- iPosition – placeringen i tävlingen
- Vad funktionen gör:
- Skapar en tabellcell med placering
- Placeringen är 1 (█), 2 (█) eller 3 (█) får cellen respektive färg, annars ingen bakgrund.
txtTeamname[redigera wikitext]
- Syfte: Avgöra namnet på ett lag under ett visst år
- Returnerar: textsträng (lagnamnet som wikilänk)
- Argument:
- idTeam – id (Q följt av ett nummer, som t.ex. 'Q3873841' för Sveriges damlandslag i volleyboll (Q3873841)) för lagets objekt
- year – årtalet för vilket du vill veta klubbens namn
- Vad funktionen gör: undersöker klubbens officiellt namn (P1448). Om det är satt loopar den igenom alla värden
- Om värdet har bestämningarna att
- startdatum (P580) <= year och det inte finns slutdatum (P582)
- startdatum (P580) <= year och slutdatum (P582) >= year
- Det inte fanns startdatum (P580) och slutdatum (P582) >= year,
- så returnerar funktionen det värdet (namnet) för den bestämningen
- ett undantag är om namnet är tomt (nil) då returnerar funktionen istället 'Namn ej inlagt på svenska än'
- Om funktionen inte hittar något värde där bestämningarna uppfyller villkoren ovan returnerar funktionen 'Namn finns inte för det årtalet'
- Om värdet har bestämningarna att
txtYears[redigera wikitext]
- Syfte: Formatera en textsträng med start- och/eller slutår
- Returnerar: textsträng
- Argument:
- startyear – startår (kan vara tom)
- endyear – slutår (kan vara tom)
- Vad funktionen gör (returnerar):
- Om både startyear och endyear finns:
- Om de är olika: returnerar startyear–endyear
- Om de är samma: returnerar startyear
- Om startyear finns, men inte endyear: returnerar startyear–
- Om endyear finns, men inte startyear: returnerar –endyear
- Om var sig startyear eller endyear finns: returnerar tom sträng
- Om både startyear och endyear finns:
years[redigera wikitext]
local wd = require( 'Modul:Sportdata localisation' )
local wd = require( 'Modul:Sportdata rankings' )
local wd = require( 'Modul:Referenshantering' )
--Artiklar som använder modul Sportdata och person/klubb deltar i tävling som saknar P3450
function competitionData(tbl,claimsIndividualCompetition)
--Get the id of the reoccuring sports event
tbl.iLeague=read(claimsIndividualCompetition[1],'id')
--Get name of the reoccuring sports event
tbl.txtLeague=txtWikilinkWOsitelink(tbl.iLeague)
--Get its rank (lower number = more status)
tbl.iCompetionRank=CompetitionDb[tbl.iLeague]
--If the reoccuring sports event has no stored rank number give it a very high one (= low status)
if (tbl.iCompetionRank==nil) then
tbl.iCompetionRank=999999
end
--Get competition class (i.e. women's football, men's basketball etc.)
local claimsType = mw.wikibase.getBestStatements(tbl.iLeague,'P2094' )
if (next(claimsType)) then
tbl.iCompetitionType=read(claimsType[1],'id')
claimsUnderclass = mw.wikibase.getAllStatements(tbl.iLeague,'P279' )
tbl.iGender=0
for key, value in pairs( claimsUnderclass ) do
local iObject=read(claimsType[1],'id')
if (iObject=="Q35555522") then
tbl.iGender=1
end
if (iObject=="Q920057") then
tbl.iGender=2
end
end
tbl.iSport = mw.wikibase.getAllStatements(tbl.iLeague,'P641' )
end
return tbl
end
function tblSeasonData(frame,tbl,valueParticipitation,entityid,bIndividual)
tbl.iStatus=1 -- Everything ok
--Default values if nothing found
tbl.iCompetitionType="Q0"
tbl.txtDateFrom=''
tbl.txtDateTo=''
--Check wether the object is an instance of a reoccuring sports event, a qualification event or not at all sports related
local claimsMainorQualifier = mw.wikibase.getBestStatements(tbl.iSeason, 'P31' )
tbl.bMainOrQualifier='-' -- Defaults to not being a competition-- Defaults to not being a competition (as P1344, that is usually used to call the function can cover a lot of things, not just sports events)
bFoundQualification=false -- Check if found qualification (will take priority of instance of both Q27020041 and Q2122052/Q51036091 )
--Loop through instances statements
for key, value in pairs( claimsMainorQualifier ) do
iInstanceOf=read(value,'id')
--If a main competition
if (not(bFoundQualification) and ((iInstanceOf=='Q27020041') or (iInstanceOf=='Q114609228') or (iInstanceOf=='Q18536594') or (iInstanceOf=='Q51031626') or (iInstanceOf=='Q26132862'))) then
tbl.bMainOrQualifier='M' -- Main competition
end
--If a qualifier
if ((iInstanceOf=='Q2122052') or (iInstanceOf=='Q51036091')) then
--Set as qualifier in table
tbl.bMainOrQualifier='Q'
--Get references
tbl.hasref,tbl.ref=tblProcessAllRefsForItemWD(frame,value['references'],entityid,'P1344')
--Look for statement for what it qualifies for and set that as the main competiton
claimsMainCompetition=mw.wikibase.getAllStatements(tbl.iSeason, 'P3085' )
iMainCompetition=read(claimsMainCompetition[1],'id')
-- If there is data on what it qualifies for set that as the sports event (so for example a qualification for a world championship will be shown in the same way as the world championship itself (but with qualitifcation rather than position as result)
if not isempty(iMainCompetition) then
tbl.iSeason=iMainCompetition
end
-- Set that a relevant reoccuring sports event has been found and stop looking for one
bFoundQualification=true
end
tbl.instanceof=read(claimsMainorQualifier[1],'id')
end
--Get the claim for the reoccuring sports event
local claimsCompetition = mw.wikibase.getBestStatements(tbl.iSeason, 'P3450' )
if (claimsCompetition[1]) then -- Has a link to leauge (from the individual season)
if (not (tbl.bMainOrQualifier=='Q')) then
tbl.bMainOrQualifier='M'
end
--Fill tbl with data about the reoccuring sports event (rather than the individual season)
tbl=competitionData(tbl,claimsCompetition)
else
--If no claim found try for a season that it might be part of instead (for example if there is a joint entity for all competitions independent of gender)
bFoundCompetition=false --Start with setting that nothing has been found
local claimsCompetition2
local claimsCompetitionSeasonPartOf = mw.wikibase.getBestStatements(tbl.iSeason, 'P361' )
--If part of another reoccuring sports event
if (claimsCompetitionSeasonPartOf[1]) then
iCompetitionSeasonPartOf=read(claimsCompetitionSeasonPartOf[1],'id')
claimsCompetition2 = mw.wikibase.getBestStatements(iCompetitionSeasonPartOf, 'P3450' )
bFoundCompetition=true
end
if (bFoundCompetition and claimsCompetition2[1]) then -- Part of a reoccuring sports event (from the individual season)
tbl=competitionData(tbl,claimsCompetition2)
else
--If neither instance of Q27020041 nor has a statement for P3450 -> assume not a sports competiton at all
tbl.iCompetionRank=999999
--If bMainOrQualifier still is its default value ('-'), it is not considered a sports results (might be a person participating in anything)
if (tbl.bMainOrQualifier=='-') then
tbl.iStatus=99 -- Return with a status that makes sure it is not considered a sports result
tbl.txtSeason=''
tbl.txtLeague=''
tbl.edit=''
tbl.hasref=false
tbl.ref=''
return tbl
else
-- Sportsevent, but not part of a reoccuring sports event -> fill with information about the error (assuming all sports events are reoccuring and not one-off events at the moment)
txtRefTmp=txtClickToAddCompetitionType .. ' [https://www.wikidata.org/wiki/' .. tbl.iSeason .. ' ' .. txtHere .. '].' .. txtaddWikiData(txtProperty3450,'tävlingstyp',txtExplanationProperty3450)
tbl.txtLeague=txtCompetitionTypeNotSet.. frame:extensionTag("ref", txtRefTmp) .. '[[' .. txtCategory .. ':' .. txtErrorCompetitionWithoutP3450 .. ']]'
tbl.iCompetitionType="Q1"
tbl.iStatus=2
end
end
end
bFounddates,tbl.txtDateFrom,tbl.txtDateTo,tbl.txtYearFrom,tbl.txtSeason=processDates(tbl.iSeason)
if not bFounddates then
--If no start year check for era
p2348=mw.wikibase.getAllStatements(tbl.iSeason, 'P2348' ) -- Om tidsperiod
if (next(p2348)) then
bFounddates,tbl.txtDateFrom,tbl.txtDateTo,tbl.txtYearFrom,tbl.txtSeason=processDates(read(p2348[1],'id') )
end
end
if not bFounddates then
p585=mw.wikibase.getAllStatements(tbl.iSeason,'P585' ) -- Om tidsperiod
if (next(p585)) then
tbl.txtDateFrom=read(p585[1],'time')
tbl.txtDateTo=tbl.txtDateFrom
tbl.txtYearFrom=string.sub(tbl.txtDateTo,2,5)
tbl.txtSeason=tbl.txtYearFrom
else
-- If neither startyear nor era, do not try do display more detailed information, just display information about the season of the league
tbl.txtSeason=txtWikilink(tbl.iSeason)
if not tbl.iStatus==2 then
-- If part of reoccuring sportsevent, but lack start/end info
tbl.iStatus=3
else
-- If not part of reoccuring sportsevent set error message
tbl.txtSeason=txtDateMissing .. '[[' .. txtCategory .. ':' .. txtGeneralError .. ']]'
end
end
end
iPositionDirect=getProperty(valueParticipitation,'P1352')
iPartner=getPropertyId(valueParticipitation,'P1706')
if (iPartner==nil) then
iPartner=getPropertyId(valueParticipitation,'P1327')
end
--If a main competition the position was not set directly in the statement using P1352
if ((tbl.bMainOrQualifier=='M') and iPositionDirect==nil or (bIndividual and iPartner==nil)) then
--Depending on if it is a competition for individuals or teams different properties should be used (P710/P1923) to list the participants
if (bIndividual) then
txtPropertyForParticipation='P710' --individuals
-- claimParticipants=mw.wikibase.getAllStatements(tbl.iSeason, txtPropertyForParticipation ) --individuals
iThisParticipant=tbl.iPlayer
else
txtPropertyForParticipation='P1923' --teams
iThisParticipant=tbl.iTeam
end
-- events
claimParticipants=mw.wikibase.getAllStatements(tbl.iSeason,txtPropertyForParticipation)
txtPos=''
tbl.hasref=0
tbl.ref=''
--Loop through participants of the event until find the particpant for which this function was called
for key, value in pairs(claimParticipants ) do
--Read participant id
iParticipantLoop=read(value,'id')
--Check if it is the same one as for which the function was called
if (iParticipantLoop==iThisParticipant) then
if (value.qualifiers) then
txtPos=string.sub(readQualifier(value.qualifiers.P1352[1],'amount'),2,-1)
--If individual look for any people that they played with (for example when people play in pairs)
if (bIndividual and value.qualifiers.P1327) then
iPartner=readQualifier(value.qualifiers.P1327[1],'id')
else
if (bIndividual and value.qualifiers.P1706) then
iPartner=readQualifier(value.qualifiers.P1706[1],'id')
end
end
end
tbl.hasref,tbl.ref=tblProcessAllRefsForItemWD(frame,value['references'],tbl.iSeason,txtPropertyForParticipation)
break
end
end
tbl.iPosition=txtPos
-- tmphasref,tmpref=tblProcessAllRefsForItemWD(frame,valueParticipitation['references'],entityid,'P1344')
tmphasref=0
tmpref=''
if ((tbl.hasref==1) and (tmphasref==1)) then
tbl.ref=mergeTables(tbl.ref,tmpref)
end
if ((tbl.hasref==1) and (tmphasref==0)) then
--do nothing
end
if ((tbl.hasref==0) and (tmphasref==1)) then
tbl.hasref=1
tbl.ref=tmpref
end
if ((tbl.hasref==0) and (tmphasref==0)) then
tbl.hasref=0
tbl.ref=tmpref
end
else
tbl.iPosition=iPositionDirect
tbl.hasref,tbl.ref=tblProcessAllRefsForItemWD(frame,valueParticipitation['references'],entityid,'P1344')
end
-- If qualifier
if (tbl.bMainOrQualifier=='Q') then
tbl.iPosition=999998
end
if (bIndividual and iPartner) then
tbl.txtTeam=txtTogetherWith .. txtWikilink(iPartner,'id')
end
tbl.edit=txtEditPen(entityid,valueParticipitation.id)
return tbl
end
function txtPosition(iPosition,txtIsQualifier)
local bMedal=0
if (iPosition==999999) then
iPosition=nil
end
if (iPosition==999998) then
iPosition=txtQualifier
end
if not (iPosition==nil) then
if ((iPosition==1) or (iPosition=="1")) then
txtPosColour='gold'
bMedal=1
end
if ((iPosition==2) or (iPosition=="2")) then
txtPosColour='silver'
bMedal=1
end
if ((iPosition==3) or (iPosition=="3")) then
txtPosColour='#CC9966'
bMedal=1
end
if (bMedal==1) then
return '<td align="center" bgcolor="' .. txtPosColour .. '">' .. iPosition .. '</td>'
else
return '<td>' .. iPosition .. '</td>'
end
else
return '<td></td>'
end
end
function txtYears(startyear,endyear,txtSeparator)
if (not (txtSeparator)) then
txtSeparator='–'
end
if (startyear=='' or startyear==nil) then
if (endyear=='' or endyear==nil) then
if (endyear=='' or endyear==nil) then
return ''
else
return txtSeparator
end
else
return txtSeparator .. endyear
end
else
if (endyear==startyear) then
return startyear
else
return startyear .. txtSeparator .. endyear
end
end
end
function processDates(entityid,txtSeparator)
txtDateFrom=''
txtDateTo=''
local p580=mw.wikibase.getAllStatements(entityid, 'P580' )
local hasstart=next(p580)
p582=mw.wikibase.getAllStatements(entityid, 'P582' )
local hasend=next(p582)
if hasstart then
txtDateFrom=read(p580[1],'time')
txtYearFrom=string.sub(txtDateFrom,2,5)
end
if hasend then
txtDateTo=read(p582[1],'time')
txtYearTo=string.sub(txtDateTo,2,5)
end
--For sorting purposes set date from and to date to the same if one of them is lacking
if hasend and not hasstart then
txtDateFrom=txtDateTo
txtYearFrom=txtYearTo
end
if hasstart and not hasend then
txtDateTo=txtDateFrom
txtYearTo=txtYearFrom
end
hasanydate=hasstart or hasend
if (hasanydate) then
txtSeason=txtYears(txtYearFrom,txtYearTo,txtSeparator)
end
return hasanydate,txtDateFrom,txtDateTo,txtYearFrom,txtSeason
end
--Fill table with information about the player's time at a club
function tblTeamInfo(frame,value,entityid,txtProperty)
local tmp={}
tmp.yearfrom,tmp.yearto,tmp.datefrom,tmp.dateto = years(value)
tmp.hasref,tmp.ref=tblProcessAllRefsForItemWD(frame,value['references'],entityid,txtProperty)
tmp.edit=txtEditPen(entityid,value.id)
return tmp
end
function years(value)
if value['qualifiers'] then
if value['qualifiers']['P580'] then
startdate=readQualifier(value.qualifiers.P580[1],'time') or '' -- readQualifier returns nil when P580 is "somevalue"
startyear=string.sub(startdate,2,5)
else
startdate=''
startyear=''
end
if value['qualifiers']['P582'] then
enddate=readQualifier(value.qualifiers.P582[1],'time') or '' -- readQualifier returns nil when P582 is "somevalue"
endyear=string.sub(enddate,2,5)
else
enddate=''
endyear=''
end
return startyear,endyear,startdate,enddate
end
return '','','',''
end
function txtDate (iYear,iMonth,iDay)
bHasMonth=not isempty(iMonth)
bHasDay=not isempty(iDay)
if (bHasMonth and bHasDay) then
return mw.getCurrentFrame():preprocess('{{#time:[[j F]] [[Y]]|'..iYear..'-'..iMonth..'-'..iDay..'}}')
else
if (bHasMonth) then
return mw.getCurrentFrame():preprocess('{{#time:F [[Y]]|'..iYear..'-'..iMonth..'-01}}')
else
return '[[' .. iYear .. ']]'
end
end
end
--Returns name of the team a given year
function txtTeamname(idTeam,year)
return txtWikilink(idTeam,year)
end
function isClub( id,txtProperty,iLevel )
if isempty(id) then
return false
end
if not (iLevel) then
iLevel=1
end
if (iLevel==1) then
if (isNationalTeam( id,txtProperty,iLevel)) then return false end
end--Start by checking it is not a national team
local instanceofs=mw.wikibase.getBestStatements(id, txtProperty )
local key, value
for key, value in pairs( instanceofs ) do
local txtId=read(value,'id')
if (txtId == 'Q847017' or txtId == 'Q12973014' or txtId=='Q108395614' or txtId=='Q13580678' or txtId=='Q115898316' or txtId=='Q15944511' or txtId=='Q476028') then return true end
if (iLevel<4) then
if (isClub(txtId,'P279',iLevel+1)) then return true end
end
end
return false
end
function isNationalTeam( id,txtProperty,iLevel)
if isempty(id) then
return false
end
if not (iLevel) then
iLevel=1
end
local instanceofs=mw.wikibase.getBestStatements(id, txtProperty );
for key, value in pairs( instanceofs ) do
local txtId=read(value,'id')
if txtId=='Q1194951' then return true end
if (iLevel<4) then
if (isNationalTeam(txtId,'P279',iLevel+1)) then return true end
end
end
return false
end
function allsame(tbl,property)
bAllSame=true
iLastType=nil
local key,value
for key, value in pairs(tbl) do
if (bAllSame and (value[property])) then --Only loop till a different value has been found
if (iLastType==nil) then --If first item set value for iLastType, otherwise compare if same as last one
iLastType=value[property]
else
bAllSame=iLastType==value[property]
end
end
end
return bAllSame
end
function showresults(myframe,all,txtShowResultsFor)
local txt=''
-- iAllCompetitionTypesTheSame=true
-- iLastType=nil
-- for key, value in pairs( all ) do
-- if (iAllCompetitionTypesTheSame) then --Only loop till a different value has been found
-- if (iLastType==nil) then --If first item set value for iLastType, otherwise compare if same as last one
-- iLastType=value.iCompetitionType
-- else
-- iAllCompetitionTypesTheSame=iLastType==value.iCompetitionType
-- end
-- end
-- end
iAllCompetitionTypesTheSame=allsame(all,'iCompetitionType')
if (myframe.args['oldestfirst']) then
table.sort(all, function(a, b)
return
a.iCompetitionType > b.iCompetitionType or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank < b.iCompetionRank) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague > b.txtLeague) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateFrom < b.txtDateFrom) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateFrom == b.txtDateFrom and a.txtDateTo < b.txtDateTo)
end)
else
table.sort(all, function(a, b)
return
a.iCompetitionType > b.iCompetitionType or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank < b.iCompetionRank) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague > b.txtLeague) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateFrom > b.txtDateFrom) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.txtDateFrom == b.txtDateFrom and a.txtDateTo > b.txtDateTo)
end)
end
if (bCondensed) then
table.sort(all, function(a, b)
return
a.iCompetitionType > b.iCompetitionType or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank < b.iCompetionRank) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague > b.txtLeague) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.iPosition < b.iPosition) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.iPosition == b.iPosition and a.txtDateFrom < b.txtDateFrom) or
(a.iCompetitionType == b.iCompetitionType and a.iCompetionRank == b.iCompetionRank and a.txtLeague==b.txtLeague and a.iPosition == b.iPosition and a.txtDateFrom == b.txtDateFrom and a.txtDateTo < b.txtDateTo)
end)
end
txtCompetitionOld=''
iCompetitionTypeOld="Q0"
iOldPosition=-1
local txtPositionRow='<tr><th width="30px">' .. txtPositionHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
if (not bHideable) then
txt=txt .. '<table style="class: biography vcard" width="100%">' .. txtPositionRow
end
for i = 1,#all do
if (all[i].iStatus==1) then
txtSeasonLink=mw.wikibase.getSitelink(all[i].iSeason)
end
if (all[i].iStatus==3) then --all[i].iStatus==2 or
txtSeasonShow= getLabelByEntity(all[i].iSeason)
else
txtSeasonShow=firstToUpper(all[i].txtSeason)
end
if not(iAllCompetitionTypesTheSame) then -- Only show competition type if there is more than one
if (all[i].iCompetitionType~=iCompetitionTypeOld) then
if (all[i].iCompetitionType=="Q0") then
txtCompetitionType=txtClickToAddCompetitionType .. ' [https://www.wikidata.org/wiki/' .. all[i].iLeague .. ' här].' .. txtaddWikiData(txtClassLabel,txtClassLabel,'('..txtClassHelp..')')
txtCompetitionType=txtCompetitionTypeNotSet.. myframe:extensionTag("ref", txtCompetitionType) .. '[[' .. txtCategory .. ':' .. txtGeneralError .. ']]'
else
if (all[i].iCompetitionType=="Q1") then
txtCompetitionType=txtClickToAddCompetition .. ' ' .. txtaddWikiData(txtProperty3450,'tävlingstyp',txtExplanationProperty3450)
txtCompetitionType=txtCompetitionTypeNotSet.. myframe:extensionTag("ref", txtCompetitionType) .. '[[' .. txtCategory .. ':' .. txtErrorCompetitionWithoutP3450 .. ']]'
else
txtCompetitionType = firstToUpper(getLabelByEntity(all[i].iCompetitionType))
end
end
-- txt=txt .. '<table style="class: biography vcard" width="100%">'..txtPositionRow .. '</table>'
if (bHideable) then
if (i>1) then
txt=txt .. '</table>'
end
txt=txt..'<table class="biography vcard" width="100%"><tr style="' .. txtStyleLevel2 .. '"><td colspan="2">' .. txtCompetitionType .. '</td><tr>'
else
txt=txt..'<tr style="' .. txtStyleLevel2 .. '"><td colspan="2">' .. txtCompetitionType .. '</td><tr>'
end
iCompetitionTypeOld=all[i].iCompetitionType
end
end
if (all[i].txtLeague~=txtCompetitionOld) then
if (bHideable) then
if (i>1) then
txt=txt .. '</table>'
end
txt=txt .. '<table class="mw-collapsible mw-collapsed biography vcard" width="100%" style="border-collapse: collapse; border: 1px solid darkgray;margin: 2px 0;"><tr ' .. txtTeamHeaderStyle .. '><td colspan="2"><b>' .. firstToUpper(all[i].txtLeague) .. '</b></td></tr>'..txtPositionRow
else
txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="2"><b>' .. firstToUpper(all[i].txtLeague) .. '</b></td></tr>'
end
txtCompetitionOld=all[i].txtLeague
end
if not ((bCondensed) and (i>1) and (all[i].iPosition==iOldPosition) and (all[i].txtLeague==all[i-1].txtLeague) and (all[i].iCompetitionType==all[i-1].iCompetitionType)) then
txt=txt..'<tr width="30px">' .. txtPosition(all[i].iPosition) --..'<td>'
if (myframe.args['condensed']) then
txt = txt ..'<td align="left" style="padding-left:10px">'
else
txt = txt ..'<td>'
end
else
txt=txt.. ', '
end
if not (txtSeasonLink==nil) then
txt=txt ..'[[' .. txtSeasonLink .. '|' .. txtSeasonShow .. ']]'
else
txt=txt .. txtSeasonShow
end
txt=txt..txtUnpackReference(myframe,all[i].hasref,all[i].ref) .. all[i].edit
if not ((bCondensed) and (i<#all) and (all[i].iPosition==all[i+1].iPosition) and (all[i].txtLeague==all[i+1].txtLeague) and (all[i].iCompetitionType==all[i+1].iCompetitionType)) then
txt=txt.. '</td></tr>'
end
iOldPosition=all[i].iPosition
end
txt=txt .. '</table>'
return all,txt
end
-- Function to add an Image to an infobox
--
-- Arguments:
-- entityid - the entity whose image we want to show
-- txtProperty - property used to get the image (usually P18, but can also be P154)
-- img - result of a call to entity:getBestStatements( 'P18' ) or equivalent
-- myArgs - array used to fill an infobox
function addImage(entityid,txtProperty,img,myArgs)
bDescription=false -- variable to check if a description has been found
if next(img) then
wdImage = img[1]['mainsnak']['datavalue']['value']
if img[1].qualifiers and img[1].qualifiers.P2096 then
-- Loop through all descriptions
for key, value in pairs(img[1].qualifiers.P2096) do
-- Only add if has the same language code as the local wikipedia
language=readQualifier(value,'language')
if (language==txtLanguageCode) then
bDescription=true -- description found!
myArgs[txtCaption]=readQualifier(value,'text') .. txtEditPen(entityid,txtProperty) -- add description (+ pen to make it easier to edit)
end
end
end
-- add image to the infobox array
myArgs[txtImage]='[[File:' .. wdImage .. '|' .. txtWidth_px .. ']]'
if (bDescription==false) then
myArgs[txtImage]=myArgs[txtImage]..txtEditPen(entityid,txtProperty)
end
end
return myArgs
end
-- Custom comparison function
--
function compareUP(a, b)
-- Handle nil values
-- if isempty(a) then
if (a==nil) then
return false
-- elseif isempty(b) then
elseif (b==nil) then
return true
-- return false
end
-- Compare the attributes (assuming a and b are strings or numbers)
return a < b
end
function compareDOWN(a, b)
-- Handle nil values
-- if (isempty(a)) then
if (a==nil) then
return true
-- elseif (isempty(b)) then
elseif (b==nil) then
return false
end
-- Compare the attributes (assuming a and b are strings or numbers)
return a < b
end
function isempty(foo)
return (foo==nil) or (foo=='') or (foo==0)
end
function sortActivityLog(posts)
table.sort(posts, function(a, b) return
(compareDOWN(a.yearfrom,b.yearfrom)) or
(a.yearfrom == b.yearfrom and compareUP(a.yearto,b.yearto)) or
(a.yearfrom == b.yearfrom and a.yearto == b.yearto and compareDOWN(a.datefrom,b.datefrom)) or
(a.yearfrom == b.yearfrom and a.yearto == b.yearto and a.datefrom == b.datefrom and compareUP(a.dateto,b.dateto))
end)
return posts
end
function mergeTables(t1, t2)
local mergedTable = {}
for _,v in ipairs(t2) do
table.insert(mergedTable, v)
end
for _,v in ipairs(t1) do
table.insert(mergedTable, v)
end
return mergedTable
end
function tblAddLocation(frame,myArgs,iCounter,txtLocationLabel,entityid, iProperty)
--Place
entityPlace=mw.wikibase.getBestStatements(entityid, iProperty )
--Only show if set
if next(entityPlace) then
idPlace=read(entityPlace[1],'id')
txtCountry = readFirstStatement(idPlace,'P17')
txtPlace = txtWikilink(idPlace)
if txtCountry then
txtPlace = txtPlace .. ', ' .. '[[' .. txtCountry .. ']]' .. txtUnpackReference(frame,tblProcessAllRefsForItemWD(frame,entityPlace[1].references,entityid,iProperty)) .. txtEditPen(entityid,iProperty)
end
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtLocationLabel
myArgs[txtContent .. iCounter]=txtPlace
end
return myArgs,iCounter
end