Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9201d19
add overall player perf to match page
ElectricalBoy Sep 26, 2025
d64202c
add CSM
ElectricalBoy Sep 26, 2025
4e9803f
adjust captions
ElectricalBoy Sep 26, 2025
253fb88
add overall team stats
ElectricalBoy Sep 26, 2025
c8b3692
plural
ElectricalBoy Sep 26, 2025
2505c1b
pass in date
ElectricalBoy Sep 26, 2025
509a8d8
refactor + lint
ElectricalBoy Sep 26, 2025
3d8571a
type anno
ElectricalBoy Sep 26, 2025
2456cf6
kick logging points
ElectricalBoy Sep 26, 2025
7c22054
reduce indentation level
ElectricalBoy Sep 26, 2025
4d56af8
adjust type anno
ElectricalBoy Sep 26, 2025
d88a7f6
code style
ElectricalBoy Sep 26, 2025
07a4383
add nil filter for stats list
ElectricalBoy Oct 4, 2025
e7d0c48
refactor team stats display
ElectricalBoy Oct 4, 2025
0bcec18
move calculation to parser
ElectricalBoy Oct 6, 2025
cae20e2
move more calculation to MGI
ElectricalBoy Oct 6, 2025
091b6f9
nil catch
ElectricalBoy Oct 6, 2025
1cbf385
move aggregated team stats calculation to MGI
ElectricalBoy Oct 6, 2025
4277327
use getTournamentIcon
ElectricalBoy Oct 6, 2025
005c6a9
add nilSafeAdd to Module:Operator
ElectricalBoy Oct 6, 2025
da44c42
more refactoring
ElectricalBoy Oct 6, 2025
9c33ef6
type annotation
ElectricalBoy Oct 6, 2025
ffe5412
fix indentation
ElectricalBoy Oct 6, 2025
e2d0f3d
start accumulating player stats
ElectricalBoy Oct 7, 2025
775f265
finish accumulating stats
ElectricalBoy Oct 7, 2025
8b9b9b1
adjust matchpage display to read from extradata
ElectricalBoy Oct 7, 2025
32e6853
comment to explain deepCopy
ElectricalBoy Oct 7, 2025
21644e4
type annotation
ElectricalBoy Oct 7, 2025
4952849
add constant for notplayed
ElectricalBoy Oct 7, 2025
9878817
cleanup formatting
ElectricalBoy Oct 7, 2025
869ba6b
use existing constant
ElectricalBoy Oct 7, 2025
2dd23dc
use Array.forEach
ElectricalBoy Oct 7, 2025
7d98cf4
switch looping order
ElectricalBoy Oct 7, 2025
cae614f
start copy cleaning
ElectricalBoy Oct 7, 2025
36d76cc
sort players in overall stats
ElectricalBoy Oct 7, 2025
bb3ec45
optimize copying
ElectricalBoy Oct 7, 2025
383222a
restore everything else
ElectricalBoy Oct 7, 2025
7a878b7
extract aggregating step
ElectricalBoy Oct 7, 2025
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
4 changes: 2 additions & 2 deletions lua/wikis/commons/MatchPage/Base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ function BaseMatchPage:renderGames()
local hasOverallStats = Logic.isNotEmpty(overallStats)

if hasOverallStats then
tabs['name1'] = 'Overall Statistics'
tabs['content1'] = overallStats
tabs.name1 = 'Overall Statistics'
tabs.content1 = overallStats
end

