Skip to content
Open
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
22 changes: 17 additions & 5 deletions lua/wikis/commons/Standings/Parse/Lpdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function StandingsParseLpdb.importFromMatches(rounds, scoreMapper)

---@type StandingTableOpponentData[]
local opponents = {}
---@type table<string, StandingTableOpponentData>
local opponentsByName = {}
Lpdb.executeMassQuery(
'match2',
{
Expand All @@ -62,7 +64,7 @@ function StandingsParseLpdb.importFromMatches(rounds, scoreMapper)
function(match2)
local roundNumbers = matchIdToRound[match2.match2id]
Array.forEach(roundNumbers, function(roundNumber)
StandingsParseLpdb.parseMatch(roundNumber, match2, opponents, scoreMapper, #rounds)
StandingsParseLpdb.parseMatch(roundNumber, match2, opponents, opponentsByName, scoreMapper, #rounds)
end)
end
)
Expand Down Expand Up @@ -116,18 +118,28 @@ end
---@param roundNumber integer
---@param match match2
---@param opponents StandingTableOpponentData[]
---@param opponentsByName table<string, StandingTableOpponentData>
---@param scoreMapper fun(opponent: standardOpponent): number?
---@param maxRounds integer
function StandingsParseLpdb.parseMatch(roundNumber, match, opponents, scoreMapper, maxRounds)
function StandingsParseLpdb.parseMatch(roundNumber, match, opponents, opponentsByName, scoreMapper, maxRounds)
local match2 = MatchGroupUtil.matchFromRecord(match)
Array.forEach(match2.opponents, function(opponent)
---Find matching opponent
local standingsOpponentData = Array.find(opponents, function(opponentData)
return Opponent.same(opponentData.opponent, opponent)
end)
local key = Opponent.toName(opponent)
local standingsOpponentData = opponentsByName[key]
if not standingsOpponentData and opponent.type == Opponent.team then
-- renamed teams have differing names but compare equal via historicaltemplate

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"renamed teams have differing names" is an incorrect assumption if i am not mistaken:

  • Opponent.toName returns TeamTemplate.toPageName (with normalized underscores)
  • TeamTemplate.toPageName returns set pagename, resolves redirects, and normalizes underscores

A correctly setup HTT should have page redirects for each of the subtemplates to the same page.
Thus they'd end up with the same name via Opponent.toName.

This would only be different if we remove the forced resolving of redirects (which i'd personally advocate for due to A/B teams, but not sure if that is going to happen and the side effects of it)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not necessarily true
there exist some team templates that have different page names set in their sub templates where no redirect exists between them
so if you would catch such a tt and process it at different dates (one before, one after the switch) you would get different pagenames returned

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the usecase of such a TT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea i hate them
iirc cs had some of them for some reasons

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you refer to the mibr vs MIBR things.
IIRC they fixed these by now, as they had other things broken.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly
if those are solved, then you are right :)

standingsOpponentData = Array.find(opponents, function(opponentData)
return Opponent.same(opponentData.opponent, opponent)
end)
if standingsOpponentData then
opponentsByName[key] = standingsOpponentData
end
end
if not standingsOpponentData then
standingsOpponentData = StandingsParseLpdb.newOpponent(opponent, maxRounds)
table.insert(opponents, standingsOpponentData)
opponentsByName[key] = standingsOpponentData
end
assert(standingsOpponentData.rounds[roundNumber], 'Round number out of bounds')

Expand Down
Loading