Modul:Goalscorers: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan
Tidak ada ringkasan suntingan
Baris 51:
--[[ ############################## Main function and other functions ######################
 
p.main() - simple output of the data in the module in list form
p.addIntroductorySentence() - menambah kalimat/paragraf pembuka jumlah gol dan rata-rata gol per pertandingan
p.addFooterSentence() - menambah catatan kaki
p.getNumberMatches()
p.owngoals() - get own goals (no longer used?)
p._owngoals() - core functionality for p.owngoals()
]]
function p.main(frame)
Baris 68 ⟶ 73:
--p.goalscorers = {} -- table where selected and sorted players will be place
g.totalGoals = 0
local ok = p.selectGoalscorers() -- selected goalscorers meeting round and group criteris
-- CHANGEeCHANGE: append own goals to list (data will now include goals and own goals (negative))
p.selectGoalscorers("OG")
Baris 142 ⟶ 147:
local dateUpdated = data.updated['date'] or "1700-01-01" --'complete' -- assume completed if missing
--local round = g.args['round'] or "all" -- round = all(empty)|group|playoffs
--local group = g.args['group'] or "all" -- group = all(empty), A,B,C etc
local allGroupGames = 0
local latestGroupDate = "1800-01-01"
if group and (round == "all" or group == "all") then -- count all the group games
for k,v in pairs(data.updated.group) do
allGroupGames = allGroupGames + v[1]
Baris 153 ⟶ 158:
end
if latestGroupDate == "1800-01-01" then latestGroupDate = "complete" end -- no dates so must be complete
end
if group and (round == "all" and group ~= "all") then -- for totals of all rounds with only one group
allGroupGames = data.updated.group[group][1] -- number matches
latestGroupDate = data.updated.group[group][2] -- update date or completed
end
 
Baris 163 ⟶ 172:
dateUpdated = latestGroupDate -- update if later date
end
elseelseif p.validateRound(k) then
matches = matches + v[1]
if v[2] ~= "complete" and v[2] > dateUpdated then dateUpdated = v[2] end -- update if later date
Baris 206 ⟶ 215:
end
 
function p.validateRound(round)
local validateRound = false
for k,v in pairs(data.rounds) do
if k == round then validateRound = true end -- data for this round exists
end
return validateRound
end
 
--[[ ############################## functions to select goalscorers ######################
-- select players meeting round and goal criteria
p.selectGoalscorers() - select goals scoreers required for list (rounds, groups)
p.getRoundAndGroup()
p.getGoalsCol(round) - get column containing round data or first data column if round = all
(country, possibleGroup)
p.getGoals (u, player)
p.parseComment(comment)
p.getPlayer(u)
]]
--[[ p.selectGoalscorers()
- select players meeting round and group criteria from goalscoreres list
- gets goals and comments
]]
function p.selectGoalscorers(og)
 
local round, group = p.getRoundAndGroup()
--data = require('Module:Goalscorers/data/'.. g.args[1]) --or 'UEFA Euro 2016 qualifying'
if not round then return false end -- exit if no valid round
local goalMinimum = tonumber(g.args['minimum']) or -5 -- assume 5 own goals is maximum
local goalsCol = p.getGoalsCol(round) -- first column for goals
-- select all players with goals totals for appropriate rounds
local round = g.args['round'] or "all" -- round = all(empty)|group|playoffs
local group = g.args['group'] or "all" -- group = all(empty), A,B,C etc
 