Array.forEach(games, function(game, idx)
Expand Down
13 changes: 13 additions & 0 deletions lua/wikis/commons/Operator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ function Operator.add(a, b)
return a + b
end

---A `nil`-safe version of `Operator.add`
---@param a number?
---@param b number?
---@return number?
function Operator.nilSafeAdd(a, b)
if not a then
return b
elseif not b then
return a
end
return a + b
end

---Uses the __sub metamethod (a - b)
---@param a number
---@param b number
Expand Down
11 changes: 8 additions & 3 deletions lua/wikis/commons/Widget/Match/Page/StatsList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ function MatchPageStatsList:render()
if Logic.isEmpty(self.props.data) then return end
return Div{
classes = {'match-bm-team-stats-list'},
children = Array.map(self.props.data, function (dataElement)
return self:_renderStat(dataElement)
end)
children = Array.map(
Array.filter(self.props.data, function (element)
return element.team1Value ~= nil or element.team2Value ~= nil
end),
function (dataElement)
return self:_renderStat(dataElement)
end
)
}
end

Expand Down
71 changes: 67 additions & 4 deletions lua/wikis/leagueoflegends/MatchGroup/Input/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ local Lua = require('Module:Lua')
local Array = Lua.import('Module:Array')
local FnUtil = Lua.import('Module:FnUtil')
local HeroNames = Lua.import('Module:ChampionNames', {loadData = true})
local Logic = Lua.import('Module:Logic')
local Operator = Lua.import('Module:Operator')
local String = Lua.import('Module:StringUtils')
local Table = Lua.import('Module:Table')

Expand All @@ -28,6 +30,8 @@ MatchFunctions.OPPONENT_CONFIG = {
MatchFunctions.DEFAULT_MODE = 'team'
MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf

local NOT_PLAYED = 'notplayed'

---@class LeagueOfLegendsMapParserInterface
---@field getMap fun(mapInput: table): table
---@field getLength fun(map: table): string?
Expand All @@ -37,6 +41,7 @@ MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf
---@field getHeroBans fun(map: table, opponentIndex: integer): string[]?
---@field getParticipants fun(map: table, opponentIndex: integer): table[]?
---@field getVetoPhase fun(map: table): table?
---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table

---@param match table
---@param options? {isMatchPage: boolean?}
Expand Down Expand Up @@ -64,7 +69,7 @@ function CustomMatchGroupInput.processMatch(match, options)
end

---@param match table
---@param opponents table[]
---@param opponents MGIParsedOpponent[]
---@param MapParser LeagueOfLegendsMapParserInterface
---@return table[]
function MatchFunctions.extractMaps(match, opponents, MapParser)
Expand All @@ -75,6 +80,7 @@ function MatchFunctions.extractMaps(match, opponents, MapParser)
getMap = MapParser.getMap,
getLength = MapParser.getLength,
getPlayersOfMapOpponent = FnUtil.curry(MapFunctions.getPlayersOfMapOpponent, MapParser),
extendMapOpponent = MapParser.extendMapOpponent
}
local maps = MatchGroupInputUtil.standardProcessMaps(match, opponents, mapParserWrapper)

Expand All @@ -96,9 +102,66 @@ end

---@param match table
---@param games table[]
---@param opponents table[]
---@param opponents MGIParsedOpponent[]
---@return table
function MatchFunctions.getExtraData(match, games, opponents)
if games[1] and games[1].opponents[1].stats then
Array.forEach(opponents, function (opponent, opponentIndex)
---@param name string
---@return number?
local function aggregateStats(name)
return Array.reduce(
Array.map(games, function (game)
return (game.opponents[opponentIndex].stats or {})[name]
end),
Operator.nilSafeAdd
)
end
opponent.extradata = {
kills = aggregateStats('kills'),
deaths = aggregateStats('deaths'),
assists = aggregateStats('assists'),
towers = aggregateStats('towers'),
inhibitors = aggregateStats('inhibitors'),
dragons = aggregateStats('dragons'),
atakhans = aggregateStats('atakhans'),
heralds = aggregateStats('heralds'),
barons = aggregateStats('barons')
}
Array.forEach(games, function (game)
if game.status == NOT_PLAYED then
return
end
opponent.match2players = Array.map(opponent.match2players, function (player, playerIndex)
local gamePlayerData = game.opponents[opponentIndex].players[playerIndex]
if Logic.isEmpty(gamePlayerData) then
return player
end
local parsedGameLength = Array.map(
Array.parseCommaSeparatedString(game.length --[[@as string]], ':'), function (element)
---Directly using tonumber as arg to Array.map causes base out of range error
return tonumber(element)
end
)
local gameLength = (parsedGameLength[1] or 0) * 60 + (parsedGameLength[2] or 0)
player.extradata = player.extradata or {}
player.extradata.role = player.extradata.role or gamePlayerData.role
player.extradata.characters = Array.extend(player.extradata.characters, gamePlayerData.character)
player.extradata.kills = Operator.nilSafeAdd(player.extradata.kills, gamePlayerData.kills)
player.extradata.deaths = Operator.nilSafeAdd(player.extradata.deaths, gamePlayerData.deaths)
player.extradata.assists = Operator.nilSafeAdd(player.extradata.assists, gamePlayerData.assists)
player.extradata.damage = Operator.nilSafeAdd(player.extradata.damage, gamePlayerData.damagedone)
player.extradata.creepscore = Operator.nilSafeAdd(player.extradata.creepscore, gamePlayerData.creepscore)
player.extradata.gold = Operator.nilSafeAdd(player.extradata.gold, gamePlayerData.gold)
player.extradata.gameLength = Operator.nilSafeAdd(player.extradata.gameLength, gameLength)
return player
end)
end)
end)
---Deep copy here to work around circular reference error from LPDB storage
opponents = Table.deepCopy(opponents)
end

return {
mvp = MatchGroupInputUtil.readMvp(match, opponents),
}
Expand All @@ -107,7 +170,7 @@ end
---@param MapParser LeagueOfLegendsMapParserInterface
---@param match table
---@param map table
---@param opponents table[]
---@param opponents MGIParsedOpponent[]
---@return table
function MapFunctions.getExtraData(MapParser, match, map, opponents)
local extraData = {}
Expand Down Expand Up @@ -146,7 +209,7 @@ end

---@param MapParser LeagueOfLegendsMapParserInterface
---@param map table
---@param opponent table
---@param opponent MGIParsedOpponent
---@param opponentIndex integer
---@return table[]
function MapFunctions.getPlayersOfMapOpponent(MapParser, map, opponent, opponentIndex)
Expand Down
30 changes: 30 additions & 0 deletions lua/wikis/leagueoflegends/MatchGroup/Input/Custom/MatchPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,34 @@ function CustomMatchGroupInputMatchPage.getObjectives(map, opponentIndex)
}
end

function CustomMatchGroupInputMatchPage.extendMapOpponent(map, opponentIndex)
local participants = CustomMatchGroupInputMatchPage.getParticipants(map, opponentIndex)

if Logic.isEmpty(participants) then
return {picks = {}, stats = {}}
end
---@cast participants -nil

---@param arr table[]
---@param item string
---@return number?
local function sumItem(arr, item)
return Array.reduce(Array.map(arr, Operator.property(item)), Operator.nilSafeAdd, 0)
end

return {
side = CustomMatchGroupInputMatchPage.getSide(map, opponentIndex),
picks = Array.map(participants, Operator.property('character')),
stats = Table.merge(
{
gold = sumItem(participants, 'gold'),
kills = sumItem(participants, 'kills'),
deaths = sumItem(participants, 'deaths'),
assists = sumItem(participants, 'assists')
},
CustomMatchGroupInputMatchPage.getObjectives(map, opponentIndex)
)
}
end

return CustomMatchGroupInputMatchPage
Loading