Module:Sandbox2/Rousseaulambertlp
Apparence
La documentation de ce module est générée par le modèle {{Documentation module}}.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local datePattern = "^(%d+)-(%d+)$"
-- local weatherTemplate = 'Template:Weather box'
local weatherTemplate = 'Modèle:Graphique_polygonal'
local wrapsTemplate = 'Utilisateur:Rousseaulambertlp/GraphBox'
function p.weathergraph( frame )
local args = getArgs(frame, { wrappers = wrapsTemplate })
local dataPage = assert(args.data, 'Missing "data" parameter')
args.data = nil
local dataPage2 = assert(args.data2, 'Missing "data2" parameter')
args.data2 = nil
local monthlyHigh_bag, monthlyLow_bag = {}, {}
local highSum_bag, highCount_bag = {}, {}
local lowSum_bag, lowCount_bag = {}, {}
local avgHighSum_bag, avgHighCount_bag = {}, {}
local avgLowSum_bag, avgLowCount_bag = {}, {}
local precipSum_bag, precipCount_bag = {}, {}
local snowfallSum_bag, snowfallCount_bag = {}, {}
-- There is currently no established way to specify sources, suggestions needed
-- For now, prepend the link to edit box to the first source
-- local source = args['source'] or args['source 1']
-- if source then source = '<br>' .. source end
-- args['source'] = '[[commons:Data:'.. dataPage ..'|edit data]]' .. source
-- args['source 1'] = nil
for key, row in pairs(mw.ext.data.get(dataPage).data) do
local date, avgHighTemp_bag, avgLowTemp_bag, avgTemp_bag, extHighTemp_bag, extLowTemp_bag, precipTotalRain_bag, precipTotalSnow_bag, precipTotal_bag, snowGrndLastDay_bag, windDirMaxGust_bag, windSpeedMaxGust_bag = unpack(row)
local year, month = date:match(datePattern)
month = tonumber(month)
if extHighTemp_bag ~= nil and (monthlyHigh_bag[month] == nil or monthlyHigh_bag[month] < extHighTemp_bag) then monthlyHigh_bag[month] = extHighTemp_bag end
if extLowTemp_bag ~= nil and (monthlyLow_bag[month] == nil or monthlyLow_bag[month] > extLowTemp_bag) then monthlyLow_bag[month] = extLowTemp_bag end
recordAvg(highSum_bag, highCount_bag, month, extHighTemp_bag)
recordAvg(lowSum_bag, lowCount_bag, month, extLowTemp_bag)
recordAvg(avgHighSum_bag, avgHighCount_bag, month, avgHighTemp_bag)
recordAvg(avgLowSum_bag, avgLowCount_bag, month, avgLowTemp_bag)
recordAvg(precipSum_bag, precipCount_bag, month, precipTotal_bag)
recordAvg(snowfallSum_bag, snowfallCount_bag, month, precipTotalSnow_bag)
end
local months = {'jan','fev','mar','avr','mai','jui','jul','aou','sep','oct','nov','dec'}
for i=1, 10 do args['S01V0' .. i] = monthlyHigh_bag[i] end
for i=10, 12 do args['S01V' .. i] = monthlyHigh_bag[i] end
-- for i=1, 12 do args['tmin-' .. months[i]] = monthlyLow[i] end
-- for i=1, 12 do args[months[i] .. 'avg record high C'] = string.format("%.1f", highSum[i] / highCount[i]) end
-- for i=1, 12 do args[months[i] .. 'avg record low C'] = string.format("%.1f", lowSum[i] / lowCount[i]) end
-- for i=1, 12 do args[months[i] .. 'high C'] = string.format("%.1f", avgHighSum[i] / avgHighCount[i]) end
-- for i=1, 12 do args[months[i] .. 'low C'] = string.format("%.1f", avgLowSum[i] / avgLowCount[i]) end
-- for i=1, 12 do args['prec-' .. months[i]] = string.format("%.1f", precipSum[i] / precipCount[i]) end
-- for i=1, 12 do args[months[i] .. ' snow mm'] = string.format("%.1f", snowfallSum[i] / snowfallCount[i]) end
return frame:expandTemplate{ title = weatherTemplate, args = args }
end
function recordAvg(sumTbl, countTbl, month, value)
if value ~= nil then
sumTbl[month] = (sumTbl[month] or 0) + value
countTbl[month] = (countTbl[month] or 0) + 1
end
end
return p