Modul:Goalscorers: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Membalikkan revisi 21216427 |
perbaikan averageString dan updateString untuk bagian templat |
||
(13 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 85 ⟶ 90:
function p.addIntroductorySentence() -- menambahkan teks/paragraf awal
local totalGoalString = "Sebanyak" .. g.totalGoals .. "
local matches, dateUpdated = p.getNumberMatches()
Baris 92 ⟶ 97:
local Date = require('Module:Date')._Date
local text1 = ""
if g.totalGoals >= 1 then
if dateUpdated ~= 'complete' or dateUpdated ~= 'completed' or dateUpdated ~= 'selesai' then text1 = "telah dicetak" end
else
if dateUpdated == 'complete' or dateUpdated == 'completed' or dateUpdated == 'selesai' then text1 = "dicetak" end
end
local text = string.format("Sebanyak %s gol %s", mw.getLanguage('id'):formatNum(g.totalGoals), text1)
if matches then
local average =
local precision = 3 -- presisi dua angka dibelakang koma
if average < 1 then precision = 2 end -- presisi satu angka dibelakang koma
average = string.format("%."..precision.."g", average)
end
if dateUpdated == 'complete' or dateUpdated =='completed' or dateUpdated =='selesai' or dateUpdated == "" then
text = text .. "."
else
Baris 142 ⟶ 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 154 ⟶ 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 163 ⟶ 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 206 ⟶ 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 233 ⟶ 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 247 ⟶ 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 279 ⟶ 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 356 ⟶ 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 461 ⟶ 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 624 ⟶ 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 629 ⟶ 750:
return tableString
else
return ("
end
Baris 662 ⟶ 783:
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
Baris 700 ⟶ 823:
return outputString
else
return ("
end
end
Baris 739 ⟶ 862:
end
if g.args['bold'] and g.args['bold']~='no' then
text = text .. " Pemain
end
if g.args['further'] then
Baris 777 ⟶ 900:
{{#ifexpr:{{{matches}}}=1|pertandingan|pertandingan}}, dengan rata-rata
{{formatnum: {{#expr:{{{goals}}}/{{{matches}}} round 2}}}} {{formatnum:{{#ifexpr:({{{goals}}}/{{{matches}}} round 2)=1|gol|gol}}}} per pertandingan.}}
{{#if:{{{bold|}}}|{{#if:{{{assists|}}}|| }}Pemain
{{#if:{{{further|}}}|{{#if:{{{assists|}}}|| }}{{{further}}}|}}
{{#if:{{{extra|}}}|{{{extra}}}{{clear}}|}}
--]]
local statNumber =
local matches = g.args['matches']
local statType = "gol"
if g.args['assists'] or g.args['umpan gol'] then statType = "umpan gol" end
if g.args['clean sheets'] or g.args['nirbobol'] then statType = "nirbobol" end
local ongoing = g.args['ongoing']
local text1 = "Sebanyak"
if g.args['lc'] then text1 = "
local text2 = ""
if ongoing then text2 = "telah" end
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("
end
if g.args['updated'] and g.args['updated'] ~= "complete" and g.args['updated'] ~= "completed" and g.args['updated'] ~= "selesai" then
updateString = " (per " ..g.args['updated'].. ")"
end
local
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 %
text1, text2, statNumber, statType,
end
text = p.addAdditionHeaderText(text) -- handles template parameters bold, further, extra
Baris 838 ⟶ 965:
if statType == "gol" or statType == "gol bunuh diri" then
if g.args['goals'] and totalGoals ~= tonumber(g.args['goals']) then
mw.addWarning("PERINGATAN.
end
end
|