Modul:Goalscorers: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Tidak ada ringkasan suntingan
perbaikan averageString dan updateString untuk bagian templat
 
(22 revisi perantara oleh 2 pengguna tidak ditampilkan)
Baris 1:
require('Module:No globalsstrict');
local yesno = require('Module:Yesno')
 
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 83 ⟶ 88:
return p.error_msg() or outputString
end
function p.addIntroductorySentence() -- addmenambahkan introductoryteks/paragraf textawal
local totalGoalString = "Sebanyak" .. g.totalGoals .. " telah dicetak."
--There were [has been|have been|was|were] #GOALS goal(s) scored in #MATCHES match(s), for an average of #GOALS/#MATCHES per match.
local matches, dateUpdated = p.getNumberMatches()
Baris 93 ⟶ 97:
local Date = require('Module:Date')._Date
local pluralGoals = "s"
local text1 = ""
if g.totalGoals =>= 1 then
if dateUpdated ~= 'complete' or dateUpdated ~= 'completed' or dateUpdated ~= 'selesai' then text1 = "telah dicetak" end
pluralGoals = ""
if dateUpdated == 'complete' then text1 = " " else text1 = " " end
else
if dateUpdated == 'complete' thenor text1dateUpdated == "'completed' "or elsedateUpdated == 'selesai' then text1 = " dicetak" end
end
local text = string.format("Sebanyak %s %s goal%s telah dicetak", text1, mw.getLanguage('en'):formatNum(g.totalGoals), pluralGoals)
local text = string.format("Sebanyak %s gol %s", mw.getLanguage('id'):formatNum(g.totalGoals), text1)
local pluralMatches = "."
if matches==1 then pluralMatches = "" end
if matches then
local average = g.totalGoals/tonumber(matches) -- menghitung rata-rata gol
local precision = 3 -- displaypresisi d.dddua (threeangka significantdibelakang disgits)koma
if average < 1 then precision = 2 end -- displaypresisi 0.ddsatu (thwoangka significantdibelakang disgits)koma
average = tostring string.format("%."..precision.."g", average)
 
text = text .. string.format(" pada %d pertandingan, dengan rata-rata %s gol per pertandingan", matches, mw.getLanguage('id'):formatNum( tonumber(average)))
local pluralAverage = "."
if tonumber(string.format("%.2f",average))==1 then pluralAverage = "" end
text = text .. string.format(" pada %d match%s, dengan rata-rata %."..precision.."g goal%s per pertandingan", matches, pluralMatches, average, pluralAverage)
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 .. " &nbsp;(as ofper " .. Date(dateUpdated):text(dateFormat) .. ")."
end
text = p.addAdditionHeaderText(text, dateUpdated) -- handles template parameters bold, further, extra
Baris 130 ⟶ 129:
return text --totalGoalString
end
function p.addFooterSentence() -- addmenambahkan notesteks atakhir/catatan bottomkaki
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
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 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 ######################
-- 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 245 ⟶ 276:
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 259 ⟶ 295:
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 291 ⟶ 347:
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 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 = "againstlawan " -- construct the alphabetical list string
for i=1, #items do
local sep = ", " -- separator for comma-delimited list
Baris 573 ⟶ 673:
 
local tableString = '\n{| class="wikitable"' -- start table
..'\n|-' .. '\n!RankPeringkat !! PlayerPemain !! GoalsGol' -- add table headers
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 .. " playerspemain"
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 ("No goalsTidak matchingada requestedgol criteriayang sesuai dengan kriteria yang diminta.")
end
Baris 669 ⟶ 778:
goalNumber = u['goals']
local goalString = " goalgol"
--if og == "OG" then
if goalNumber < 0 then
goalString = "string.format own("%s ..bunuh diri", goalString )
end
if math.abs(u['goals']) ~= 1 then goalString = goalString .. "s" 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 ("No goalsTidak matchingada requestedgol criteriayang sesuai dengan kriteria yang diminta.")
end
end
Baris 752 ⟶ 862:
end
if g.args['bold'] and g.args['bold']~='no' then
text = text .. " PlayersPemain highlighted indengan '''boldcetak tebal''' are stillmasih activebermain inpada theturnamen competitionini."
end
if g.args['further'] then
Baris 790 ⟶ 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|}}}||&nbsp;}}Pemain bercetakdengan '''cetak tebal''' masih bermain pada turnamen ini.|}}
{{#if:{{{further|}}}|{{#if:{{{assists|}}}||&nbsp;}}{{{further}}}|}}
{{#if:{{{extra|}}}|{{{extra}}}{{clear}}|}}
--]]
local statNumber = gmw.args[getLanguage('goalsid']):formatNum( ortonumber( g.args['assistsgoals'] or 0) ) --format number as string
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 = "theresebanyak" end
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(" pada %d match%s, dengan rata-rata %.3g", goal%s per pertandingan"averageGoals)
end
if g.args['updated'] and g.args['updated'] ~= "complete" and g.args['updated'] ~= "completed" and g.args['updated'] ~= "selesai" then
updateString = "&nbsp;(per " ..g.args['updated'].. ")"
end
local titiksep = "."
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)
if g.args['goals'] then
text = string.format("%s %ds %s %s dicetak pada %d pertandingan, dengan rata-rata %s gol per pertandingan"..updateString..sep,
text1, text2, statNumber, statType, averageStringg.args['matches'], mw.updateString..titikgetLanguage('id'):formatNum( tonumber(averageString)))
end
text = p.addAdditionHeaderText(text) -- handles template parameters bold, further, extra
Baris 838 ⟶ 952:
statType = "gol bunuh diri"
end
local plural = "s"
if number == 1 or number == -1 then plural = "" end
if entry then -- do we have goals/assists for this number
 
output = output .. "\n'''" .. tostring(math.abs(number)) .. " " .. statType .. plural .. "'''\n"
.. p.openList(frame) .. "\n" .. entry .. p.closeList(frame)
totalGoals = p.countGoals(entry, number, totalGoals)
Baris 853 ⟶ 965:
if statType == "gol" or statType == "gol bunuh diri" then
if g.args['goals'] and totalGoals ~= tonumber(g.args['goals']) then
mw.addWarning("PERINGATAN. MismatchJumlah betweengol numberpada of goals listedterdaftar (" .. totalGoals .. ") and goalsdan parameter gol (" .. g.args['goals'] .. ") tidak cocok.")
end
end