-
Notifications
You must be signed in to change notification settings - Fork 93
feat: add StageWinnings #6602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hjpalpha
wants to merge
15
commits into
main
Choose a base branch
from
stage-standings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add StageWinnings #6602
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0e9e39d
feat: add StageWinnings
hjpalpha c059ae7
some more
hjpalpha 9d2669f
tiny fix
hjpalpha 36b0693
add exchange info stuff
hjpalpha 3f5d2c6
some fixes
hjpalpha ea56e8d
fix calculations
hjpalpha 52a5bf5
no Fragment
hjpalpha 63f93cc
support default wins
hjpalpha 67eff3c
make use of 6658
hjpalpha 43f87b9
fix indent
hjpalpha 63d5d05
unused imports
hjpalpha d82967c
lets kick echange info
hjpalpha 887db79
Merge branch 'main' into stage-standings
hjpalpha 3483577
fixerino
hjpalpha fb2d7dd
some more fixing
hjpalpha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:StageWinningsCalculation | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Array = Lua.import('Module:Array') | ||
| local Logic = Lua.import('Module:Logic') | ||
| local Opponent = Lua.import('Module:Opponent/Custom') | ||
| local Page = Lua.import('Module:Page') | ||
|
|
||
| local Condition = Lua.import('Module:Condition') | ||
| local ConditionTree = Condition.Tree | ||
| local ConditionNode = Condition.Node | ||
| local Comparator = Condition.Comparator | ||
| local BooleanOperator = Condition.BooleanOperator | ||
| local ColumnName = Condition.ColumnName | ||
| local ConditionUtil = Condition.Util | ||
|
|
||
| local StageWinningsCalculation = {} | ||
|
|
||
| ---@param props {ids: string?, tournaments: string, startDate: integer?, endDate: integer?, mode: string, | ||
| ---startValue: number, valuePerWin: number, valueByScore: table<string, number>?} | ||
| ---@return {opponent: standardOpponent, matchWins: integer, matchLosses: integer, gameWins: integer, | ||
| ---gameLosses: integer, winnings: number, scoreDetails: table<string, integer>}[] | ||
| function StageWinningsCalculation.run(props) | ||
| local matches = mw.ext.LiquipediaDB.lpdb('match2', { | ||
| conditions = StageWinningsCalculation._buildConditions(props), | ||
| query = 'match2opponents, winner', | ||
| limit = 5000 | ||
| }) | ||
| matches = Array.filter(matches, function(match) | ||
| return #match.match2opponents == 2 | ||
| end) | ||
|
|
||
| local byName = {} | ||
|
|
||
| Array.forEach(matches, function(match) | ||
| Array.forEach(match.match2opponents, function(opponent) | ||
| local identifier = opponent.name | ||
| byName[identifier] = byName[identifier] or { | ||
| opponent = Opponent.fromMatch2Record(opponent), | ||
| scoreDetails = {}, | ||
| matchWins = 0, | ||
| matchLosses = 0, | ||
| gameWins = 0, | ||
| gameLosses = 0, | ||
| winnings = 0, | ||
| } | ||
| end) | ||
|
|
||
| local winnerId = tonumber(match.winner) | ||
| if winnerId ~= 1 and winnerId ~= 2 then return end | ||
| local loserId = 3 - winnerId | ||
|
|
||
| local winner = match.match2opponents[winnerId] | ||
| local loser = match.match2opponents[loserId] | ||
|
|
||
| local winnerScore = tonumber(winner.score) or '' | ||
| local loserScore = tonumber(loser.score) or '' | ||
hjpalpha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| local score = winnerScore .. '-' .. loserScore | ||
| local reversedScore = loserScore .. '-' .. winnerScore | ||
|
|
||
| byName[winner.name].scoreDetails[score] = (byName[winner.name].scoreDetails[score] or 0) + 1 | ||
| byName[loser.name].scoreDetails[reversedScore] = (byName[loser.name].scoreDetails[reversedScore] or 0) + 1 | ||
|
|
||
| byName[winner.name].matchWins = byName[winner.name].matchWins + 1 | ||
| byName[loser.name].matchLosses = byName[loser.name].matchLosses + 1 | ||
|
|
||
| byName[winner.name].gameWins = byName[winner.name].gameWins + (tonumber(winner.score) or 0) | ||
| byName[loser.name].gameLosses = byName[loser.name].gameLosses + (tonumber(winner.score) or 0) | ||
| byName[winner.name].gameLosses = byName[winner.name].gameLosses + (tonumber(loser.score) or 0) | ||
| byName[loser.name].gameWins = byName[loser.name].gameWins + (tonumber(loser.score) or 0) | ||
| end) | ||
|
|
||
| local opponents = Array.extractValues(byName) | ||
|
|
||
| Array.forEach(opponents, function(opponent) | ||
| if props.mode == 'matchWins' then | ||
| opponent.winnings = props.startValue + opponent.matchWins * props.valuePerWin | ||
| return | ||
| elseif props.mode == 'gameWins' then | ||
| opponent.winnings = props.startValue + opponent.gameWins * props.valuePerWin | ||
| return | ||
| end | ||
| -- case: props.mode == 'scores' | ||
| local winnings = props.startValue | ||
| for score, count in pairs(opponent.scoreDetails) do | ||
| winnings = winnings + (props.valueByScore[score] or 0) * count | ||
| end | ||
| opponent.winnings = winnings | ||
| end) | ||
|
|
||
| Array.sortInPlaceBy(opponents, function(opponent) | ||
| return {- opponent.winnings, - opponent.matchWins, - opponent.gameWins, Opponent.toName(opponent)} | ||
| end) | ||
|
|
||
| return opponents | ||
|
|
||
| end | ||
|
|
||
| ---@param props {ids: string?, tournaments: string, startDate: integer?, endDate: integer?} | ||
| ---@return string | ||
| function StageWinningsCalculation._buildConditions(props) | ||
| local ids = Array.parseCommaSeparatedString(props.ids) | ||
|
|
||
| local conditions = ConditionTree(BooleanOperator.all):add{ | ||
| ConditionNode(ColumnName('finished'), Comparator.eq, '1'), | ||
| ConditionNode(ColumnName('status'), Comparator.neq, 'notplayed'), | ||
| ConditionNode(ColumnName('winner'), Comparator.neq, ''), | ||
| } | ||
|
|
||
| if Logic.isNotEmpty(ids) then | ||
| conditions:add(ConditionUtil.anyOf(ColumnName('match2bracketid'), ids)) | ||
| else | ||
| local tournaments = Array.map(Array.parseCommaSeparatedString(props.tournaments), Page.pageifyLink) | ||
| conditions:add(ConditionUtil.anyOf(ColumnName('pagename'), tournaments)) | ||
| end | ||
hjpalpha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if props.startDate then | ||
| conditions:add(ConditionNode(ColumnName('date'), Comparator.ge, props.startDate)) | ||
| end | ||
|
|
||
| if props.endDate then | ||
| conditions:add(ConditionNode(ColumnName('date'), Comparator.le, props.endDate)) | ||
| end | ||
|
|
||
| return tostring(conditions) | ||
| end | ||
|
|
||
| return StageWinningsCalculation | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.