local p =
local degree = "°"local m_weather = require("Module:Weather/sandbox")
local format
local message = ""
local function add_message(new_message) if message
local function get_format (frame) local input_format_parameter = frame.args.input_format local input_unit, output_unit, length, output_format, display_unit, array_names if input_format_parameter
"C" then output_unit = "F" elseif input_unit
nil then error ("get_format has not found a length value in the length or input_format parameter") end return end
local function precision(value, decimals) local string = string.format('%.' .. decimals .. 'f', value) return stringend
local function check_for_string(string) return string ~= "" and string ~= nilend
local function check_for_number(value) return type(tonumber(value))
local function convert(value, decimals, unit) -- Unit is the unit being converted from. It defaults to input_unit. if not unit then unit = format.input_unit end if check_for_number(value) then local value = tonumber(value) if unit
"F" then return precision((value - 32) * 5/9, decimals) else error("Input unit not recognized", 2) end else return "" -- Setting result to empty string if value is not a number avoids concatenation errors. endend
local function make_array(parameter, array, frame) format = get_format(frame) local array = local n = 1 for number in parameter:gmatch('%-?%d+%.?%d?') do local number = number table.insert(array, n, number) if array[n]
local function make_arrays(frame) local a, b, c get_format(frame) local parameter_a = frame.args.a local parameter_b = frame.args.b local parameter_c = frame.args.c if parameter_a then a = make_array(parameter_a, a, frame) else error("Please provide a set of numbers in parameter
a") end if parameter_b then b = make_array(parameter_b, b, frame) else add_message("There is no content in parameter b.") end if parameter_c then c = make_array(parameter_c, c, frame) else add_message("There is no content in parameter c.") end return a, b, cendlocal output_formats =
local function add_unit_names(value, unit) if not unit then unit = format.input_unit end if format.output_format.unit_names
"" then return value -- Don't add a unit name to an empty string else return value .. degree .. unit end else return value endend
local function interpret_format(parameter, realization1, realization2) if realization1 then if realization2 then if parameter
"yes" then parameter = realization1 else parameter = "" end end else parameter = "" add_message("
interpret_format needs at least one realization") end return parameterendlocal function make_cell(row, output_format, a, b, c) local cell, CSS, cell_content = "", "", "" local title_content, sort_attribute, sortkey, attribute_separator local style_attribute, title_attribute, values_separator =,, local values, converted_units local line_break, brackets = interpret_format(output_format.line_break, "
"), interpret_format(output_format.brackets, "(", ")") if a then if b then values, values_separator =, else values, values_separator =, -- Empty values must be strings, or concatenation will not work. end end if format.input_unit
"C" or output_format.first
"" then style_attribute = else style_attribute = end
--" end local td = row:tag("td") if check_for_string(cell_content) then td:wikitext (cell_content) else add_message(" cell_content is not defined.") end if check_for_string(CSS) then td:cssText (CSS) end if check_for_string(title_content) then td:attr ("title", title_content) end if check_for_string(sortkey) then td:attr ("data-sort-value", sortkey) end -- cell = "\n| " .. style_attribute[1] .. .. style_attribute[2] .. title_attribute[1] .. title_content .. title_attribute[2] .. sort_attribute .. attribute_separator .. cell_content return tdendfunction p.print_arrays(frame) local a, b, c = make_arrays(frame) local classes = "wikitable" if format.sortable
return p