Module:UŊMAO: Difference between revisions

From Nguhcraft Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(17 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, find do local u = require("Module:Utils") def, _a, find = u.def, u._a, u.find end
local data = mw.loadJsonData "Data:UŊMAO"
local places = require "Module:Places"
local c = data.currencies
local r = data.resources
local _m = {}
 
 
local function formatval(v)
if type(v) ~= "number" then return v end
return string.format("%.6f", v)
end
 
local function get_nval(code)
local _, c_data = find(c, "code", code)
if not c_data then return nil end
if c_data.n_val then return c_data.n_val end
local _, r_data = find(r, "code", c_data.backing)
if not r_data then return nil end
return r_data.n_val * c_data.b_val
end


local _m = {}
local function place_of(code)
local _, v = find(c, "code", code)
if not v.place_override then return (places.get(v.code:sub(1, 2)) or {common_name = "???"}).common_name
elseif v.code:sub(1,1) == "X" then return v.place_override
else return places.get(v.place_override).common_name
end
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>]=]
local resources = require("Module:Data/UŊMAO/Resources")
for _, v in ipairs(r) do
for _, v in ipairs(resources) do
out = out .. "<tr><td>"
out = out .. "<tr><td>" .. v.code .. "</td><td>" .. v.name .. "</td><td>" .. v.value .. "</td><td>" .. (v.sxg and "yes" or "no") .. "</td></tr>"
out = out .. v.code  
out = out .. "</td><td>"
out = out .. v.name
out = out .. "</td><td>"
out = out .. formatval(v.n_val)
out = out  .. "</td><td>"
out = out  .. (v.sxg and "yes" or "no")
out = out  .. "</td></tr>"
end
end
out = out .. "</table>"
out = out .. "</table>"
Line 13: Line 46:
end
end


local function formatval(v)
if type(v) ~= "number" then return v end
return string.format("%.6f", v)
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 B.R.)</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>]=]
local c = require"Module:Data/UŊMAO/Currencies"
for _, v in ipairs(c) do
for _, v in ipairs(c) do
if not v.discontinued then
if not v.discontinued then
local backing_fmt, b_val_fmt
if v.backing == "___" then
backing_fmt = "Mixed"
b_val_fmt = "N/A"
else
_, backing_data = find(r, "code", v.backing)
if backing_data then backing_fmt = [[<abbr title="]] .. backing_data.name .. [[">]] .. v.backing .. "</abbr>"
else backing_fmt = v.backing
end
b_val_fmt = formatval(v.b_val)
end
out = out ..
out = out ..
"<tr><td>" .. v.code ..
"<tr><td>" .. v.code ..
"</td><td>[[" .. v.place ..
"</td><td>[[" .. place_of(v.code) ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>" .. v.backed ..
"]]</td><td>" .. backing_fmt ..
"</td><td>" .. formatval(v.brval) ..
"</td><td>" .. b_val_fmt ..
"</td><td>" .. formatval(c._get_nval(v.code)) ..
"</td><td>" .. formatval(get_nval(v.code)) ..
"</td></tr>"
"</td></tr>"
end
end
Line 37: Line 76:


