From 1797d51112668e6b9fe278b80a835e4436487771 Mon Sep 17 00:00:00 2001 From: Hesketh2 <88981446+Hesketh2@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:50:28 +0700 Subject: [PATCH] feat(infobox_extensions): create automated game appearances for players (#4178) * feat: add GameAppearances as Extension module * 1st attempt at fixing this is gonna take a while to figured it out * 2nd attempt * 3rd * return string * Update infobox_extension_game_appearances.lua * Update infobox_extension_game_appearances.lua * With the suggested changes I still need a way for this extension to catch Underscores vs non-Underscores cases. That would be the last thing needed before this can go merged * Update infobox_extension_game_appearances.lua --- .../infobox_extension_game_appearances.lua | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 components/infobox/extensions/commons/infobox_extension_game_appearances.lua diff --git a/components/infobox/extensions/commons/infobox_extension_game_appearances.lua b/components/infobox/extensions/commons/infobox_extension_game_appearances.lua new file mode 100644 index 00000000000..14982335d73 --- /dev/null +++ b/components/infobox/extensions/commons/infobox_extension_game_appearances.lua @@ -0,0 +1,55 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:Infobox/Extension/GameApperances +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Array = require('Module:Array') +local Game = require('Module:Game') +local Table = require('Module:Table') + +local DEFAULT_MAX_NUMBER_OF_PLAYERS_IN_PLACEMENT = 10 + +local Appearances = {} + +----Provide a list of games compete by a player +---@param args {player: string?, numberOfPlayersInPlacement}? +---@return string[]? +function Appearances.player(args) + if not args or not args.player then return end + local numberOfPlayersInPlacement = args.numberOfPlayersInPlacement or DEFAULT_MAX_NUMBER_OF_PLAYERS_IN_PLACEMENT + + local player = args.player:gsub(' ', '_') + local playerWithoutUnderscores = args.player:gsub('_', ' ') + + local conditions = { + '[[opponentname::' .. player .. ']]', + '[[opponentname::' .. playerWithoutUnderscores .. ']]', + } + + Array.forEach(Array.range(1, numberOfPlayersInPlacement), function(index) + Array.appenWith(conditions, + '[[opponentplayers_p' .. index .. '::' .. player .. ']]', + '[[opponentplayers_p' .. index .. '::' .. playerWithoutUnderscores .. ']]' + ) + end) + + local queriedGames = Table.map(mw.ext.LiquipediaDB.lpdb('placement', { + conditions = table.concat(conditions, ' OR '), + query = 'game', + groupby = 'game asc', + limit = 1000, + }), function(_, item) return Game.toIdentifier{game = item.game, useDefault = false}, true end) + + local orderedGames = Array.filter(Game.listGames{ordered = true}, function(game) + return queriedGames[game] + end) + + return Array.map(orderedGames, function(game) + return Game.name{game = game} + end) +end + +return Appearances