Module:GEMinMax: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary Tag: Reverted |
No edit summary Tag: Manual revert |
||
Line 1: | Line 1: | ||
-- <nowiki> |
|||
local prices = mw.loadJsonData('Module:GEPrices/data.json') |
|||
local _coins = require('Module:Currency')._amount |
|||
local p = {} |
local p = {} |
||
local expr = mw.ext.ParserFunctions.expr |
|||
⚫ | |||
⚫ | |||
wikitable = 'wikitable', |
|||
local args = getargs(frame) |
|||
wikitablereverse = 'wikitablereverse', |
|||
return p._min(args) |
|||
table = 'wikitable', |
|||
⚫ | |||
t = 'wikitable', |
|||
rtable = 'wikitablereverse', |
|||
rt = 'wikitablereverse', |
|||
bracket = 'bracket', |
|||
b = 'bracket', |
|||
backetreverse = 'backetreverse', |
|||
rb = 'backetreverse', |
|||
item = 'item', |
|||
price = 'price', |
|||
none = 'none' |
|||
} |
|||
local formats = { |
|||
wikitable = function(i,v) return string.format('| %s\n| %s', i, v) end, |
|||
wikitablereverse = function(i,v) return string.format('| %s\n| %s', v, i) end, |
|||
bracket = function(i,v) return string.format('%s (%s)', i, v) end, |
|||
backetreverse = function(i,v) return string.format('%s (%s)', v, i) end, |
|||
item = function(i,v) return i end, |
|||
price = function(i,v) return v end, |
|||
none = function(i,v) return '' end |
|||
} |
|||
function |
function findVal(comp, def, args) |
||
local |
local item = '@unknown@' |
||
local value = def |
|||
for |
for i,v in ipairs(args) do |
||
local pr = prices[v] |
|||
if pr then |
|||
⚫ | |||
⚫ | |||
item = v |
|||
⚫ | |||
end |
end |
||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
function p. |
function p._min(args) |
||
return findVal(function(pr,v) return v > pr end, math.huge, args) |
|||
local args = getargs(frame) |
|||
⚫ | |||
return p._max(args) |
|||
⚫ | |||
return findVal(function(pr,v) return v < pr end, -1, args) |
|||
end |
end |
||
function p. |
function p.main(frame) |
||
local |
local c = frame.args[1] |
||
⚫ | |||
local f = fmap[pargs.format] |
|||
for _, v in ipairs(tbl) do |
|||
f = formats[f] or formats.bracket |
|||
⚫ | |||
local r1, r2 = p['_'..c](pargs) |
|||
⚫ | |||
if pargs.coins == 'y' then |
|||
⚫ | |||
r2 = _coins(r2, 'coins') |
|||
elseif pargs.coins == 'n' then |
|||
r2 = _coins(r2, 'nocoins') |
|||
elseif pargs.coins == 'f' then |
|||
r2 = mw.getContentLanguage():formatNum(r2) |
|||
⚫ | |||
if pargs.link == 'plp' then |
|||
r1 = string.format('[[File:%s.png|link=%s]]', r1, r1) |
|||
elseif pargs.link == 'p' then |
|||
r1 = string.format('[[File:%s.png|link=%s]] [[%s]]', r1, r1, r1) |
|||
elseif not pargs.link then |
|||
⚫ | |||
end |
end |
||
⚫ | |||
return high |
|||
mw.ext.VariablesLua.vardefine(pargs.var..'_item', r1) |
|||
⚫ | |||
mw.ext.VariablesLua.vardefine(pargs.var..'_price', r2) |
|||
function getargs(frame) |
|||
⚫ | |||
⚫ | |||
for _, v in ipairs(args) do |
|||
⚫ | |||
w = tonumber(w) or tonumber(expr(w)) |
|||
⚫ | |||
table.insert(nums,w) |
|||
end |
|||
end |
end |
||
return |
return f(r1, r2) |
||
end |
end |
||
return p |
return p |
||
-- </nowiki> |
Latest revision as of 11:22, 17 October 2024
Module documentation
This documentation is transcluded from Module:GEMinMax/doc. [edit] [history] [purge]
Module:GEMinMax's function main is invoked by Template:MaxPrice.
Module:GEMinMax's function main is invoked by Template:MinPrice.
Module:GEMinMax requires Module:Currency.
Module:GEMinMax loads data from Module:GEPrices/data.json.
Module:GEMinMax is invoked by Template:MinPrice.
Module:GEMinMax is invoked by Template:MaxPrice.
Module:GEMinMax requires Module:Currency.
Module:GEMinMax loads data from Module:GEPrices/data.json.
-- <nowiki>
local prices = mw.loadJsonData('Module:GEPrices/data.json')
local _coins = require('Module:Currency')._amount
local p = {}
local fmap = {
wikitable = 'wikitable',
wikitablereverse = 'wikitablereverse',
table = 'wikitable',
t = 'wikitable',
rtable = 'wikitablereverse',
rt = 'wikitablereverse',
bracket = 'bracket',
b = 'bracket',
backetreverse = 'backetreverse',
rb = 'backetreverse',
item = 'item',
price = 'price',
none = 'none'
}
local formats = {
wikitable = function(i,v) return string.format('| %s\n| %s', i, v) end,
wikitablereverse = function(i,v) return string.format('| %s\n| %s', v, i) end,
bracket = function(i,v) return string.format('%s (%s)', i, v) end,
backetreverse = function(i,v) return string.format('%s (%s)', v, i) end,
item = function(i,v) return i end,
price = function(i,v) return v end,
none = function(i,v) return '' end
}
function findVal(comp, def, args)
local item = '@unknown@'
local value = def
for i,v in ipairs(args) do
local pr = prices[v]
if pr then
if comp(pr, value) then
value = pr
item = v
end
end
end
return item, value
end
function p._min(args)
return findVal(function(pr,v) return v > pr end, math.huge, args)
end
function p._max(args)
return findVal(function(pr,v) return v < pr end, -1, args)
end
function p.main(frame)
local c = frame.args[1]
local pargs = frame:getParent().args
local f = fmap[pargs.format]
f = formats[f] or formats.bracket
local r1, r2 = p['_'..c](pargs)
if pargs.coins == 'y' then
r2 = _coins(r2, 'coins')
elseif pargs.coins == 'n' then
r2 = _coins(r2, 'nocoins')
elseif pargs.coins == 'f' then
r2 = mw.getContentLanguage():formatNum(r2)
end
if pargs.link == 'plp' then
r1 = string.format('[[File:%s.png|link=%s]]', r1, r1)
elseif pargs.link == 'p' then
r1 = string.format('[[File:%s.png|link=%s]] [[%s]]', r1, r1, r1)
elseif not pargs.link then
r1 = string.format('[[%s]]', r1)
end
if pargs.var then
mw.ext.VariablesLua.vardefine(pargs.var..'_item', r1)
mw.ext.VariablesLua.vardefine(pargs.var..'_price', r2)
end
return f(r1, r2)
end
return p
-- </nowiki>