Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Exchange/ohje
--[[
{{Helper module|name=Exchange
|fname1=_price(arg)
|ftype1=String
|fuse1=Gets the current median price of item named arg
|fname2=_value(arg)
|ftype2=String
|fuse2=Gets the value of item named arg
}}
--]]
-- <pre>
--
-- Apuväline eri Exchange mallineisiin
-- Katso yksittäiset dokumentit lisätiedoista
--
-- Katso myös:
-- - [[Moduuli:ExchangeData]]
-- - [[Moduuli:ExchangeDefault]]
--
local p = {}
-- Lataa vain usein käyetyt moduulit tässä
local yesno = require( 'Moduuli:Yesno' )
local addcommas = require( 'Moduuli:Addcommas' )._add
-- kartta ohjaa oikeille sivuille
local geRedirects = {
['1/2 anchovy pizza'] = '½ anchovy pizza',
['1/2 meat pizza'] = '½ meat pizza',
["1/2 p'apple pizza"] = "½ p'apple pizza",
['1/2 plain pizza'] = '½ plain pizza',
['1/3 evil turnip'] = '⅓ evil turnip',
['2/3 cake'] = '⅔ cake',
['2/3 chocolate cake'] = '⅔ chocolate cake',
['2/3 evil turnip'] = '⅔ evil turnip',
['Dragon platelegs/skirt ornament kit (or)'] = 'Dragon platelegs & skirt ornament kit (or)',
['Dragon platelegs/skirt ornament kit (sp)'] = 'Dragon platelegs & skirt ornament kit (sp)'
}
--
-- Varmista, että ensimmäinen kirjain on iso kirjain
-- Käsittelee automaattisesti ohjaukset
--
local function checkTitle( item )
-- Iso kirjain oikean sivun löytämiseen
item = mw.text.split( item, '' )
item[1] = mw.ustring.upper( item[1] )
item = table.concat( item )
-- Ohjausten käsittely
if geRedirects[item] ~= nil then
item = geRedirects[item]
end
return item
end
--
-- Yksinkertainen mw.loadData wrapperi
--
-- @param item {string} Tavaran datan keräämiseen
-- @return {table} Taulukko datalle
--
local function load( item )
item = checkTitle( item )
local noErr, ret = pcall( mw.loadData, 'Moduuli:Exchange/' .. item )
if noErr then
return ret
end
error( ret )
end
--
-- Palauttaa tavaran hinnan
--
-- @param item {string} Tämänhetkinen hinta
-- @param multi {number} (optional) Moninkertaistaa hinnan tietyllä numerolla
-- @param format {boolean} (optional) Alustaa tuloksen pilkuilla
-- @return {number|string} Tavaran hinta
--
function p._price( item, multi, format )
local price = load( item ).price
local multi = type( multi ) == 'number' and multi or 1
local format = type( format ) == 'boolean' and format or false
local ret = price * multi
if format then
return addcommas( ret )
end
return ret
end
--
-- Palauttaa tavaran ostorajan
--
-- @param item {string} Ostoraja
-- @return {number} Tavaran ostoraja
--
function p._limit( item )
return load( item ).limit
end
--
-- Palauttaa tavaran arvon
--
-- @param item {string} Arvo
-- @return {number} Tavaran arvo
--
function p._value( item )
return load( item ).value
end
--
-- Laskee tavaran tämänhetkisen hinnan ja viimeksipäivitetyn hinnan eron
--
-- @param item {string} Tavara eron laskemiseksi
-- @param format {boolean} `true` jos alustetaan pilkuilla
-- Defaulttina `false`
-- @return {number|string} Hintaero numerona
-- Jos `format` on `true`, palauttaa stringin
-- Jos ei onnistu, palauttaa `0` (numero)
--
function p._diff( item, format )
local data = load( item )
local diff = 0
if data.price and data.last then
diff = data.price - data.last
if format then
diff = addcommas( diff )
end
end
return diff
end
--
-- {{GEItem}} sisäinen metodi
--
-- @todo merge p.tableksi
--
-- @param item {string} Data tavaralle
-- @return {string}
--
function p._table( item )
-- lataa datan ja vaaditut moduulit
local item = checkTitle( item )
local data = load( item )
local timeago = require( 'Moduuli:TimeAgo' )._ago
local changeperday = require( 'Moduuli:ChangePerDay' )._change
-- Muuttjuat tähän seuraamisen helpottamiseksi
local div = '<i>Ei tiedossa</i>'
local limit = data.limit and addcommas( data.limit ) or '<i>Ei tiedossa</i>'
local members = '<i>Ei tiedossa</i>'
if data.last then
local link = 'http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' .. data.itemId
local change = math.abs( changeperday( {data.price, data.last, data.date, data.lastDate} ) )
if data.price > data.last then
arrow = '[[File:Up.png|20px|link=' .. link .. ']]'
elseif data.price < data.last then
arrow = '[[File:Down.png|20px|link=' .. link .. ']]'
else
arrow = '[[File:Unchg.png|40px|link=' .. link .. ']]'
end
if change >= 0.04 then
arrow = arrow .. arrow .. arrow
elseif change >= 0.02 then
arrow = arrow .. arrow
end
div = mw.html.create( 'div' )
:css( 'white-space', 'nowrap' )
:wikitext( arrow )
div = tostring( div )
end
if data.members == true then
members = '[[File:P2P icon.png|30px|link=Members]]'
elseif data.members == false then
members = '[[File:F2P icon.png|30px|link=Free-to-play]]'
end
-- Rakentaa taulukon
local tr = mw.html.create( 'tr' )
:tag( 'td' )
:wikitext( '[[File:' .. item .. '.png|' .. item .. ']]' )
:done()
:tag( 'td' )
:css( {
['width'] = '15%',
['text-align'] = 'left'
} )
:wikitext( '[[' .. item .. ']]' )
:done()
:tag( 'td' )
:wikitext( addcommas( data.price ) )
:done()
:tag( 'td' )
:wikitext( div )
:done()
if data.alchable == nil or yesno( data.alchable ) then
local low, high = '<i>Ei tiedossa</i>', '<i>Ei tiedossa</i>'
if data.value then
low = addcommas( math.floor( data.value * 0.4 ) )
high = addcommas( math.floor( data.value * 0.6 ) )
end
tr
:tag( 'td' )
:wikitext( low )
:done()
:tag( 'td' )
:wikitext( high )
:done()
else
tr
:tag( 'td' )
:attr( 'colspan', '2' )
:wikitext( '<i>Ei voi käyttää alkemiaa</i>' )
:done()
end
tr
:tag( 'td' )
:wikitext( limit )
:done()
:tag( 'td' )
:wikitext( members )
:done()
:tag( 'td' )
:css( 'white-space', 'nowrap' )
:wikitext( '[[Exchange:' .. item .. '|view]]' )
:done()
:tag( 'td' )
:css( 'font-size', '85%' )
:wikitext( timeago{data.date} )
:done()
return tostring( tr )
end
--
-- {{GEExists}}
--
function p.exists( frame )
local args = frame:getParent().args
local item = checkTitle( args[1] or '' )
local noErr, data = pcall( mw.loadData, 'Moduuli:Exchange/' .. item )
if noErr then
return '1'
end
return '0'
end
--
-- Sisäinen metodi p.highAlchTable:lle, p.lowAlchTable:lle skeä p.genStoreTable:lle
--
-- @param item {string} Tavaran nimi
-- @param data {table} Tavaran ge data
-- @param alch {number} Tavaran alch/myyntiarvo
-- @param min {number} (valinnainen) Asettaa määrän tavaroille, kuinka monta voi muuttaa gp:ksi tunnissa
-- @param natPrice {number} (valinnainen) Asettaa Nature runen hinnan (`0` `p.genStoreTable`ssa)
--
local function alchTable( item, data, alch, min, natPrice )
local timeago = require( 'Moduuli:TimeAgo' )._ago
local round = require( 'Moduuli:Number' )._round
-- General store ei tarvitse Naturen hintaa
-- Asetetaan 0:ksi
local natPrice = natPrice or load( 'Nature rune' ).price
local profit = alch - data.price - natPrice
local image = '[[File:' .. item .. '.png|' .. item .. ']]'
local itemStr = '[[' .. item .. ']]'
local priceStr = addcommas( data.price )
local alchStr = addcommas( alch )
local profitStr = addcommas( profit )
local roi = tostring( round( ( profit / ( data.price + natPrice ) * 100 ), 1 ) ) .. '%'
local limit = data.limit and addcommas( data.limit ) or '<i>Ei tiedossa</i>'
local maxProfit = '<i>Ei tiedossa</i>'
local members = '<i>Ei tiedossa</i>'
local details = '[[Exchange:' .. item .. '|Katso]] • [[Exchange:' .. item .. '/Data|Kaavio]]'
local lastUpdated = timeago{data.date}
if data.limit then
-- Maksimimäärä 4800:ssa, maksimimäärä alkemiaa joka neljäs tunti
-- vaihtelee kaupoissa
min = min or 4800
min = ( data.limit > min ) and min or data.limit
maxProfit = addcommas( min * profit )
end
mw.log( maxProfit )
if data.members == true then
members = '[[File:P2P icon.png|30px|link=Members]]'
elseif data.members == false then
members = '[[File:F2P icon.png|30px|link=Free-to-play]]'
end
local tr = mw.html.create( 'tr' )
:tag( 'td' )
:wikitext( image )
:done()
:tag( 'td' )
:css( {
width = '15%',
['text-align'] = 'left'
} )
:wikitext( itemStr )
:done()
:tag( 'td' )
:wikitext( priceStr )
:done()
:tag( 'td' )
:wikitext( alchStr )
:done()
:tag( 'td' )
:wikitext( profitStr )
:done()
:tag( 'td' )
:wikitext( roi )
:done()
:tag( 'td' )
:wikitext( limit )
:done()
:tag( 'td' )
:wikitext( maxProfit )
:done()
:tag( 'td' )
:wikitext( members )
:done()
:tag( 'td' )
:css( 'white-space', 'nowrap' )
:wikitext( details )
:done()
:tag( 'td' )
:css( 'font-size', '85%' )
:wikitext( lastUpdated )
:done()
return tostring( tr )
end
--
-- {{HighAlchTableRow}}
--
-- @example {{HighAlchTableRow|<item>}}
--
function p.highAlchTable( frame )
local args = frame:getParent().args
local item = checkTitle( args[1] )
local data = load( item )
local alch = math.floor( data.value * 0.6 )
return alchTable( item, data, alch )
end
--
-- {{LowAlchTableRow}}
--
-- @example {{LowAlchTableRow|<tavara>}}
--
function p.lowAlchTable( frame )
local args = frame:getParent().args
local item = checkTitle( args[1] )
local data = load( item )
local alch = math.floor( data.value * 0.4 )
return alchTable( item, data, alch )
end
--
-- {{GenStoreTableRow}}
--
-- @example {{GenStoreTableRow|<tavara>}}
--
function p.genStoreTable( frame )
local args = frame:getParent().args
local item = checkTitle( args[1] )
local data = load( item )
local alch = math.floor( data.value * 0.3 )
return alchTable( item, data, alch, 50000, 0 )
end
--
-- {{GEP}}
-- {{GEPrice}}
--
-- @example {{GEPrice|<tavara>|<format>|<multi>}}
-- @example {{GEPrice|<tavara>|<multi>}}
-- @example {{GEP|<tavara>|<multi>}}
--
function p.price( frame )
-- usage: {{foo|item|format|multi}} or {{foo|item|multi}}
local args = frame.args
local pargs = frame:getParent().args
local item = pargs[1]
if item then
item = mw.text.trim( item )
else
error( '"item" argument not specified', 0 )
end
-- Defaulttina alustaa vanhojen GE mallineiden takia, jotta sopii yhteen
local format = true
local multi = 1
-- format is set with #invoke
-- so set it first to allow it to be overridden by template args
if args.format ~= nil then
format = yesno( args.format )
end
if tonumber( pargs[2] ) ~= nil then
multi = tonumber( pargs[2] )
-- Osoitus
-- #expr:n käyttö varmistukseksi
elseif pargs[2] ~= nil and mw.ustring.find( pargs[2], '[/*+-]' ) then
multi = tonumber( frame:preprocess( '{{#expr:' .. pargs[2] .. '}}' ) )
-- Käyttää elseif:tä, ettei tapahtuisi esimerkiksi {{GEP|Foo|1}}
-- Aiheuttaa alustuksen
elseif type( yesno( pargs[2] ) ) == 'boolean' then
format = yesno( pargs[2] )
if tonumber( pargs[3] ) ~= nil then
multi = tonumber( pargs[3] )
end
end
return p._price( item, multi, format )
end
--
-- {{GEItem}}
--
-- @example {{GEItem|<tavara>}}
--
function p.table( frame )
local args = frame:getParent().args
local item = args[1]
if item then
item = mw.text.trim( item )
else
error( '"item" argument not specified', 0 )
end
return p._table( item )
end
--
-- {{ExchangeItem}}
-- {{GEDiff}}
-- {{GELimit}}
-- {{GEValue}}
-- {{GEId}}
--
-- @example {{ExchangeItem|<tavara>}}
-- @example {{GEDiff|<tavara>}}
-- @example {{GELimit|<tavara>}}
-- @example {{GEValue|<tavara>}}
-- @example {{GEId|<tavara>}}
--
function p.view( frame )
local fargs = frame.args
local pargs = frame:getParent().args
local item = pargs[1]
local view = fargs.view or ''
local loadView = {limit=true, value=true, itemId=true}
if item then
item = mw.text.trim( item )
else
error( '"item" argument not specified', 0 )
end
view = mw.ustring.lower( view )
if view == 'itemid' then
view = 'itemId'
end
if view == 'diff' then
return p._diff( item )
elseif loadView[view] then
return load( item )[view]
else
local default = require( 'Moduuli:ExchangeDefault' )
-- handle redirects and casing of item before passing it on
item = checkTitle( item )
return default.main( item )
end
end
return p
Community content is available under CC-BY-SA unless otherwise noted.