Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Anon423/ClimateCommons
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 = {} function p.getMonthHighestTemp(month, files) local max month = string.format("%02d", month) for file,data in pairs(files) do field_index = p.getColumnIndex("extremeMax", data) for index,values in pairs(data.data) do if string.find(string.sub(values[1], 1, 3), month, 1, true) then if max == nil or values[field_index] > max then max = values[field_index] end end end end return max end function p.getMonthLowestTemp(month, files) local min month = string.format("%02d", month) for file,data in pairs(files) do field_index = p.getColumnIndex("extremeMin", data) for index,values in pairs(data.data) do if string.find(string.sub(values[1], 1, 3), month, 1, true) then if min == nil or values[field_index] < min then min = values[field_index] end end end end return min end function p.getMonthHighestRainfall(month, files) local max month = string.format("%02d", month) for file,data in pairs(files) do field_index = p.getColumnIndex("extremeRainfall", data) for index,values in pairs(data.data) do if string.find(string.sub(values[1], 1, 3), month, 1, true) then if max == nil or values[field_index] > max then max = values[field_index] end end end end return max end function p.getMonthHighestSnowfall(month, files) local max month = string.format("%02d", month) for file,data in pairs(files) do field_index = p.getColumnIndex("extremeSnowfall", data) for index,values in pairs(data.data) do if string.find(string.sub(values[1], 1, 3), month, 1, true) then if max == nil or values[field_index] > max then max = values[field_index] end end end end return max end function p.getColumnIndex(name, file) for index,value in pairs(file["schema"]["fields"]) do if value["name"] == name then return index end end return nil end function p.main(frame) debug = "" local args = frame:getParent().args local template_args = {} local donnees = args["données"] local files = {} local months = {"jan", "fev", "mar", "avr", "mai", "jui", "jul", "aou", "sep", "oct", "nov", "dec"} -- Duplicate in args for key,value in pairs(args) do template_args[key] = args[key] end -- Open data files for file in string.gmatch(donnees, "[^%s]+") do files[file] = mw.ext.data.get(file) end -- Temperature extreme high for num,month in pairs(months) do if template_args["tmax-record-" .. month] == nil or template_args["tmax-record-" .. month] == "" then template_args["tmax-record-" .. month] = p.getMonthHighestTemp(num, files) template_args["tmax-record-date-" .. month] = nil elseif template_args["tmax-record-" .. month] == "-" then template_args["tmax-record-" .. month] = nil end end -- Temperature extreme low for num,month in pairs(months) do if template_args["tmin-record-" .. month] == nil or template_args["tmin-record-" .. month] == "" then template_args["tmin-record-" .. month] = p.getMonthLowestTemp(num, files) template_args["tmin-record-date-" .. month] = nil elseif template_args["tmin-record-" .. month] == "-" then template_args["tmin-record-" .. month] = nil end end -- Rainfall max for num,month in pairs(months) do if template_args["pluie-record-" .. month] == nil or template_args["pluie-record-" .. month] == "" then template_args["pluie-record-" .. month] = p.getMonthHighestRainfall(num, files) template_args["pluie-record-date-" .. month] = nil elseif template_args["pluie-record-" .. month] == "-" then template_args["pluie-record-" .. month] = nil end end -- Snowfall max for num,month in pairs(months) do if template_args["neige-record-" .. month] == nil or template_args["neige-record-" .. month] == "" then template_args["neige-record-" .. month] = p.getMonthHighestSnowfall(num, files) template_args["neige-record-date-" .. month] = nil elseif template_args["neige-record-" .. month] == "-" then template_args["neige-record-" .. month] = nil end end -- Force debug, if any if debug ~= "" then return debug else return frame:expandTemplate{title = 'Weather box', args = template_args} 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/Anon423/ClimateCommons/doc
(
edit
)