Modul:Goalscorers: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan |
perbaikan averageString dan updateString untuk bagian templat |
||
(23 revisi perantara oleh 2 pengguna tidak ditampilkan) | |||
Baris 1:
require('
local yesno = require('Module:Yesno')
Baris 51:
--[[ ############################## Main function and other functions ######################
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
--
p.selectGoalscorers("OG")
Baris 83 ⟶ 88:
return p.error_msg() or outputString
end
function p.addIntroductorySentence() --
local totalGoalString = "Sebanyak" .. g.totalGoals .. "
local matches, dateUpdated = p.getNumberMatches()
Baris 93 ⟶ 97:
local Date = require('Module:Date')._Date
local text1 = ""
if g.totalGoals
if dateUpdated ~= 'complete' or dateUpdated ~= 'completed' or dateUpdated ~= 'selesai' then text1 = "telah dicetak" end
else
if dateUpdated == 'complete'
end
local text = string.format("Sebanyak %s gol %s", mw.getLanguage('id'):formatNum(g.totalGoals), text1)
if matches then
local average = g.totalGoals/tonumber(matches) -- menghitung rata-rata gol
local precision = 3 --
if average < 1 then precision = 2 end --
average =
text = text .. string.format(" pada %d pertandingan, dengan rata-rata %s gol per pertandingan", matches, mw.getLanguage('id'):formatNum( tonumber(average)))
end
if dateUpdated == 'complete' or dateUpdated =='completed' or dateUpdated =='selesai' or dateUpdated == "" then
text = text .. "."
else
Baris 124 ⟶ 123:
if mdyFormat == false then dateFormat = "dmy" end -- template param overrides
end
text = text .. "
end
text = p.addAdditionHeaderText(text, dateUpdated) -- handles template parameters bold, further, extra
Baris 130 ⟶ 129:
return text --totalGoalString
end
function p.addFooterSentence() --
local footerSentence = g.args['footer'] or ""
Baris 154 ⟶ 153:
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 round, group = p.getRoundAndGroup()
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 166:
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
if round == "all" then -- all rounds and goals
matches=0
Baris 175 ⟶ 178:
dateUpdated = latestGroupDate -- update if later date
end
matches = matches + v[1]
if v[2] ~= "complete" and v[2] > dateUpdated then dateUpdated = v[2] end -- update if later date
Baris 218 ⟶ 221:
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 ######################
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()
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 players who have scored in rounds/groups requested
Baris 245 ⟶ 276:
local playerName, playerAlias = p.getPlayer(v[1]) -- player name
local goalsByRound, commentByRound = 0, ""
if round == "all" then -- goals
if group and group ~= "all" and 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 --TODO use getGoals on round options
if commentByRound ~= "" then
Baris 259 ⟶ 295:
i = i+1
end
elseif round == "
--TODO code to go through all rounds but only include goals in specified group [TODO merge with above option]
--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 291 ⟶ 347:
g.totalGoals = g.totalGoals + math.abs(goals) -- increment total goal counter
end
end
--[[ p.getRoundAndGroup()
]]
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
--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
end
--[[ p.getGroup(country, possibleGroup)
- 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 368 ⟶ 460:
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 473 ⟶ 573:
table.sort(items, function(a,b) return a<b end) -- sort the table alphbetically
local list = "
for i=1, #items do
local sep = ", " -- separator for comma-delimited list
Baris 573 ⟶ 673:
local tableString = '\n{| class="wikitable"' -- start table
..'\n|-' .. '\n!
if g.args['header'] then tableString = tableString .. '\n|+ ' .. g.args['header'] end -- add header
for j,u in pairs(g.goalscorers) do -- run through sorted list of selected goalscorers
Baris 615 ⟶ 715:
local rowSpan = rankCount
if playerCount > maxRank * 1.5 then
firstplayerCell = '\n| style="font-style:italic;text-align:center;"|' .. rankCount .. "
playerCells = ""
rowSpan = 1
Baris 636 ⟶ 736:
end
end -- reached end of list of goalscorers
-- if all scorers on one goal, tableString isn't updated in loop above (may need to generalise for other goal number)
if goalNumber == 1 then
local rowSpan = rankCount + 1
tableString = tableString .. '\n|-\n| style="text-align:center;" rowspan="' .. rowSpan .. '"|' .. rank
tableString = tableString .. firstplayerCell
tableString = tableString .. '\n| style="text-align:center;" rowspan="' .. rowSpan .. '"|' .. goalNumber
tableString = tableString .. playerCells
end
if tableString ~= "" then
Baris 641 ⟶ 750:
return tableString
else
return ("
end
Baris 669 ⟶ 778:
goalNumber = u['goals']
local goalString = "
--if og == "OG" then
if goalNumber < 0 then
goalString =
end
if math.abs(u['goals']) ~= 1 then goalString = goalString end
outputString = outputString .. "\n'''" .. math.abs(u['goals']) .. goalString .. "'''" -- list caption
Baris 713 ⟶ 823:
return outputString
else
return ("
end
end
Baris 752 ⟶ 862:
end
if g.args['bold'] and g.args['bold']~='no' then
text = text .. "
end
if g.args['further'] then
Baris 782 ⟶ 892:
--getArgs(frame)
--[[
{{#if:{{{own_goals|}}}| (dengan {{{own_goals}}} gol di antaranya termasuk ke dalam
{{formatnum: {{#expr:{{{goals}}}/{{{matches}}} round 2}}}}
{{#if:{{{further|}}}|{{#if:{{{assists|}}}|| }}{{{further}}}|}}
--]]
local statNumber =
local matches = g.args['matches']
local statType = "
if g.args['assists'] or g.args['umpan gol'] then statType = "
if g.args['clean sheets'] or g.args['nirbobol'] then statType = "
local ongoing = g.args['ongoing']
local text1 = "
if g.args['lc'] then text1 = "
local text2 = "
if ongoing then text2 = "
local updateString = ""
local averageString = ""
-- auto version: string.format(" pada %d pertandingan, dengan rata-rata %.3g gol per pertandingan")
if g.args['goals'] and g.args['matches'] then
local averageGoals = g.args['goals']/g.args['matches']
averageString = string.format("%.3g", averageGoals)
end
if g.args['updated'] and g.args['updated'] ~= "complete" and g.args['updated'] ~= "completed" and g.args['updated'] ~= "selesai" then
updateString = " (
end
local sep = "."
if g.args['sep'] then sep = g.args['sep'] end
local text = ""
if g.args['goals'] then --Sebanyak %statNumber %statType telah dicetak pada %matches pertandingan, dengan rata-rata %averageString per pertandingan (%updateString)
text = string.format("%s %s %
text1, text2, statNumber, statType,
end
text = p.addAdditionHeaderText(text) -- handles template parameters bold, further, extra
Baris 852 ⟶ 950:
if number < 0 then
entry = g.args[math.abs(number) .. ' own goals'] or g.args[math.abs(number) .. ' own goal']
statType = "
end
if entry then -- do we have goals/assists for this number
output = output .. "\n'''" .. tostring(math.abs(number)) .. " " .. statType
.. p.openList(frame) .. "\n" .. entry .. p.closeList(frame)
totalGoals = p.countGoals(entry, number, totalGoals)
Baris 867 ⟶ 963:
end
if statType == "
if g.args['goals'] and totalGoals ~= tonumber(g.args['goals']) then
mw.addWarning("
end
end
Baris 888 ⟶ 984:
--{{#if:{{{source|}}}|{{small|Source: {{{source}}}}}|}}
local source = g.args['source'] or ""
if source ~= "" then source = "<small>
return text .. output .. footer .. source
|