Module:Sports series: Difference between revisions

Content deleted Content added
improve logic
allow for determining winner on away goals
Line 9:
end
 
-- Function to check the existence of template passed via |flag=
local function templateExists(templateName)
local title = mw.title.new('Template:' .. templateName)
Line 77 ⟶ 78:
 
-- Function to determine the winner based on scores within parentheses (first) or regular format (second)
local function determineWinner(cleanScorecleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregate, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
local team1Winner, team2Winner = false, false
local score1, score2
Line 103 ⟶ 104:
end
 
-- Handling for manual coloring of team or aggregate cells
if team1 and type(team1) == 'string' then
manualColor1 = team1:find("''") and not (team1:gsub("''", ""):match("^%s*$"))
Line 140 ⟶ 141:
-- Regular winner determination logic if manual bolding or coloring is not conclusive
if not team1Winner and not team2Winner and not isDraw and (boldWinner or colorWinner or isFBRStyle) then
local parenthetical = cleanScorecleanAggregate:match('%((%d+%-+%d+)%)')
local outsideParenthetical = cleanScorecleanAggregate:match('^(%d+%-+%d+)')
if parenthetical then -- Prioritize checking score inside parenthetical
score1, score2 = parenthetical:match('(%d+)%-+(%d+)')
elseif outsideParenthetical then
Line 149 ⟶ 150:
 
if score1 and score2 then
team1Winnerscore1 = tonumber(score1)
> score2 = tonumber(score2)
team2Winner = tonumber(score1) < tonumber(score2)
if colorWinnerscore1 or> isFBRStylescore2 then
isDrawteam1Winner = tonumber(score1) == tonumber(score2)true
team2Winnerelseif = tonumber(score1) < tonumber(score2) then
team2Winner = endtrue
elseif score1 == score2 and legs == 2 and not disableAwayGoals then
-- Apply away goals endrule
local cleanLeg1 = cleanScore(leg1Score):gsub('[()]', '')
local cleanLeg2 = cleanScore(leg2Score):gsub('[()]', '')
local _, team2AwayGoals = cleanLeg1:match('(%d+)%-+(%d+)')
local team1AwayGoals = cleanLeg2:match('(%d+)%-+(%d+)')
 
if team1AwayGoals and elseif isDrawteam2AwayGoals then
team1AwayGoals, team2AwayGoals = tonumber(team1AwayGoals), tonumber(team2AwayGoals)
elseifif team2Winnerteam1AwayGoals > team2AwayGoals then
elseif isDraw then team1Winner = true
elseif team2Winnerteam2AwayGoals > team1AwayGoals then
team2Winner = true
end
end
end
if (colorWinner or isFBRStyle) and legs == 0 then
isDraw = not team1Winner and not team2Winner
end
end
Line 170 ⟶ 194:
end
 
-- Function to add a legend to below the table when |matches_style=FBR
local function createFBRLegend()
return mw.html.create('div')
Line 197 ⟶ 222:
local fillBlanks = args.fill_blanks and (args.fill_blanks == 'y' or args.fill_blanks == 'yes' or args.fill_blanks == '1' or args.fill_blanks == 'true')
 
-- Process the font size parameter
local size
if args.size then
Line 252 ⟶ 277:
local isFBRStyle = matchesStyle and matchesStyle:upper() == "FBR"
local isHA = args.h_a == 'y' or args.h_a == 'yes' or args.h_a == '1' or args.h_a == 'true'
local disableAwayGoals = args.away_goals == 'n' or args.away_goals == 'no' or args.away_goals == '0' or args.away_goals == 'false' or args.away_goals == 'null'
 
local tableClass = 'wikitable'
Line 367 ⟶ 393:
local team1, aggregateScore, team2
local team1Winner, team2Winner, manualBold, manualColor, isDraw = false, false, false, false, false
local leg1Score, leg2Score = false, false
local team1Asterick, team2Asterick = false, false
 
Line 390 ⟶ 417:
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 then
leg1Score = args[i+3]
leg2Score = args[i+4]
end
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Add background-color for winning team if set by user
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
Line 415 ⟶ 447:
-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0 or manualColor then
if isFBRStyle and legs == 0team1Winner then
ifaggregateStyle team1Winner= thenaggregateStyle .. '; background-color: #BBF3FF;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #BBF3FFFFBBBB;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBBFFFFBB;'
end
-- Create rows for aggregate score and team names, bolded if set by user
Line 446 ⟶ 476:
-- Clean the aggregate score
local cleanAggregate = cleanScore(aggregateScore)
-- Name the 1st/2nd leg scores for two-legged ties for possibly determining the winner on away goals
if legs == 2 then
if noFlagIcons then
leg1Score = args[i+3]
leg2Score = args[i+4]
else
leg1Score = args[i+5]
leg2Score = args[i+6]
end
end
-- Determine the winning team on aggregate
team1, team2, team1Winner, team2Winner, manualBold, manualColor, isDraw, aggregateScore = determineWinner(cleanAggregate, matchType, team1, team2, boldWinner, colorWinner, aggregateScore, isFBRStyle, legs, leg1Score, leg2Score, disableAwayGoals)
-- Add background-color for winning team if set by user
local team1Style = team1Winner and ((colorWinner or manualColor) and 'background-color: #CCFFCC;' or '') .. 'text-align: right;' or 'text-align: right;'
Line 467 ⟶ 507:
-- Create aggregate score cell with conditional styling
local aggregateStyle = 'text-align: center;'
if isFBRStyle and legs == 0 or manualColor then
if isFBRStyle and legs == 0team1Winner then
ifaggregateStyle team1Winner= thenaggregateStyle .. '; background-color: #BBF3FF;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #BBF3FFFFBBBB;'
elseif team2Winner then
aggregateStyle = aggregateStyle .. '; background-color: #FFBBBB;'
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
elseif isDraw then
aggregateStyle = aggregateStyle .. '; background-color: #FFFFBB;'
end
-- Create rows for aggregate score and team names, bolded if set by user