Content deleted Content added
Test. Tag: Reverted |
sync + try "Percentage possible sunshine" per talk proposal |
||
(23 intermediate revisions by 9 users not shown) | |||
Line 1:
-- Implement [[Template:Weather box]].
local
local function precision(text)
-- Input like 'Jan precipitation inch = trace' calls this with text = 'trace'
-- which would cause _precision to throw an error since it is not numeric.
-- Workaround: Return 0 as the precision if an error occurs.
local success, result = pcall(_precision, text)
if success then
end▼
return 0
local function stripToNil(text)
Line 20 ⟶ 30:
end
local function makeLabel(args, options, is_first, base, what)
local first
if isAny(args, ' ' .. what .. ' cm') then
first = 'cm'
else
first = (what:sub(1, 4) == 'snow' or
▲ if isAny(args, ' ' .. what .. ' mm') then
▲ first = 'mm'
▲ precision(args['Jan ' .. what .. ' inch'] or '0') < 1)
▲ and 'cm'
▲ end
end
local second = 'inches'
Line 39 ⟶ 47:
end
if is_first then
if
first = first .. ' (' .. second .. ')'
end
Line 65 ⟶ 73:
end
local function
--------------------------------------------------------------------------------
-- Result before July 2022 for single_line setting:
-- blank/omitted : separate table rows for metric and imperial (two rows)
-- N : bug: only one row with either metric or imperial (not both)
-- but heading like "cm (inches)"
-- Y/junk : single row with both metric/imperial in same cell
--------------------------------------------------------------------------------
-- Intend changing in July 2022 so single_line=Y is the default and
-- need single_line=N for separate lines.
-- However, this release (1 July 2022) keeps blank/omitted as meaning "no"
-- so the other large changes can be tested before switching the default.
parm = (parm or ''):lower()
return not (parm == 'no' or parm == 'n' or parm == '')
end
local function getDefinitions(frame, args, options)
-- Return a list of tables or strings that define each row.
local navbar = require('Module:Navbar')._navbar▼
local function _if(parm, a, b)
return stripToNil(args[parm]) and a or b or ''
Line 76 ⟶ 99:
local function _ifany(suffix)
return isAny(args, suffix)
end
local function _ifSingle(a, b)
return options.wantSingleLine and a or b or ''
end
local function _colorscheme(what, default)
return stripToNil(args[what .. ' colour']) or stripToNil(args[what .. ' color']) or default
end
local function _margin()
if stripToNil(args.margin) then
return 'margin:' .. args.margin .. ';'
end
return ''
end
local ___location = _if('___location', args.___location, '{{{___location}}}') -- show "{{{___location}}}" to alert editor if parameter is blank
local navbarText
if not stripToNil(args.open) then
if stripToNil(args.name) then
navbarText = navbar({'Climate data for ' ..
end
end
return {
----------- HEADER ----------
'{| class="wikitable ' .. _if('open', '', 'mw-collapsible' .. _if('collapsed', ' mw-collapsed')) ..
'" style="width:' .. _ifset('width', '
'; text-align:center; line-height:
_if('open',
▲ '\n|+Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'),
'\n|-' ..
'\n!colspan="14" | ' .. _if('name', navbarText, 'Climate data for ' .. ___location)
▲ navbar({'Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'), args.name, collapsible=1}),
)▼
) ..
[=[
Line 114 ⟶ 152:
{---------- FIRST LINE MAXIMUM HUMIDEX ----------
WANTROW = _ifany(' maximum humidex') and (_ifset('metric first') or
mode = 'basic',
group_name = 'maximum humidex',
color_scheme =
scale_factor = '1',
label = 'Record high [[humidex]]',
Line 126 ⟶ 164:
mode = 'temperature',
group_name = 'record high',
color_scheme =
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'max',
},
Line 135 ⟶ 173:
mode = 'temperature',
group_name = 'avg record high',
color_scheme =
scale_factor = '1',
label = 'Mean maximum °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'max',
},
{---------- FIRST LINE
WANTROW = _ifany(' high C') or _ifany(' high F'),
mode = 'temperature',
group_name = 'high',
color_scheme =
scale_factor = '1',
label = '
annual_mode = 'avg',
},
Line 153 ⟶ 191:
mode = 'temperature',
group_name = 'mean',
color_scheme =
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'avg',
},
{---------- FIRST LINE
WANTROW = _ifany(' low C') or _ifany(' low F'),
mode = 'temperature',
group_name = 'low',
color_scheme =
scale_factor = '1',
label = '
annual_mode = 'avg',
},
Line 171 ⟶ 209:
mode = 'temperature',
group_name = 'avg record low',
color_scheme =
scale_factor = '1',
label = 'Mean minimum °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'min',
},
Line 180 ⟶ 218:
mode = 'temperature',
group_name = 'record low',
color_scheme =
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'min',
},
{---------- FIRST LINE MINIMUM WIND CHILL ----------
WANTROW = _ifany(' chill') and (_ifset('metric first') or
mode = 'basic',
group_name = 'chill',
color_scheme =
scale_factor = '1',
label = 'Record low [[wind chill]]',
Line 198 ⟶ 236:
mode = 'precipitation',
group_name = 'precipitation',
color_scheme =
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average [[precipitation]]', 'precipitation'),
annual_mode = 'sum',
},
Line 209 ⟶ 247:
mode = 'precipitation',
group_name = 'rain',
color_scheme =
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average rainfall', 'rain'),
annual_mode = 'sum',
},
Line 221 ⟶ 259:
group_name = 'snow',
prefer_cm = true,
color_scheme =
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, true, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- FIRST LINE
WANTROW = _ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch'),
mode = 'precipitation',
group_name = 'snow depth',
prefer_cm = true,
color_scheme =
scale_factor = '0.
label = makeLabel(args, options, true, '
annual_mode = 'max',
},
{---------- SECOND LINE MAXIMUM HUMIDEX ----------
WANTROW = not
mode = 'basic',
group_name = 'maximum humidex',
color_scheme =
scale_factor = '1',
label = '[[Humidex]]',
Line 248 ⟶ 286:
},
{---------- SECOND LINE RECORD HIGH TEMPERATURES ----------
WANTROW = not
mode = 'temperature',
group_name = 'record high',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'F', 'C'),
annual_mode = 'max',
},
{---------- SECOND LINE
WANTROW = not
mode = 'temperature',
group_name = 'high',
second_line = true,
color_scheme =
scale_factor = '1',
label = '
annual_mode = 'avg',
},
{---------- SECOND LINE DAILY MEAN TEMPERATURES ----------
WANTROW = not
mode = 'temperature',
group_name = 'mean',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'F', 'C'),
Line 278 ⟶ 316:
annual_mode = 'avg',
},
{---------- SECOND LINE
WANTROW = not
mode = 'temperature',
group_name = 'low',
second_line = true,
color_scheme =
scale_factor = '1',
label = '
show = _if('metric first', '2', '1'),
annual_mode = 'avg',
},
{---------- SECOND LINE RECORD LOW TEMPERATURES ----------
WANTROW = not
mode = 'temperature',
group_name = 'record low',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'F', 'C'),
Line 301 ⟶ 339:
},
{---------- SECOND LINE MINIMUM WIND CHILL ----------
WANTROW = not
mode = 'basic',
group_name = 'chill',
color_scheme =
scale_factor = '1',
label = '[[Wind chill]]',
Line 310 ⟶ 348:
},
{---------- SECOND LINE TOTAL PRECIPITATION ----------
WANTROW = not
mode = 'precipitation',
group_name = 'precipitation',
second_line = true,
color_scheme =
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
label = makeLabel(args, options, false, 'Average [[precipitation]]', 'precipitation'),
annual_mode = 'sum',
},
{---------- SECOND LINE RAINFALL ----------
WANTROW = not
mode = 'precipitation',
group_name = 'rain',
second_line = true,
color_scheme =
date_mode = true,
scale_factor = '1',
prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
label = makeLabel(args, options, false, 'Average rainfall', 'rain'),
annual_mode = 'sum',
},
{---------- SECOND LINE SNOWFALL ----------
WANTROW = not
mode = 'precipitation',
group_name = 'snow',
second_line = true,
prefer_cm = true,
color_scheme =
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, false, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- SECOND LINE
WANTROW = not
mode = 'precipitation',
group_name = 'snow depth',
second_line = true,
prefer_cm = true,
color_scheme =
scale_factor = '0.
label = makeLabel(args, options, false, '
annual_mode = 'max',
},
Line 360 ⟶ 398:
mode = 'basic',
group_name = 'precipitation days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 370 ⟶ 408:
mode = 'basic',
group_name = 'rain days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 380 ⟶ 418:
mode = 'basic',
group_name = 'snow days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 390 ⟶ 428:
mode = 'basic',
group_name = 'humidity',
color_scheme =
scale_factor = '1',
label = 'Average [[relative humidity]] (%)' ..
Line 401 ⟶ 439:
mode = 'basic',
group_name = 'afthumidity',
color_scheme =
scale_factor = '1',
label = 'Average afternoon [[relative humidity]] (%)' ..
Line 412 ⟶ 450:
mode = 'temperature',
group_name = 'dew point',
color_scheme =
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'C', 'F') ..
annual_mode = 'avg',
},
{---------- SECOND LINE AVERAGE DEW POINT----------
WANTROW = not
mode = 'temperature',
group_name = 'dew point',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'F', 'C'),
Line 432 ⟶ 470:
mode = 'basic',
group_name = 'sun',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 442 ⟶ 480:
mode = 'basic',
group_name = 'd sun',
color_scheme =
include_space = false,
scale_factor = '30.44',
Line 452 ⟶ 490:
mode = 'basic',
group_name = ' light',
color_scheme =
include_space = false,
scale_factor = '30.44',
Line 462 ⟶ 500:
mode = 'basic',
group_name = 'percentsun',
color_scheme =
scale_factor = '7.2',
label = '
annual_mode = 'avg',
},
Line 471 ⟶ 509:
mode = 'basic',
group_name = 'uv',
color_scheme =
scale_factor = '1',
label = 'Average [[ultraviolet index]]',
Line 479 ⟶ 517:
makeSources(frame, args),
}
▲end
▲ return {
end
local function main(frame)
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
local buildRow = require('Module:Weather box/row' .. sandbox).
local args = frame:getParent().args
local options = {
wantSingleLine = wantSingle(args['single line']),
sandbox = sandbox,
local results = {}
for i,
local row
if type(
row =
elseif
row = buildRow(
else
row = ''
|