Module:UŊMAO: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local def, _a do local u = require("Module:Utils") def, _a = u.def, u._a end | local def, _a do local u = require("Module:Utils") def, _a = u.def, u._a end | ||
local c = require"Module:Data/UŊMAO/Currencies" | |||
local r = require"Module:Data/UŊMAO/Resources" | |||
local _m = {} | |||
local | local function formatval(v) | ||
if type(v) ~= "number" then return v end | |||
return string.format("%.6f", v) | |||
end | |||
_m.resource_table = function(frame) | _m.resource_table = function(frame) | ||
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Resource</th><th>Value (in [[slablet]]s)</th><th>Traded at the [[Slab Exchange]]</th></tr>]=] | local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Resource</th><th>Value (in [[slablet]]s)</th><th>Traded at the [[Slab Exchange]]</th></tr>]=] | ||
for _, v in ipairs(r) do | |||
for _, v in ipairs( | out = out .. "<tr><td>" .. v.code .. "</td><td>" .. v.name .. "</td><td>" .. formatval(v.value) .. "</td><td>" .. (v.sxg and "yes" or "no") .. "</td></tr>" | ||
out = out .. "<tr><td>" .. v.code .. "</td><td>" .. v.name .. "</td><td>" .. v.value .. "</td><td>" .. (v.sxg and "yes" or "no") .. "</td></tr>" | |||
end | end | ||
out = out .. "</table>" | out = out .. "</table>" | ||
| Line 13: | Line 19: | ||
end | end | ||
_m.current_currencies = function(frame) | _m.current_currencies = function(frame) | ||
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s)</th></tr>]=] | local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s)</th></tr>]=] | ||
for _, v in ipairs(c) do | for _, v in ipairs(c) do | ||
if not v.discontinued then | if not v.discontinued then | ||
| Line 40: | Line 41: | ||
_m.withdrawn_currencies = function(frame) | _m.withdrawn_currencies = function(frame) | ||
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s) at the time of withdrawal</th><th>Reason for withdrawal</th></tr>]=] | local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s) at the time of withdrawal</th><th>Reason for withdrawal</th></tr>]=] | ||
for _, v in ipairs(c) do | for _, v in ipairs(c) do | ||
if v.discontinued then | if v.discontinued then | ||
| Line 64: | Line 63: | ||
out = [=[<table class="wikitable"><tr><td>TO →</br>↓ FROM</td>]=] | out = [=[<table class="wikitable"><tr><td>TO →</br>↓ FROM</td>]=] | ||
for _, v in ipairs(c) do if not v.discontinued then | for _, v in ipairs(c) do if not v.discontinued then | ||
out = out .. "<th>" .. v.code .. "</th>" | out = out .. "<th><abbr title=\"" .. v.name .. " (" .. v.place .. ")\">" .. v.code .. "</abbr></th>" | ||
end end | end end | ||
out = out .. "</tr>" | out = out .. "</tr>" | ||
for _, vf in ipairs(c) do if not vf.discontinued then | for _, vf in ipairs(c) do if not vf.discontinued then | ||
out = out .. "<tr><th>" .. vf.code .. "</th>" | out = out .. "<tr><th><abbr title=\"" .. vf.name .. " (" .. vf.place .. ")\">" .. vf.code .. "</abbr></th>" | ||
for _, vt in ipairs(c) do if not vt.discontinued then | for _, vt in ipairs(c) do if not vt.discontinued then | ||
out = out .. "<td>" .. formatval(c._get_nval( | out = out .. "<td>" .. formatval(c._get_nval(vf.code)/c._get_nval(vt.code)) .. "</td>" | ||
end end | end end | ||
out = out .. "</tr>" | out = out .. "</tr>" | ||
Latest revision as of 09:41, 21 September 2025
Functions for the UŊMAO page
local def, _a do local u = require("Module:Utils") def, _a = u.def, u._a end
local c = require"Module:Data/UŊMAO/Currencies"
local r = require"Module:Data/UŊMAO/Resources"
local _m = {}
local function formatval(v)
if type(v) ~= "number" then return v end
return string.format("%.6f", v)
end
_m.resource_table = function(frame)
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Resource</th><th>Value (in [[slablet]]s)</th><th>Traded at the [[Slab Exchange]]</th></tr>]=]
for _, v in ipairs(r) do
out = out .. "<tr><td>" .. v.code .. "</td><td>" .. v.name .. "</td><td>" .. formatval(v.value) .. "</td><td>" .. (v.sxg and "yes" or "no") .. "</td></tr>"
end
out = out .. "</table>"
return out
end
_m.current_currencies = function(frame)
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s)</th></tr>]=]
for _, v in ipairs(c) do
if not v.discontinued then
local backing = r._get(v.backed)
local backed_formatted = (backing == nil) and v.backed or ([[<abbr title="]] .. backing.name .. [[">]] .. v.backed .. [[</abbr>]])
out = out ..
"<tr><td>" .. v.code ..
"</td><td>[[" .. v.place ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>" .. backed_formatted ..
"</td><td>" .. formatval(v.brval) ..
"</td><td>" .. formatval(c._get_nval(v.code)) ..
"</td></tr>"
end
end
return out .. "</table>"
end
_m.withdrawn_currencies = function(frame)
local out = [=[<table class="wikitable sortable"><tr><th>Code</th><th>Place</th><th>Name</th><th>Backing</th><th>Value (in the <abbr title="Backing Resource">B.R.</abbr>)</th><th>Value (in [[slablet]]s) at the time of withdrawal</th><th>Reason for withdrawal</th></tr>]=]
for _, v in ipairs(c) do
if v.discontinued then
local backing = r._get(v.backed)
local backed_formatted = (backing == nil) and v.backed or ([[<abbr title="]] .. backing.name .. [[">]] .. v.backed .. [[</abbr>]])
out = out ..
"<tr><td>" .. v.code ..
"</td><td>[[" .. v.place ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>" .. backed_formatted ..
"</td><td>" .. formatval(v.brval) ..
"</td><td>" .. formatval(v.nval) ..
"</td><td>" .. tostring(v.discontinued) ..
"</td></tr>"
end
end
return out .. "</table>"
end
_m.curency_map = function(frame)
local c = require"Module:Data/UŊMAO/Currencies"
out = [=[<table class="wikitable"><tr><td>TO →</br>↓ FROM</td>]=]
for _, v in ipairs(c) do if not v.discontinued then
out = out .. "<th><abbr title=\"" .. v.name .. " (" .. v.place .. ")\">" .. v.code .. "</abbr></th>"
end end
out = out .. "</tr>"
for _, vf in ipairs(c) do if not vf.discontinued then
out = out .. "<tr><th><abbr title=\"" .. vf.name .. " (" .. vf.place .. ")\">" .. vf.code .. "</abbr></th>"
for _, vt in ipairs(c) do if not vt.discontinued then
out = out .. "<td>" .. formatval(c._get_nval(vf.code)/c._get_nval(vt.code)) .. "</td>"
end end
out = out .. "</tr>"
end end
return out
end
return _m