Content deleted Content added
switch to collapsible |
sync + try "Percentage possible sunshine" per talk proposal |
||
(19 intermediate revisions by 7 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
return result
return 0
end
local function stripToNil(text)
Line 24 ⟶ 34:
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 66 ⟶ 74:
local function wantSingle(parm)
--------------------------------------------------------------------------------
-- Result before July 2022 for single_line setting:
-- blank/omitted : separate table rows for metric and imperial (two rows)
-- That was changed in June 2020 so single line is the default and▼
-- N : bug: only one row with either metric or imperial (not both)
-- now need "|single line=no" or "|single line=n" for separate lines.▼
-- but heading like "cm (inches)"
-- Y/junk : single row with both metric/imperial in same cell
--------------------------------------------------------------------------------
▲ --
-- 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
Line 87 ⟶ 102:
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
Line 100 ⟶ 124:
----------- 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 ' .. ___location,
Line 131 ⟶ 155:
mode = 'basic',
group_name = 'maximum humidex',
color_scheme =
scale_factor = '1',
label = 'Record high [[humidex]]',
Line 140 ⟶ 164:
mode = 'temperature',
group_name = 'record high',
color_scheme =
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
Line 149 ⟶ 173:
mode = 'temperature',
group_name = 'avg record high',
color_scheme =
scale_factor = '1',
label = 'Mean maximum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
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 167 ⟶ 191:
mode = 'temperature',
group_name = 'mean',
color_scheme =
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
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 185 ⟶ 209:
mode = 'temperature',
group_name = 'avg record low',
color_scheme =
scale_factor = '1',
label = 'Mean minimum °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
Line 194 ⟶ 218:
mode = 'temperature',
group_name = 'record low',
color_scheme =
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
Line 203 ⟶ 227:
mode = 'basic',
group_name = 'chill',
color_scheme =
scale_factor = '1',
label = 'Record low [[wind chill]]',
Line 212 ⟶ 236:
mode = 'precipitation',
group_name = 'precipitation',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 223 ⟶ 247:
mode = 'precipitation',
group_name = 'rain',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 235 ⟶ 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 AVERAGE EXTREME SNOW DEPTH ----------
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 = _colorscheme('snow', 'p'),
scale_factor = '0.2',
label = makeLabel(args, options, true, 'Average extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- SECOND LINE MAXIMUM HUMIDEX ----------
Line 245 ⟶ 279:
mode = 'basic',
group_name = 'maximum humidex',
color_scheme =
scale_factor = '1',
label = '[[Humidex]]',
Line 256 ⟶ 290:
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 options.wantSingleLine and (_ifany(' high C') or _ifany(' high F')),
mode = 'temperature',
group_name = 'high',
second_line = true,
color_scheme =
scale_factor = '1',
label = '
annual_mode = 'avg',
},
Line 276 ⟶ 310:
group_name = 'mean',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'F', 'C'),
Line 282 ⟶ 316:
annual_mode = 'avg',
},
{---------- SECOND LINE
WANTROW = not options.wantSingleLine and (_ifany(' low C') or _ifany(' low F')),
mode = 'temperature',
group_name = 'low',
second_line = true,
color_scheme =
scale_factor = '1',
label = '
show = _if('metric first', '2', '1'),
annual_mode = 'avg',
Line 298 ⟶ 332:
group_name = 'record low',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'F', 'C'),
Line 308 ⟶ 342:
mode = 'basic',
group_name = 'chill',
color_scheme =
scale_factor = '1',
label = '[[Wind chill]]',
Line 318 ⟶ 352:
group_name = 'precipitation',
second_line = true,
color_scheme =
date_mode = true,
scale_factor = '1',
Line 330 ⟶ 364:
group_name = 'rain',
second_line = true,
color_scheme =
date_mode = true,
scale_factor = '1',
Line 343 ⟶ 377:
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 AVERAGE EXTREME SNOW DEPTH ----------
WANTROW = not options.wantSingleLine and (_ifany(' snow depth cm') or _ifany(' snow depth mm') or _ifany(' snow depth inch')),
mode = 'precipitation',
group_name = 'snow depth',
second_line = true,
prefer_cm = true,
color_scheme = _colorscheme('snow', 'p'),
scale_factor = '0.2',
label = makeLabel(args, options, false, 'Average extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- PRECIPITATION DAYS ----------
Line 353 ⟶ 398:
mode = 'basic',
group_name = 'precipitation days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 363 ⟶ 408:
mode = 'basic',
group_name = 'rain days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 373 ⟶ 418:
mode = 'basic',
group_name = 'snow days',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 383 ⟶ 428:
mode = 'basic',
group_name = 'humidity',
color_scheme =
scale_factor = '1',
label = 'Average [[relative humidity]] (%)' ..
Line 394 ⟶ 439:
mode = 'basic',
group_name = 'afthumidity',
color_scheme =
scale_factor = '1',
label = 'Average afternoon [[relative humidity]] (%)' ..
Line 405 ⟶ 450:
mode = 'temperature',
group_name = 'dew point',
color_scheme =
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'C', 'F') .. _ifSingle(' (°' .. _if('metric first', 'F', 'C') .. ')'),
Line 415 ⟶ 460:
group_name = 'dew point',
second_line = true,
color_scheme =
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'F', 'C'),
Line 425 ⟶ 470:
mode = 'basic',
group_name = 'sun',
color_scheme =
date_mode = true,
scale_factor = '1',
Line 435 ⟶ 480:
mode = 'basic',
group_name = 'd sun',
color_scheme =
include_space = false,
scale_factor = '30.44',
Line 445 ⟶ 490:
mode = 'basic',
group_name = ' light',
color_scheme =
include_space = false,
scale_factor = '30.44',
Line 455 ⟶ 500:
mode = 'basic',
group_name = 'percentsun',
color_scheme =
scale_factor = '7.2',
label = '
annual_mode = 'avg',
},
Line 464 ⟶ 509:
mode = 'basic',
group_name = 'uv',
color_scheme =
scale_factor = '1',
label = 'Average [[ultraviolet index]]',
|