Module:Weather box/sandbox: Difference between revisions

Content deleted Content added
Try 0.2.
Tag: Reverted
Restore John's test version.
Line 20:
end
 
local function makeLabel(args, options, is_first, base, what)
local first
if isAny(args, ' ' .. what .. ' cm') then
Line 39:
end
if is_first then
if stripToNil(args['single line'])options.wantSingleLine then
first = first .. ' (' .. second .. ')'
end
Line 65:
end
 
local function getDefinitionswantSingle(frame, argsparm)
-- Originally needed "|single line=yes" or "|single line=<any non-blank>" for
-- single line output (default was separate lines for metric/imperial units).
-- That was changed in June 2020 so single line is the default and
-- now need "|single line=no" or "|single line=n" for separate lines.
parm = (parm or ''):lower()
return not (parm == 'no' or parm == 'n')
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 ⟶ 84:
local function _ifany(suffix)
return isAny(args, suffix)
end
local function _ifSingle(a, b)
return options.wantSingleLine and a or b or ''
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
local navbar = require('Module:Navbar')._navbar
navbarText = navbar({'Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'), args.name, collapsible=1}),
end
end
return {
Line 85 ⟶ 104:
_ifset('margin', 'auto') .. ';"' ..
_if('open',
'\n|+Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'),
-- Following intentionally shows "{{{___location}}}" if parameter is blank to alert editor.
'\n|+Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'),
'\n|-' ..
'\n!colspan="14" | ' .. _if('name', navbarText, 'Climate data for ' .. ___location)
_if('name',
navbar({'Climate data for ' .. _if('___location', args.___location, '{{{___location}}}'), args.name, collapsible=1}),
'Climate data for ' .. _if('___location', args.___location, '{{{___location}}}')
)
) ..
[=[
Line 114 ⟶ 128:
 
{---------- FIRST LINE MAXIMUM HUMIDEX ----------
WANTROW = _ifany(' maximum humidex') and (_ifset('metric first') or _ifset('single line')options.wantSingleLine),
mode = 'basic',
group_name = 'maximum humidex',
Line 128 ⟶ 142:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Record high °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'max',
},
Line 137 ⟶ 151:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Mean maximum °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'max',
},
Line 146 ⟶ 160:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Average high °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
Line 155 ⟶ 169:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Daily mean °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
Line 164 ⟶ 178:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Average low °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
Line 173 ⟶ 187:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Mean minimum °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'min',
},
Line 182 ⟶ 196:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Record low °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'min',
},
{---------- FIRST LINE MINIMUM WIND CHILL ----------
WANTROW = _ifany(' chill') and (_ifset('metric first') or _ifset('single line')options.wantSingleLine),
mode = 'basic',
group_name = 'chill',
Line 202 ⟶ 216:
scale_factor = '1',
prefer_cm = precision(_ifset('Jan precipitation inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average [[precipitation]]', 'precipitation'),
annual_mode = 'sum',
},
Line 213 ⟶ 227:
scale_factor = '1',
prefer_cm = precision(_ifset('Jan rain inch', '0')) < 1,
label = makeLabel(args, options, true, 'Average rainfall', 'rain'),
annual_mode = 'sum',
},
Line 224 ⟶ 238:
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, true, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- FIRST LINE MAX 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 = _ifset('snow colour', 'p'),
scale_factor = '0.2',
label = makeLabel(args, true, 'Extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- SECOND LINE MAXIMUM HUMIDEX ----------
WANTROW = not _ifset('single line')options.wantSingleLine and _ifany(' maximum humidex'),
mode = 'basic',
group_name = 'maximum humidex',
Line 248 ⟶ 252:
},
{---------- SECOND LINE RECORD HIGH TEMPERATURES ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' record high C') or _ifany(' record high F')),
mode = 'temperature',
group_name = 'record high',
Line 258 ⟶ 262:
},
{---------- SECOND LINE AVERAGE HIGH TEMPERATURES ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' high C') or _ifany(' high F')),
mode = 'temperature',
group_name = 'high',
Line 268 ⟶ 272:
},
{---------- SECOND LINE DAILY MEAN TEMPERATURES ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' mean C') or _ifany(' mean F')),
mode = 'temperature',
group_name = 'mean',
Line 279 ⟶ 283:
},
{---------- SECOND LINE AVERAGE LOW TEMPERATURES ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' low C') or _ifany(' low F')),
mode = 'temperature',
group_name = 'low',
Line 290 ⟶ 294:
},
{---------- SECOND LINE RECORD LOW TEMPERATURES ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' record low C') or _ifany(' record low F')),
mode = 'temperature',
group_name = 'record low',
Line 301 ⟶ 305:
},
{---------- SECOND LINE MINIMUM WIND CHILL ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' chill') and _if('metric first')),
mode = 'basic',
group_name = 'chill',
Line 310 ⟶ 314:
},
{---------- SECOND LINE TOTAL PRECIPITATION ----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' precipitation cm') or _ifany(' precipitation mm') or _ifany(' precipitation inch')),
mode = 'precipitation',
group_name = 'precipitation',
Line 318 ⟶ 322:
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 _ifset('single line')options.wantSingleLine and (_ifany(' rain cm') or _ifany(' rain mm') or _ifany(' rain inch')),
mode = 'precipitation',
group_name = 'rain',
Line 330 ⟶ 334:
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 _ifset('single line')options.wantSingleLine and (_ifany(' snow cm') or _ifany(' snow mm') or _ifany(' snow inch')),
mode = 'precipitation',
group_name = 'snow',
Line 342 ⟶ 346:
date_mode = true,
scale_factor = '1',
label = makeLabel(args, options, false, 'Average snowfall', 'snow'),
annual_mode = 'sum',
},
{---------- SECOND LINE MAX SNOW DEPTH ----------
WANTROW = not _ifset('single line') 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 = _ifset('snow colour', 'p'),
scale_factor = '0.2',
label = makeLabel(args, false, 'Extreme snow depth', 'snow depth'),
annual_mode = 'max',
},
{---------- PRECIPITATION DAYS ----------
Line 414 ⟶ 407:
color_scheme = _ifset('temperature colour', 't'),
scale_factor = '1',
label = 'Average [[dew point]] °' .. _if('metric first', 'C', 'F') .. _if_ifSingle('single line', ' (°' .. _if('metric first', 'F', 'C') .. ')'),
annual_mode = 'avg',
},
{---------- SECOND LINE AVERAGE DEW POINT----------
WANTROW = not _ifset('single line')options.wantSingleLine and (_ifany(' dew point C') or _ifany(' dew point F')),
mode = 'temperature',
group_name = 'dew point',
Line 479 ⟶ 472:
makeSources(frame, args),
}
end
 
local function makeFrame(self_args, parent_args)
-- Kludge to pass arguments for a single row to buildRow.
-- Later: Refactor buildRow so this is not needed.
return {
args = self_args,
getParent = function (self) return makeFrame(parent_args, nil) end,
}
end
 
local function main(frame)
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
local buildRow = require('Module:Weather box/row' .. sandbox).buildRow_buildRow
local args = frame:getParent().args
local options = {
wantSingleLine = wantSingle(args['single line']),
sandbox = sandbox,
)}
local results = {}
for i, defdefinition in ipairs(getDefinitions(frame, args, options)) do
local row
if type(defdefinition) == 'string' then
row = defdefinition
elseif defdefinition.WANTROW then
row = buildRow(makeFrame(defdefinition, args), options)
else
row = ''