Content deleted Content added
copy from Module:Weather box/row; will later provide alternative for: "require('Module:Weather box/colors/sandbox')" |
style cleanups; no substantive change |
||
Line 1:
local
local math_mod = require('Module:Math')
local wbc = require('Module:Weather box/colors')
Line 105:
Value.__index = Value
local function checkFlag(
if flag == nil then
return default
elseif type(
return flag
elseif type(
flag = flag:lower()
if flag == '0' or flag == 'false' or
Line 120:
end
else
return error(
end
end
local function makeLine(
local result = {'|- style="text-align: center;"\n! scope="row" style="height: 16px;" | ', label, "\n"}
for i = 1, 13 do
local color_str = color_values[i]
if i == 13 then
table.insert(
else
table.insert(
end
local display = first_values[i]:getDisplay()
if display then
table.insert(
if second_values ~= nil then
display = second_values[i]:getDisplay(true)
if display then
table.insert(
end
end
else
table.insert(
end
▲ table.insert( result, "\n" )
end
▲ return table.concat( result )
end
local function getInputs(
local month_names = { 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'year' }
Line 160 ⟶ 156:
local values = {}
if suffix == nil then
for i, mon in ipairs(
if include_space then
str = frame.args[ mon .. ' ' .. group_name ] or ''
Line 169 ⟶ 165:
end
else
for i, mon in ipairs(
local value, updated
for var, suf in ipairs(
if include_space then
str = frame.args[ mon .. ' ' .. group_name .. ' ' .. suf ]
Line 194 ⟶ 190:
end
local function getAnnualValue(
if mode == 'avg' or mode == 'sum' then
local total = 0
Line 209 ⟶ 205:
end
end
p2 = values[i]:getPrecision()
if p2 > p1 then
p1 = p2
end
total = total + values[i].number
end
local value = Value.new(total)
if mode == 'avg' then
value:setNumberRounded(
end
value.variant = variant
Line 244 ⟶ 238:
return target or Value.new()
else
error(
end
end
local function reconcileTemperature(
for i = 1, 13 do
local p
if C_values[i].string == '' then
Line 265 ⟶ 259:
end
local function reconcilePrecipitation(
local v_class = 0
for i = 1, 13 do
if M_values[i].variant == 1 then
v_class = 1
Line 281 ⟶ 275:
end
end
for i = 1, 13 do
local units
if M_values[i].string == '' then
Line 290 ⟶ 284:
units = 'in2mm'
end
M_values[i]:setConvert(
M_values[i].variant = v_class
end
Line 300 ⟶ 294:
units = 'mm2in'
end
I_values[i]:setConvert(
end
end
Line 306 ⟶ 300:
end
function
local mode = (frame.args.mode or 'basic'):lower()
local group_name = frame.args.group_name
Line 312 ⟶ 306:
local color_values
local color_scheme = frame.args.color_scheme or 't'
local scale_factor = math_mod._cleanNumber( frame.args.scale_factor ) or 1
local date_mode = checkFlag( frame.args.date_mode, false )
local label = frame.args.label or ''
Line 327 ⟶ 321:
traceText = trace
end
if imperial_first == nil then
imperial_first = metric_first == nil and true or not metric_first
end
if mode == 'basic' then
first_values = getInputs( pframe, group_name, nil, include_space )
Line 344 ⟶ 336:
reconcilePrecipitation( first_values, second_values, prefer_cm )
else
error(
end
local good = false
for i = 1, 13 do
if first_values[i].string ~= '' then
good = true
Line 357 ⟶ 348:
return ''
end
if first_values[13].string == '' then
first_values[13] = getAnnualValue(
end
if second_values ~= nil then
if second_values[13].string == '' then
second_values[13] = getAnnualValue(
end
end
▲ color_scheme = wbc.interpret_color_code( color_scheme )
color_values = {}
local month_adj = { 31/30, 28.25/30, 31/30, 1, 31/30, 1,
31/30, 31/30, 1, 31/30, 1, 31/30, 365.25/30 }
for i = 1, 13 do
if first_values[i]:isValid() then
local adj = scale_factor
Line 383 ⟶ 371:
end
end
table.insert(
else
table.insert(
end
end
if imperial_first and second_values ~= nil then
first_values, second_values = second_values, first_values
end
if not single_line then
if second_line and second_values ~= nil then
Line 399 ⟶ 385:
second_values = nil
end
▲ return makeLine( label, first_values, second_values, color_values )
end
return
|