Skip to content

Commit

Permalink
Merge branch 'main' into support-postponed-in-match2
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha authored Jan 14, 2025
2 parents 2029919 + 0499f8d commit f9f036e
Show file tree
Hide file tree
Showing 301 changed files with 7,205 additions and 4,264 deletions.
190 changes: 190 additions & 0 deletions components/country_representation/commons/country_representation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
-- @Liquipedia
-- wiki=commons
-- page=Module:CountryRepresentation
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Arguments = require('Module:Arguments')
local Array = require('Module:Array')
local Class = require('Module:Class')
local Flags = require('Module:Flags')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MathUtil = require('Module:MathUtil')
local Page = require('Module:Page')
local Table = require('Module:Table')

local Condition = require('Module:Condition')
local ConditionTree = Condition.Tree
local ConditionNode = Condition.Node
local Comparator = Condition.Comparator
local BooleanOperator = Condition.BooleanOperator
local ColumnName = Condition.ColumnName

local Widgets = Lua.import('Module:Widget/All')
local Td = Widgets.Td
local Th = Widgets.Th
local Tr = Widgets.Tr
local DataTable = Widgets.DataTable

local WidgetUtil = Lua.import('Module:Widget/Util')

---@class CountryRepresentation
---@operator call(table<string, any>): CountryRepresentation
---@field config CountryRepresentationConfig
---@field byCountry table<string, {page:string, displayName: string?}[]>
---@field count integer
local CountryRepresentation = Class.new(function(self, args) self:init(args) end)

---@class CountryRepresentationConfig
---@field tournaments string[]
---@field showNoCountry boolean
---@field staff boolean

---@param frame Frame
---@return Widget
function CountryRepresentation.run(frame)
local args = Arguments.getArgs(frame)
return CountryRepresentation(args):fetchAndProcess():create()
end

