-
Notifications
You must be signed in to change notification settings - Fork 106
feat(Infobox): add Fortnite Power Rankings for players and organizations #7633
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
Mehdi9120310391
wants to merge
35
commits into
Liquipedia:main
Choose a base branch
from
Mehdi9120310391:patch-10
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.
+609
−0
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1a97c2c
Add fetchPowerRanking function for team power rankings
Mehdi9120310391 b9efab2
Add power ranking fetching functionality to Custom.lua
Mehdi9120310391 c5cf87d
Update lua/wikis/fortnite/Infobox/Team/Custom.lua
Mehdi9120310391 cfad681
Update lua/wikis/fortnite/Infobox/Person/Player/Custom.lua
Mehdi9120310391 7531cd2
Update lua/wikis/fortnite/Infobox/Person/Player/Custom.lua
Mehdi9120310391 80faf8e
Update lua/wikis/fortnite/Infobox/Person/Player/Custom.lua
Mehdi9120310391 612d1f1
Refactor fetchPowerRanking function and imports
Mehdi9120310391 b11e795
Refactor power ranking link in Custom.lua
Mehdi9120310391 3ccf9bf
Add PowerRankings module for Fortnite
Mehdi9120310391 4be4212
Add Lua module for Fortnite organization power rankings
Mehdi9120310391 ad6d5fd
Update PowerRankings.lua
Mehdi9120310391 b87d42f
Update Orgs.lua
Mehdi9120310391 05eb714
Update Orgs.lua
Mehdi9120310391 05e400d
Update Custom.lua
Mehdi9120310391 8c9144e
Update PowerRankings.lua
Mehdi9120310391 b6a93b2
Update Orgs.lua
Mehdi9120310391 6fd34f0
Merge branch 'main' into patch-10
Mehdi9120310391 c6c5682
Update Orgs.lua
Mehdi9120310391 cb220f7
Update PowerRankings.lua
Mehdi9120310391 43fc5be
Update PowerRankings.lua
Mehdi9120310391 f4091bd
Update Orgs.lua
Mehdi9120310391 92979cb
Merge branch 'main' into patch-10
Mehdi9120310391 ad3f911
Update Orgs.lua
Mehdi9120310391 fd753d8
Merge branch 'main' into patch-10
Mehdi9120310391 dc963ea
Merge branch 'main' into patch-10
Mehdi9120310391 f4b0ffd
Merge branch 'main' into patch-10
Mehdi9120310391 ca33e7a
Update Orgs.lua
Mehdi9120310391 f0bb9e5
Update lua/wikis/fortnite/PowerRankings/Orgs.lua
hjpalpha 6cacbbd
Apply suggestion from @hjpalpha
hjpalpha 1a7d1a4
Update Custom.lua
Mehdi9120310391 83454ec
Update Custom.lua
Mehdi9120310391 4c7f8b8
Update PowerRankings.lua
Mehdi9120310391 80e46da
Update Orgs.lua
Mehdi9120310391 497a22f
Merge branch 'main' into patch-10
Mehdi9120310391 c240bbd
Merge branch 'main' into patch-10
Mehdi9120310391 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,178 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:PowerRankings | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Arguments = Lua.import('Module:Arguments') | ||
| local Array = Lua.import('Module:Array') | ||
| local Currency = Lua.import('Module:Currency') | ||
| local DateExt = Lua.import('Module:Date/Ext') | ||
| local Icon = Lua.import('Module:Icon') | ||
| local Logic = Lua.import('Module:Logic') | ||
| local Lpdb = Lua.import('Module:Lpdb') | ||
| local Opponent = Lua.import('Module:Opponent/Custom') | ||
| local OpponentDisplay = Lua.import('Module:OpponentDisplay/Custom') | ||
| local PlayerDisplay = Lua.import('Module:Player/Display/Custom') | ||
| local PlayerExt = Lua.import('Module:Player/Ext/Custom') | ||
| local PowerRankingsData = Lua.import('Module:PowerRankings/Data', {loadData = true}) | ||
|
|
||
| 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 HtmlWidgets = Lua.import('Module:Widget/Html') | ||
| local Link = Lua.import('Module:Widget/Basic/Link') | ||
| local TableWidgets = Lua.import('Module:Widget/Table2/All') | ||
| local WidgetUtil = Lua.import('Module:Widget/Util') | ||
|
|
||
| local PLAYER_DATAPOINT_TYPE = 'FTN_PR' | ||
|
|
||
| local PowerRankings = {} | ||
|
|
||
| ---@param updated string? | ||
| ---@return Renderable | ||
| local function buildTitle(updated) | ||
| return HtmlWidgets.Div{ | ||
| classes = {'ranking-table__top-row'}, | ||
| children = { | ||
| HtmlWidgets.Div{ | ||
| children = WidgetUtil.collect( | ||
| HtmlWidgets.B{children = 'Fortnite Power Rankings'}, | ||
| Logic.isNotEmpty(updated) and HtmlWidgets.Span{children = {'Last updated: ', updated}} or nil | ||
| ), | ||
| classes = {'ranking-table__top-row-text'}, | ||
| }, | ||
| HtmlWidgets.Div{ | ||
| children = {HtmlWidgets.Span{children = 'Data by Epic Games'}}, | ||
| classes = {'ranking-table__top-row-logo-container'}, | ||
| }, | ||
| }, | ||
| } | ||
| end | ||
|
Mehdi9120310391 marked this conversation as resolved.
|
||
|
|
||
| ---@return Renderable | ||
| local function buildFooter() | ||
|
Mehdi9120310391 marked this conversation as resolved.
|
||
| return Link{ | ||
| link = 'Fortnite Power Rankings', | ||
| linktype = 'internal', | ||
| children = { | ||
| HtmlWidgets.Div{ | ||
| children = {'See Rankings Page', Icon.makeIcon{iconName = 'goto'}}, | ||
| classes = {'ranking-table__footer-button'}, | ||
| }, | ||
| }, | ||
| } | ||
| end | ||
|
|
||
| ---@param frame Frame | ||
| ---@return VNode | ||
| function PowerRankings.main(frame) | ||
| local args = Arguments.getArgs(frame) | ||
| local limit = tonumber(args.limit) | ||
| local showMore = Logic.readBool(args.showMore) | ||
|
|
||
| local players = PowerRankingsData.players or {} | ||
| if limit then | ||
| players = Array.sub(players, 1, limit) | ||
| end | ||
|
|
||
| local updated, updatedIso | ||
| if Logic.isNotEmpty(PowerRankingsData.updated) then | ||
| updated = PowerRankingsData.updated .. ' ' .. DateExt.defaultTimezone | ||
| updatedIso = DateExt.toYmdInUtc(PowerRankingsData.updated) | ||
| end | ||
|
|
||
| local rows = Array.map(players, function(entry) | ||
| local player = { | ||
| displayName = entry.name, | ||
| pageName = Logic.nilIfEmpty(entry.link) or entry.name, | ||
| } | ||
| PlayerExt.syncPlayer(player) | ||
| local teamTemplate = PlayerExt.syncTeam(player.pageName, nil, {date = updatedIso}) | ||
|
|
||
| PowerRankings._store(player, entry) | ||
|
|
||
| return TableWidgets.Row{children = { | ||
| TableWidgets.Cell{children = HtmlWidgets.B{children = entry.rank}}, | ||
| TableWidgets.Cell{children = HtmlWidgets.B{children = Currency.formatMoney(entry.points, 0)}}, | ||
| TableWidgets.Cell{children = PlayerDisplay.BlockPlayer{player = player}}, | ||
| TableWidgets.Cell{children = teamTemplate and OpponentDisplay.BlockOpponent{opponent = { | ||
| type = Opponent.team, | ||
| template = teamTemplate, | ||
| extradata = {}, | ||
| }} or nil}, | ||
| }} | ||
| end) | ||
|
|
||
| return TableWidgets.Table{ | ||
| title = buildTitle(updated), | ||
| sortable = false, | ||
| columns = { | ||
| {align = 'center', sortType = 'number'}, | ||
| {align = 'center', sortType = 'number'}, | ||
| {align = 'left'}, | ||
| {align = 'left'}, | ||
| }, | ||
| footer = showMore and buildFooter() or nil, | ||
| css = {width = '100%'}, | ||
| children = { | ||
| TableWidgets.TableHeader{children = { | ||
| TableWidgets.Row{children = { | ||
| TableWidgets.CellHeader{children = 'Rank'}, | ||
| TableWidgets.CellHeader{children = 'Points'}, | ||
| TableWidgets.CellHeader{children = 'Player'}, | ||
| TableWidgets.CellHeader{children = 'Organization'}, | ||
| }}, | ||
| }}, | ||
| TableWidgets.TableBody{children = rows}, | ||
| }, | ||
| } | ||
| end | ||
|
|
||
| ---@param player standardPlayer | ||
| ---@param entry {rank: integer, points: number} | ||
| function PowerRankings._store(player, entry) | ||
| if Lpdb.isStorageDisabled() then return end | ||
| mw.ext.LiquipediaDB.lpdb_datapoint(PLAYER_DATAPOINT_TYPE .. '_' .. player.pageName, { | ||
| type = PLAYER_DATAPOINT_TYPE, | ||
| name = player.pageName, | ||
| information = entry.rank, | ||
| extradata = {score = entry.points}, | ||
| }) | ||
| end | ||
|
|
||
| ---@param pageName string | ||
| ---@param datapointType string | ||
| ---@return string? | ||
| function PowerRankings.queryForInfobox(pageName, datapointType) | ||
| local conditions = ConditionTree(BooleanOperator.all):add{ | ||
| ConditionNode(ColumnName('type'), Comparator.eq, datapointType), | ||
| ConditionNode(ColumnName('name'), Comparator.eq, pageName), | ||
| } | ||
|
|
||
| local data = mw.ext.LiquipediaDB.lpdb('datapoint', { | ||
| limit = 1, | ||
| order = 'date DESC', | ||
| conditions = tostring(conditions), | ||
| query = 'information, extradata', | ||
| })[1] | ||
|
|
||
| if not data then return end | ||
|
|
||
| local points = data.extradata.score | ||
| local rank = data.information | ||
| if not points or not rank then return end | ||
|
|
||
| points = Currency.formatMoney(points, datapointType == PLAYER_DATAPOINT_TYPE and 0 or 1) | ||
|
|
||
| return points .. ' (Rank #' .. rank .. ')' | ||
| end | ||
|
|
||
| return PowerRankings | ||
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.