Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lua/wikis/commons/Standings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function Standings.fetchEntries(standings)
'standingsentry',
{
conditions = conditions:toString(),
order = 'roundindex asc',
order = 'roundindex asc, slotindex asc',
},
function(record)
table.insert(standingsEntries, record)
Expand All @@ -231,11 +231,13 @@ function Standings.makeRounds(standings)
local roundCount = Array.maxBy(Array.map(standingsEntries, function(entry)
return tonumber(entry.roundindex) or 1 end), FnUtil.identity)

local _, entriesByRound = Array.groupBy(standingsEntries, function(entry)
return tonumber(entry.roundindex)
end)

return Array.mapRange(1, roundCount or 1, function(roundIndex)
local roundEntries = Array.filter(standingsEntries, function(entry)
return tonumber(entry.roundindex) == roundIndex
end)
local opponents = Array.sortBy(Array.map(roundEntries, Standings.entryFromRecord), Operator.property('position'))
local roundEntries = Array.map(entriesByRound[roundIndex] or {}, Standings.entryFromRecord)
local opponents = Array.sortBy(roundEntries, Operator.property('position'))
return {
round = roundIndex,
opponents = opponents,
Expand Down
16 changes: 7 additions & 9 deletions lua/wikis/commons/Standings/Parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ function StandingsParser.parse(rounds, opponents, bgs, title, matches, standings
end)
end)

local _, entriesByRound = Array.groupBy(entries, function(entry)
return entry.roundindex
end)

Array.forEach(rounds, function(round)
StandingsParser.calculateTiebreakerValues(Array.filter(entries, function(opponentRound)
return opponentRound.roundindex == round.roundNumber
end), tiebreakerIds)
StandingsParser.calculateTiebreakerValues(entriesByRound[round.roundNumber] or {}, tiebreakerIds)
end)

Array.forEach(rounds, function(round)
StandingsParser.determinePlacements(Array.filter(entries, function(opponentRound)
return opponentRound.roundindex == round.roundNumber
end), tiebreakerIds)
StandingsParser.determinePlacements(entriesByRound[round.roundNumber] or {}, tiebreakerIds)
end)
---@cast entries {opponent: standardOpponent, standingindex: integer, roundindex: integer,
---points: number, placement: integer?, slotindex: integer}[]
Expand All @@ -96,9 +96,7 @@ function StandingsParser.parse(rounds, opponents, bgs, title, matches, standings

StandingsParser.addStatuses(entries, bgs, 'currentstatus')
if isFinished then
StandingsParser.addStatuses(Array.filter(entries, function(opponentRound)
return opponentRound.roundindex == #rounds
end), bgs, 'definitestatus')
StandingsParser.addStatuses(entriesByRound[#rounds] or {}, bgs, 'definitestatus')
end
---@cast entries {opponent: standardOpponent, standingindex: integer, roundindex: integer, points: number,
---placement: integer?, slotindex: integer, placementchange: integer?,
Expand Down
Loading