---@param args table
---@return self
function CountryRepresentation:init(args)
self.config = {
showNoCountry = Logic.nilOr(Logic.readBoolOrNil(args.noCountry), true),
staff = Logic.readBool(args.staff),
tournaments = Array.map(Array.extractValues(Table.filterByKey(args, function(key)
return key:sub(1, #'tournament') == 'tournament'
end)), Page.pageifyLink),
}

if Logic.isEmpty(self.config.tournaments) then
self.config.tournaments = {Page.pageifyLink(mw.title.getCurrentTitle().text)}
end

return self
end

---@return string
function CountryRepresentation:_buildConditions()
local conditions = ConditionTree(BooleanOperator.all):add{
ConditionNode(ColumnName('mode'), Comparator.neq, 'award_individual'),
ConditionTree(BooleanOperator.any):add(
Array.map(self.config.tournaments, function(page)
return ConditionNode(ColumnName('pagename'), Comparator.eq, page)
end)
),
}

return conditions:toString()
end

---@return self
function CountryRepresentation:fetchAndProcess()
local queryResult = mw.ext.LiquipediaDB.lpdb('placement', {
limit = 5000,
offset = 0,
conditions = self:_buildConditions(),
query = 'opponentplayers',
})

local count = 0
local cache = {}
local byCountry = {}
local handleEntry = function(prefix, players)
local page = players[prefix]
if Logic.isEmpty(page) or cache[page] then return end

local flag = players[prefix .. 'flag']
if Logic.isEmpty(flag) and not self.config.showNoCountry then return end

cache[page] = true
count = count + 1

byCountry[flag or ''] = byCountry[flag or ''] or {}
table.insert(byCountry[flag or ''], {page = page, displayName = players[prefix .. 'dn']})
end

Array.forEach(queryResult, function(placement)
local players = placement.opponentplayers or {}
for prefix in Table.iter.pairsByPrefix(players, 'p') do
handleEntry(prefix, players)
end
if not self.config.staff then return end
for prefix in Table.iter.pairsByPrefix(players, 'c') do
handleEntry(prefix, players)
end
end)

-- sort the players alphabetically for each country
for _, tbl in pairs(byCountry) do
table.sort(tbl, function(player1, player2)
return string.lower(player1.page) < string.lower(player2.page)
end)
end

self.byCountry = byCountry
self.count = count

return self
end

---@return Widget
function CountryRepresentation:create()
local cache = {rank = 0, counter = 0, lastCount = 0}
local rows = {}
for country, players in Table.iter.spairs(self.byCountry, CountryRepresentation._sortCountries) do
cache.counter = cache.counter + 1
if #players ~= cache.lastCount then
cache.rank = cache.counter
end
cache.lastCount = #players
table.insert(rows, Tr{
children = {
Td{css = {['text-align'] = 'right'}, children = {cache.rank}},
Td{children = {Flags.Icon(country), '&nbsp;', country}},
Td{css = {['text-align'] = 'right'}, children = {self:_ratioDisplay(#players)}},
Td{children = {table.concat(Array.map(players, function(player)
return Page.makeInternalLink({}, player.displayName or player.page, player.page)
end), ', ')}},
}
})
end

local headerRow = Tr{
children = {
Th{classes = {'unsortable'}, children = {'#'}},
Th{children = {'Country / Region'}},
Th{children = {'Representation'}},
Th{classes = {'unsortable'}, children = {'Players'}},
}
}

return DataTable{
classes = {'sortable'},
children = WidgetUtil.collect(headerRow, rows),
}
end

---@param byCountry {page:string, displayName: string?}[]
---@param country1 string
---@param country2 string
---@return boolean
function CountryRepresentation._sortCountries(byCountry, country1, country2)
if #byCountry[country1] ~= #byCountry[country2] then
return #byCountry[country1] > #byCountry[country2]
end
return country1 < country2
end

---@param numberOfPlayers integer
---@return string
function CountryRepresentation:_ratioDisplay(numberOfPlayers)
local percentage = self.count == 0 and 0 or MathUtil.round(100 * numberOfPlayers / self.count, 0)
return numberOfPlayers .. ' / ' .. self.count .. ' (' .. percentage .. '%)'
end

return CountryRepresentation
2 changes: 0 additions & 2 deletions components/earnings/wikis/halo/earnings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ local Lua = require('Module:Lua')

local CustomEarnings = Lua.import('Module:Earnings/Base')

CustomEarnings.defaultNumberOfPlayersInTeam = 4

-- Legacy entry points
---@deprecated
function CustomEarnings.calc_player(input)
Expand Down
2 changes: 0 additions & 2 deletions components/earnings/wikis/rocketleague/earnings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ local Lua = require('Module:Lua')

local CustomEarnings = Lua.import('Module:Earnings/Base')

CustomEarnings.defaultNumberOfPlayersInTeam = 3

-- Legacy entry points
---@deprecated
function CustomEarnings.calc_player(input)
Expand Down
2 changes: 0 additions & 2 deletions components/earnings/wikis/valorant/earnings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ local Lua = require('Module:Lua')

local CustomEarnings = Lua.import('Module:Earnings/Base')

CustomEarnings.defaultNumberOfPlayersInTeam = 5

-- Legacy entry points
---@deprecated
function CustomEarnings.calc_player(input)
Expand Down
16 changes: 0 additions & 16 deletions components/earnings/wikis/worldofwarcraft/earnings.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

local Array = require('Module:Array')
local Class = require('Module:Class')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local String = require('Module:StringUtils')
local Variables = require('Module:Variables')
local Table = require('Module:Table')
Expand All @@ -24,15 +26,14 @@ local DROPDOWN_ARROW = '&#8203;▼&#8203;'
---@field transform? fun(item: string): string
---@field expandKey string?
---@field expandable boolean?
---@field additionalClass string?
---@field order? fun(a: string, b: string): boolean
---@field load? fun(cat: FilterButtonCategory): FilterButtonCategory

---Builds filterbuttons based on config stored in Module:FilterButtons/Config
---Can be used from wikicode
---@return Html
function FilterButtons.getFromConfig()
return FilterButtons.get(require('Module:FilterButtons/Config').categories)
return FilterButtons.get(Lua.import('Module:FilterButtons/Config').categories)
end

---Entrypoint building a set of FilterButtons
Expand Down Expand Up @@ -84,12 +85,9 @@ function FilterButtons.getButtonRow(category)
:wikitext('All')
:done()

if String.isNotEmpty(category.additionalClass) then
buttons:addClass(category.additionalClass)
end

local transform = category.transform or FnUtil.identity
for _, value in ipairs(category.items or {}) do
local text = category.transform and category.transform(value) or value
local text = transform(value)
local button = mw.html.create('span')
:addClass('filter-button')
:attr('data-filter-on', value)
Expand All @@ -116,10 +114,6 @@ function FilterButtons.getButtonRow(category)
:css('display','none')
:attr('data-filter-on', 'all'))

if String.isNotEmpty(category.additionalClass) then
dropdownButton:addClass(category.additionalClass)
end

buttons:node(dropdownButton)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
-- @Liquipedia
-- wiki=apexlegends
-- page=Module:FilterButtons/Config
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Tier = require('Module:Tier/Utils')
local Config = {}

Config.categories = {
{
name = 'liquipediatier',
property = 'liquipediaTier',
load = function(category)
category.items = {}
for _, tier in Tier.iterate('tiers') do
table.insert(category.items, tier.value)
end
end,
defaultItems = {'1', '2', '3', '4', '5'},
transform = function(tier)
return Tier.toName(tier)
end,
},
}

return Config
44 changes: 44 additions & 0 deletions components/filter_buttons/wikis/dota2/filter_buttons_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
-- @Liquipedia
-- wiki=dota2
-- page=Module:FilterButtons/Config
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Tier = require('Module:Tier/Utils')
local Config = {}

Config.categories = {
{
name = 'liquipediatier',
property = 'liquipediaTier',
load = function(category)
category.items = {}
for _, tier in Tier.iterate('tiers') do
table.insert(category.items, tier.value)
end
end,
defaultItems = {'1', '2', '3'},
transform = function(tier)
return Tier.toName(tier)
end,
expandKey = "liquipediatiertype",
},
{
name = 'liquipediatiertype',
property = 'liquipediaTierType',
expandable = true,
load = function(category)
category.items = {}
for _, tiertype in Tier.iterate('tierTypes') do
table.insert(category.items, Tier.toIdentifier(tiertype.value))
end
end,
transform = function(tiertype)
return select(2, Tier.toName(1, tiertype))
end,
},
}

return Config
29 changes: 29 additions & 0 deletions components/filter_buttons/wikis/halo/filter_buttons_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
-- @Liquipedia
-- wiki=halo
-- page=Module:FilterButtons/Config
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Tier = require('Module:Tier/Utils')
local Config = {}

Config.categories = {
{
name = 'liquipediatier',
property = 'liquipediaTier',
load = function(category)
category.items = {}
for _, tier in Tier.iterate('tiers') do
table.insert(category.items, tier.value)
end
end,
defaultItems = {'1', '2', '3', '4'},
transform = function(tier)
return Tier.toName(tier)
end,
},
}

return Config
Loading

0 comments on commit f9f036e

Please sign in to comment.