Module:ExchangeDefault

-- -- Default view for for use on Exchange ns pages -- -- Use of this via #invoke is deprecated and will eventually be removed -- This is intended for use by Module:Exchange --

local p = {}

-- imports local excgdata = require( 'Module:ExchangeData' )._main local round = require( 'Module:Number' )._round local timeago = require( 'Module:TimeAgo' )._ago local yesno = require( 'Module:Yesno' )

function p.main( item ) local frame = mw.getCurrentFrame local lang = mw.language.getContentLanguage local title = mw.title.getCurrentTitle local data = mw.loadData( 'Module:Exchange/' .. item )

-- set variables here if possible to keep table building easier to follow local rowspan = 8 local volDate = data.volumeDate or lang:formatDate( 'c' ) local dateDiffZ = lang:formatDate( 'z' ) - lang:formatDate( 'z', volDate ) local dateDiffY = lang:formatDate( 'Y' ) - lang:formatDate( 'Y', volDate ) local price = data.price and lang:formatNum( data.price ) or Unknown local date = Unknown local lowAlch = Not alchable local highAlch = Not alchable local memsIcon = '' local usage = ''

if data.volume and ( dateDiffZ + 365 * dateDiffY ) <= 7 then rowspan = 10 end

if data.date then date = lang:formatDate( 'j F Y, H:i "(UTC)"', data.date ) end

if data.alchable == nil or yesno( data.alchable ) then if data.value then lowAlch = lang:formatNum( math.floor( data.value * 0.4 ) ) highAlch = lang:formatNum( math.floor( data.value * 0.6 ) ) else lowAlch, highAlch = Unknown, Unknown end end

if data.members ~= nil then if data.members then memsIcon = '' else memsIcon = '' end end

-- workaround so we can use `table.concat` usage = {}

for k, v in ipairs( data.usage ) do       usage[k] = v    end

if #usage == 0 then usage = "\n* None" else usage = '\n* ' .. table.concat( usage, '\n* ' ) .. '' end

usage = usage .. string.format('\n Modules: info • data ', data.item, data.item)