_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 B.R.)</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>]=]
local c = require"Module:Data/UŊMAO/Currencies"
for _, v in ipairs(c) do
for _, v in ipairs(c) do
if v.discontinued then
if v.discontinued then
local backing_fmt, b_val_fmt
if v.backing == "___" then
backing_fmt = "Mixed"
b_val_fmt = "N/A"
else
_, backing_data = find(r, "code", v.backing)
if backing_data then backing_fmt = [[<abbr title="]] .. backing_data.name .. [[">]] .. v.backing .. "</abbr>"
else backing_fmt = v.backing
end
b_val_fmt = formatval(v.b_val)
end
out = out ..
out = out ..
"<tr><td>" .. v.code ..
"<tr><td>" .. v.code ..
"</td><td>[[" .. v.place ..
"</td><td>[[" .. place_of(v.code) ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>[[" .. v.name ..
"]]</td><td>" .. v.backed ..
"]]</td><td>" .. backing_fmt ..
"</td><td>" .. formatval(v.brval) ..
"</td><td>" .. b_val_fmt ..
"</td><td>" .. formatval(v.nval) ..
"</td><td>" .. formatval(v.n_val) ..
"</td><td>" .. tostring(v.discontinued) ..
"</td><td>" .. tostring(v.discontinued) ..
"</td></tr>"
"</td></tr>"
Line 55: Line 104:
end
end


_m.curency_map = function(frame)
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 .. " (" .. place_of(v.code) .. ")\">" .. 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 .. " (" .. place_of(vf.code) .. ")\">" .. vf.code .. "</abbr></th>"
for _, vt in ipairs(c) do if not vt.discontinued then
out = out .. "<td>" .. formatval(get_nval(vf.code)/get_nval(vt.code)) .. "</td>"
end end
out = out .. "</tr>"
end end
return out
end
return _m
return _m

Latest revision as of 22:58, 17 February 2026

Functions for the UŊMAO page


local def, _a, find do local u = require("Module:Utils") def, _a, find = u.def, u._a, u.find end
local data = mw.loadJsonData "Data:UŊMAO"
local places = require "Module:Places"
local c = data.currencies
local r = data.resources
local _m = {}


local function formatval(v)
	if type(v) ~= "number" then return v end
	return string.format("%.6f", v)
end

local function get_nval(code)
	local _, c_data = find(c, "code", code)
	if not c_data then return nil end
	if c_data.n_val then return c_data.n_val end
	local _, r_data = find(r, "code", c_data.backing)
	if not r_data then return nil end
	return r_data.n_val * c_data.b_val
end

local function place_of(code)
	local _, v = find(c, "code", code)
	if not v.place_override then return (places.get(v.code:sub(1, 2)) or {common_name = "???"}).common_name
	elseif v.code:sub(1,1) == "X" then return v.place_override
	else return places.get(v.place_override).common_name
	end
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>"
		out = out .. v.code 
		out = out .. "</td><td>"
		out = out .. v.name
		out = out .. "</td><td>"
		out = out .. formatval(v.n_val)
		out = out  .. "</td><td>"
		out = out  .. (v.sxg and "yes" or "no")
		out = out  .. "</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_fmt, b_val_fmt
			if v.backing == "___" then
				backing_fmt = "Mixed"
				b_val_fmt = "N/A"
			else
				_, backing_data = find(r, "code", v.backing)
				if backing_data then backing_fmt = [[<abbr title="]] .. backing_data.name .. [[">]] .. v.backing .. "</abbr>"
				else backing_fmt = v.backing
				end
				b_val_fmt = formatval(v.b_val)
			end
			out = out ..
				"<tr><td>" .. v.code ..
				"</td><td>[[" .. place_of(v.code) ..
				"]]</td><td>[[" .. v.name ..
				"]]</td><td>" .. backing_fmt ..
				"</td><td>" .. b_val_fmt ..
				"</td><td>" .. formatval(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_fmt, b_val_fmt
			if v.backing == "___" then
				backing_fmt = "Mixed"
				b_val_fmt = "N/A"
			else
				_, backing_data = find(r, "code", v.backing)
				if backing_data then backing_fmt = [[<abbr title="]] .. backing_data.name .. [[">]] .. v.backing .. "</abbr>"
				else backing_fmt = v.backing
				end
				b_val_fmt = formatval(v.b_val)
			end
			out = out ..
				"<tr><td>" .. v.code ..
				"</td><td>[[" .. place_of(v.code) ..
				"]]</td><td>[[" .. v.name ..
				"]]</td><td>" .. backing_fmt ..
				"</td><td>" .. b_val_fmt ..
				"</td><td>" .. formatval(v.n_val) ..
				"</td><td>" .. tostring(v.discontinued) ..
				"</td></tr>"
		end
	end
	return out .. "</table>"
end

_m.curency_map = function(frame)
	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 .. " (" .. place_of(v.code) .. ")\">" .. 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 .. " (" .. place_of(vf.code) .. ")\">" .. vf.code .. "</abbr></th>"
		for _, vt in ipairs(c) do if not vt.discontinued then
			out = out .. "<td>" .. formatval(get_nval(vf.code)/get_nval(vt.code)) .. "</td>"
		end end
		out = out .. "</tr>"
	end end
	return out
end
return _m