Module:GeneralPortSectorSummary: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local ag = require("Module:AutoUpdateAgPrices") | ||
local manf = require("Module:AutoUpdateManfPrices") | |||
local serv = require("Module:AutoUpdateServPrices") | |||
local function round(num, places) | local function round(num, places) | ||
| Line 29: | Line 17: | ||
return string.format("%.1f%%", num) | return string.format("%.1f%%", num) | ||
else | else | ||
return "0.0%" | return "0.0%%" | ||
end | end | ||
end | end | ||
local function colorForPct(pct) | local function colorForPct(pct) | ||
if pct > | if pct > 0 then | ||
return "#d8f0d2", "#1f5f1f" | return "#d8f0d2", "#1f5f1f" | ||
elseif pct | elseif pct < 0 then | ||
return "#f8d7d7", "#8b1e1e" | return "#f8d7d7", "#8b1e1e" | ||
else | else | ||
return "#f3f3f3", "#555555" | return "#f3f3f3", "#555555" | ||
| Line 47: | Line 31: | ||
end | end | ||
function p.main(frame) | |||
local sectors = { | |||
ag.getAverageData(), | |||
manf.getAverageData(), | |||
serv.getAverageData() | |||
local | |||
} | } | ||
local out = {} | local out = {} | ||
table.insert(out, '{| class="wikitable" style="width:100%; text-align:center;"') | table.insert(out, '{| class="wikitable" style="width:100%; text-align:center;"') | ||
table.insert(out, '|-') | table.insert(out, '|-') | ||
table.insert(out, '! Sector !! Average Daily Change !! Summary | table.insert(out, '! Sector !! Average Daily Change !! Summary') | ||
for _, | for _, row in ipairs(sectors) do | ||
local | local bg, fg = colorForPct(row.pctChange) | ||
table.insert(out, '|-') | |||
table.insert(out, '| style="text-align:left;" | ' .. row.label) | |||
table.insert(out, string.format( | |||
'| style="background:%s; color:%s; font-weight:bold;" | %s', | |||
bg, fg, fmtPct(row.pctChange) | |||
)) | |||
table.insert(out, string.format( | |||
'| style="background:%s; color:%s;" | Average adjusted (%.4f) vs base (%.4f): %s %s', | |||
bg, fg, row.avgNew, row.avgBase, row.avgSym, row.avgLevel | |||
)) | |||
end | end | ||
table.insert(out, '|}') | table.insert(out, '|}') | ||
return table.concat(out, "\n") | return table.concat(out, "\n") | ||
end | end | ||
return p | return p | ||
Revision as of 17:34, 20 March 2026
Documentation for this module may be created at Module:GeneralPortSectorSummary/doc
local p = {}
local ag = require("Module:AutoUpdateAgPrices")
local manf = require("Module:AutoUpdateManfPrices")
local serv = require("Module:AutoUpdateServPrices")
local function round(num, places)
local mult = 10 ^ (places or 0)
return math.floor(num * mult + 0.5) / mult
end
local function fmtPct(num)
num = round(num, 1)
if num > 0 then
return string.format("+%.1f%%", num)
elseif num < 0 then
return string.format("%.1f%%", num)
else
return "0.0%%"
end
end
local function colorForPct(pct)
if pct > 0 then
return "#d8f0d2", "#1f5f1f"
elseif pct < 0 then
return "#f8d7d7", "#8b1e1e"
else
return "#f3f3f3", "#555555"
end
end
function p.main(frame)
local sectors = {
ag.getAverageData(),
manf.getAverageData(),
serv.getAverageData()
}
local out = {}
table.insert(out, '{| class="wikitable" style="width:100%; text-align:center;"')
table.insert(out, '|-')
table.insert(out, '! Sector !! Average Daily Change !! Summary')
for _, row in ipairs(sectors) do
local bg, fg = colorForPct(row.pctChange)
table.insert(out, '|-')
table.insert(out, '| style="text-align:left;" | ' .. row.label)
table.insert(out, string.format(
'| style="background:%s; color:%s; font-weight:bold;" | %s',
bg, fg, fmtPct(row.pctChange)
))
table.insert(out, string.format(
'| style="background:%s; color:%s;" | Average adjusted (%.4f) vs base (%.4f): %s %s',
bg, fg, row.avgNew, row.avgBase, row.avgSym, row.avgLevel
))
end
table.insert(out, '|}')
return table.concat(out, "\n")
end
return p