-- build table local tbl = mw.html.create( 'table' ) :addClass( 'wikitable' ) :css( {           ['border'] = '0',            ['border-collapse'] = 'separate',            ['margin-top'] = '-1em',            ['margin-bottom'] = '0'        } ) :tag( 'tr' ) :tag( 'th' ) :attr( 'colspan', '2' ) :css( {                   border = '0',                    padding = '0'                } ) :tag( 'table' ) :css( {                       width = '100%',                        ['border-collapse'] = 'collapse'                    } ) :tag( 'tr' ) :tag( 'td' ) :css( {                               padding = '8px 16px',                                ['border-right'] = '0'                            } ) :wikitext( '' ) :done :tag( 'td' ) :css( {                               width = '100%',                                ['font-size'] = '135%',                                ['text-align'] = 'left',                                ['white-space'] = 'normal',                                padding = '8px 0',                                ['border-left'] = '0',                                ['border-right'] = '0'                            } ) -- this used to default to Grand Exchange Market Watch if item wasn't supplied -- but that only happened on 6 user pages, an orphanage and a preload :wikitext(  .. item ..  ) :tag( 'br' ) :done :tag( 'span' ) :css( {                                   ['font-weight'] = 'normal',                                    ['font-size'] = '75%'                                } ) :wikitext( data.examine or '' ) :done :done :tag( 'td' ) :css( {                               padding = '8px 16px',                                ['border-left'] = '0'                            } ) :wikitext( memsIcon ) :done :done :done :done :done :tag( 'tr' ) :tag( 'th' ) :css( {                   ['text-align'] = 'left',                    ['padding-left'] = '10px'                } ) :wikitext( 'Price data' ) :done :tag( 'td' ) :attr( 'rowspan', rowspan ) :css( 'vertical-align', 'top' ) :tag( 'div' ) :addClass( 'GEPage' ) :css( {                       padding = '10px 5px 0 5px',                        float = 'right'                    } ) :tag( 'div' ) :addClass( 'GEdatachart' ) :css( {                           margin = '5px 0 25px 0',                            ['min-width'] = '700px',                            ['height'] = '500px'                        } ) -- GE Chart goes here :done :done :done :done :tag( 'tr' ) :tag( 'td' ) :css( {                   ['vertical-align'] = 'top',                    ['padding-bottom'] = '5px'                } ) :tag( 'ul' ) :tag( 'li' ) :wikitext( 'Price: ' ) :tag( 'span' ) :attr( 'id', 'GEPrice' ) :wikitext( price ) :done :done :tag( 'li' ) :wikitext( 'Last updated: ' .. timeago{data.date, purge='yes'} ) :tag( 'br' ) :done :tag( 'span' ) :attr( 'id', 'GEDate' ) :wikitext( date ) :done :done :done :done :done if data.volume and ( dateDiffZ + 365 * dateDiffY ) <= 7 then tbl :tag( 'tr' ) :tag( 'th' ) :css( {                       ['text-align'] = 'left',                        ['padding-left'] = '10px'                    } ) :wikitext( 'Volume data' ) :done :done :tag( 'tr' ) :tag( 'td' ) :attr( 'id', 'volumeData' ) :css ( {                       ['vertical-align'] = 'top',                        ['padding-bottom'] = '5px'                    } ) :tag( 'ul' ) :tag( 'li' ) :wikitext( '7-day total: ' ) :tag( 'span' ) :attr( 'id', 'GEVolume' ) :wikitext( lang:formatNum( 1000000 * data.volume ) ) :done :done :tag( 'li' ) :wikitext( '1-day average ' .. lang:formatNum( round( 1000000 / 7 * data.volume, -3 ) ) ) :done :tag( 'li' ) :wikitext( 'Last updated: ' .. timeago{data.volumeDate, purge='yes'} ) :tag( 'br' ) :done :tag( 'span' ) :attr( 'id', 'GEVolumeDate' ) :wikitext( lang:formatDate( 'j F Y, H:i "(UTC)"', data.volumeDate ) ) :done :done :done :done end tbl :tag( 'tr' ) :tag( 'th' ) :css( {                   ['text-align'] = 'left',                    ['padding-left'] = '10px'                } ) :wikitext( 'Other details' ) :done :done :tag( 'tr' ) :tag( 'td' ) :css( {                   ['vertical-align'] = 'top',                    ['padding-bottom'] = '5px'                } ) :tag( 'ul' ) :tag( 'li' ) :wikitext( 'Exchange ID: ' ) :tag( 'span' ) :attr( 'id', 'GEDBID' ) :wikitext( data.itemId or Unknown ) :done :done :tag( 'li' ) :wikitext( 'Low Alchemy: ' .. lowAlch ) :done :tag( 'li' ) :wikitext( 'High Alchemy: ' .. highAlch ) :done :tag( 'li' ) :wikitext( 'Value: ' .. ( data.value and lang:formatNum( data.value ) or Unknown ) ) :done :tag( 'li' ) :wikitext( 'Exchange limit: ' .. ( data.limit and lang:formatNum( data.limit ) or Unknown ) ) :done :tag( 'li' ) :wikitext( 'GED Category: ' .. (data.category or Unknown) ) :done :done :done :done :tag( 'tr' ) :tag( 'th' ) :css( {                   ['text-align'] = 'left',                    ['padding-left'] = '10px'                } ) :wikitext( 'External links' ) :done :done :tag( 'tr' ) :tag( 'td' ) :css( {                   ['vertical-align'] = 'top',                    ['padding-bottom'] = '5px'                } ) :tag( 'ul' ) :tag( 'li' ) :wikitext( '.. data.itemId .. ' Look up current price' ) :done :tag( 'li' ) :wikitext( '.. mw.uri.encode( item, 'QUERY' ) .. ' Search for relevant prices' ) :done :done :done :done :tag( 'tr' ) :tag( 'th' ) :css( {                   ['text-align'] = 'left',                    ['padding-left'] = '10px'                } ) :wikitext( 'Usage' ) :done :done :tag( 'tr' ) :tag( 'td' ) :css( {                   ['vertical-align'] = 'top',                    ['padding-left'] = '5px',                    ['padding-bottom'] = '5px'                } ) :wikitext( 'This item is used in:' .. usage ) :done :done

tbl = tostring( tbl )

-- categories local cats = '' local natPrice

if title.nsText == 'Exchange' then cats = cats ..                    ..                     .. ''

if item ~= title.text then cats = cats .. ''       end

-- have to preprocess this for it to work cats = cats .. frame:preprocess( '' )

if not data.itemId then cats = cats .. ''       end

if not data.icon then cats = cats .. ''       end

if data.price and data.value and ( data.alchable == nil or yesno( data.alchable ) ) then if mw.ustring.lower( item ) == 'nature rune' then natPrice = data.price else natPrice = mw.loadData( 'Module:Exchange/Nature rune' ).price end

if math.floor( ( data.value * 0.6 ) - data.price - natPrice ) > 0 then cats = cats .. ''           end

if math.floor( ( data.value * 0.4 ) - data.price - natPrice ) > 0 then cats = cats .. ''           end

if math.floor( ( data.value * 0.3 ) - data.price ) > 0 then cats = cats .. ''           end

elseif not data.value then cats = cats .. ''       end

-- this doesn't allow for the update time to be in the previous day but less than 24 hours -- if that's the case, then the page will end up in the 7 days category -- the same will happen for the other 2 categories too -- but it's not so noticeable given the already elapsed time local lastUpdate = ( lang:formatDate( 'z' ) - lang:formatDate( 'z', data.date ) + 365 * ( lang:formatDate( 'Y' ) - lang:formatDate( 'Y', data.date ) ) + 3 ) / 7 lastUpdate = round( lastUpdate, 0 ) if lastUpdate == 1 then cats = cats .. ''       elseif lastUpdate >= 2 and lastUpdate <= 4 then cats = cats .. ''       elseif lastUpdate > 4 then cats = cats .. ''       end

if not data.limit then cats = cats .. ''       end

if not data.category then cats = cats .. ''       end

-- Error checking if not data.price or data.price < 1 then cats = cats .. ''       end end

-- help header local help = mw.html.create( 'div' ) :attr( 'id', 'gemw_guide' ) :css( {           padding = '5px 10px',            color = '#000',            border = '1px solid #aaa',            background = '#f2f2f2'        } ) :wikitext( 'If you need assistance on editing this page, or trying to understand how these Exchange pages work, please add a comment to Talk:Grand Exchange Market Watch.' )

help = tostring( help )

local noErr, data = pcall( excgdata, { item }, true ) if not noErr then data = '' end return help .. ' ' .. tbl .. data .. cats end

return p