local goalsCol = p.getGoalsCol(round) -- 4 -- first column for goals
--local groupCol = 3 -- default column for group
if round then
-- goalsCol = data.rounds[round] or data.rounds[1] or 4 -- get column containing goals for that round or first round listed if all
end
--groupCol = data.group[round] or 3 -- get column containing goals for that round
-- select players who have scored in rounds/groups requested
Baris 233 ⟶ 270:
local playerName, playerAlias = p.getPlayer(v[1]) -- player name
local goalsByRound, commentByRound = 0, ""
if round == "all" then -- goals --in all rounds and goalsall groups
--local for i = 4goalsCol, #v, 1 do
for i = goalsCol, #v, 1 do --or while i <= #v do
if group and group ~= "all" and i == p.getGoalsCol("group") and group ~= p.getGroup(v[2], v[3]) then
goalsByRound, commentByRound = p.getGoals( v[i] , playerName)
goalsByRound = 0
commentByRound = ""
else
goalsByRound, commentByRound = p.getGoals( v[i] , playerName)
end
goals = goals + goalsByRound --TODO use getGoals on round options
if commentByRound ~= "" then
Baris 247 ⟶ 289:
i = i+1
end
elseif round == "groupall2" thenand group ~= "all" then -- goals in all rounds but only from --one group round only
--TODO code to go through all rounds but only include goals in specified group [TODO merge with above option]
--if group == v[groupCol] then -- single group only
--mw.addWarning( g.args[1] .. ":Mix:round=all and group=" .. group .. "/" .. p.getGroup(v[2], v[3] ) )
for i = goalsCol, #v, 1 do
if i == p.getGoalsCol("group") and group ~= p.getGroup(v[2], v[3]) then
goalsByRound = 0
commentByRound = ""
else
goalsByRound, commentByRound = p.getGoals( v[i] , playerName)
end
goals = goals + goalsByRound
if commentByRound ~= "" then
if comment == "" then
comment = commentByRound
else
comment = comment .. "," .. commentByRound --TODO decide on comma or semi-colon
end
end
i = i+1
end
elseif round == "group" then -- group round only
if group == p.getGroup(v[2], v[3]) then -- single group only
goals, comment = p.getGoals( v[goalsCol] , playerName)
elseif group == "all" then -- any group
goals, comment = p.getGoals( v[goalsCol] , playerName)
else
-- do nothing for other groups
end
--elseif round == "playoffs" then -- playoff round (redunant?)
Baris 279 ⟶ 341:
g.totalGoals = g.totalGoals + math.abs(goals) -- increment total goal counter
end
--return p.goalscorerstrue -- itdata iscollected availablefor anywayselected goalscorers
end
--[[ p.getRoundAndGroup()
--[[ get column for round or first round listed if "all"
]]
-allows group column to be omitted from player table when group table provided ]]
function p.getRoundAndGroup()
local round = g.args['round'] or "all" -- round = all(empty)|group|playoffs
local group = g.args['group'] or "all" -- group = all(empty), A,B,C etc
 
local validateRound = false
local validateGroupRound = false
for k,v in pairs(data.rounds) do
if k == round then validateRound = true end -- data for this round exists
if k == "group" then validateGroupRound = true end -- there is a group round
end
if validateRound == false and round ~= "all" then
local message = 'Invalid round "' .. round .. '" specified. No data found for that round. '
mw.addWarning( message )
p.errorString = p.errorString .. message
round = nil
end
if validateGroupRound == false then group = false end -- there is no group round
-- TODO add group error checking
-- Could merge with getGoalsCol() and also return goalsCol
return round, group
end
 
--[[ p.getGoalsCol(round)
- get column containing round data or first data column if round = "all"
- allows group column to be omitted from player table when group table provided
]]
function p.getGoalsCol(round)
 
local minimum = 1000
if round == "all" then -- if all need column of first round
for k,v in pairs(data.rounds) do
returnif v; --< returnminimum thethen firstminimum one= v end
--return v -- return the first one [this seemed to work reliably, but sometimes table order is not as listed]
end
return minimum
end
if data.rounds and data.rounds[round] then
return data.rounds[round] -- get column containing goals for that round
else
return 4 -- an old default when no data.round (may not be necessary)
end
return data.rounds[round] or 4 -- get column containing goals for that round or first round listed if all
end
--[[ p.getGroup(country, possibleGroup)
--[[ get group from group table or from player table ]]
- get group from group table or from player table
- possibleGroup is the column containing the Group (when no group table) or the first data column
]]
function p.getGroup(country, possibleGroup) -- row contain player name, country code, group if given, goals
if data.groups then
Baris 356 ⟶ 454:
end
end
 
--[[ ############################## functions to sort goalscorers ######################
p.preprocessSortName (name)
p.getPlayerSortName (playerName, sortName, countryName)
p.sortComment(comment)
p.getCountryName(country)
p.sortGoalscorers() -- the main sort funtion
]]
--[=[ function p.preprocessSortName()
stripp off wikitext [[ and ]]
Baris 461 ⟶ 567:
table.sort(items, function(a,b) return a<b end) -- sort the table alphbetically
 
local list = "againstlawan " -- construct the alphabetical list string
for i=1, #items do
local sep = ", " -- separator for comma-delimited list
Baris 662 ⟶ 768:
goalString = string.format ("%s bunuh diri", goalString )
end
if math.abs(u['goals']) ~= 1 then goalString = goalString end
 
outputString = outputString .. "\n'''" .. math.abs(u['goals']) .. goalString .. "'''" -- list caption
outputString = outputString .. p.openList(frame,og) --start new list