diff --git a/lua/wikis/commons/Standings.lua b/lua/wikis/commons/Standings.lua index da891d1d3cb..3d86bc63352 100644 --- a/lua/wikis/commons/Standings.lua +++ b/lua/wikis/commons/Standings.lua @@ -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) @@ -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, diff --git a/lua/wikis/commons/Standings/Parser.lua b/lua/wikis/commons/Standings/Parser.lua index da58111abc0..59a505fddd6 100644 --- a/lua/wikis/commons/Standings/Parser.lua +++ b/lua/wikis/commons/Standings/Parser.lua @@ -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}[] @@ -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?,