Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Rousseaulambertlp
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local getArgs = require('Module:Arguments').getArgs local datePattern = "^(%d+)-(%d+)$" -- local weatherTemplate = 'Template:Weather box' local weatherTemplate = 'Template:Climat' local wrapsTemplate = 'User:Rousseaulambertlp/Weather box' function p.weatherbox( frame ) local args = getArgs(frame, { wrappers = wrapsTemplate }) local dataPage = assert(args.data, 'Missing "data" parameter') args.data = nil local monthlyHigh, monthlyLow = {}, {} local highSum, highCount = {}, {} local lowSum, lowCount = {}, {} local avgHighSum, avgHighCount = {}, {} local avgLowSum, avgLowCount = {}, {} local precipSum, precipCount = {}, {} local snowfallSum, snowfallCount = {}, {} -- 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, avgLowTemp, extHighTemp, extLowTemp, precipTotalRain, precipTotalSnow, precipTotal, snowGrndLastDay, windDirMaxGust, windSpeedMaxGust = unpack(row) local year, month = date:match(datePattern) month = tonumber(month) if extHighTemp ~= nil and (monthlyHigh[month] == nil or monthlyHigh[month] < extHighTemp) then monthlyHigh[month] = extHighTemp end if extLowTemp ~= nil and (monthlyLow[month] == nil or monthlyLow[month] > extLowTemp) then monthlyLow[month] = extLowTemp end recordAvg(highSum, highCount, month, extHighTemp) recordAvg(lowSum, lowCount, month, extLowTemp) recordAvg(avgHighSum, avgHighCount, month, avgHighTemp) recordAvg(avgLowSum, avgLowCount, month, avgLowTemp) recordAvg(precipSum, precipCount, month, precipTotal) recordAvg(snowfallSum, snowfallCount, month, precipTotalSnow) end local months = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'} for i=1, 12 do args[months[i] .. 'tmax-'] = monthlyHigh[i] end for i=1, 12 do args[months[i] .. 'tmin-'] = 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[months[i] .. 'prec-'] = 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
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Rousseaulambertlp/doc
(
edit
)