Module:Sandbox/User:Alsang: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
require('strict')
p = {}
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local xpdata = mw.loadData('Module:Experience/data')


local p = {}
function p.main(args)

-- non dynamic module, no inputs
function p.main()
-- returns only directly needed parameter needed for the row,
local variants = {'Basic','Moderate','Fine','Strong','Superior','Perfect'}
-- other parameters are determined by subqueries of chained pages
local weapons1 = {'Hammerfist','Throwing Stones','Stone Slab Shield',
local query = {
'Stone Mace','Stone Discs','War Hammer',
'[[Activity JSON::~*]]',
'Bolas','Stone Chunk Shield','Double Headed Hammer',
'? = name',
'Throwing Clubs','Great Stone Mace',' Polished Stone Shield',
'?Activity JSON = activityJSON',
'Throwing Hammers','Great Hammer','Sling'}
'limit = 1500'
local weapons2 = {'Hammerfist','Throwing Stones','Stone Slab Shield',
}
'Stone Mace','Stone Discs','War Hammer',
local results = mw.smw.ask(query)
'Bolas','Stone Chunk Shield','Double Headed Hammer',
'Throwing Clubs','Great Stone Mace',' Polished Stone Shield',
'Throwing Hammers','Great Hammer','Sling'}
local weapons3 = {'Hammerfist','Throwing Stones','Stone Slab Shield',
'Stone Mace','Stone Discs','War Hammer',
'Bolas','Stone Chunk Shield','Double Headed Hammer',
'Throwing Clubs','Great Stone Mace',' Polished Stone Shield',
'Throwing Hammers','Great Hammer','Sling'}
results = p.screenResults(results)
weapons = weapons1
local allWeapons = {}
for i,item in ipairs(variants) do
for j,jtem in ipairs(weapons) do
table.insert(allWeapons,{pagename='[[' .. jtem .. ' (' .. item .. ')]]',wrongname='[[' .. item .. ' ' .. jtem .. ']]'})
end
end


return p.displayTable(results)
for i,item in ipairs(allWeapons) do
local query = mw.smw.ask(item.pagename .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.facility = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity XP #- = data|mainlabel=-')
if type(query)=='table' then
item.XP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity duration #- = data|mainlabel=-')
if type(query)=='table' then
item.duration = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity KP #- = data|mainlabel=-')
if type(query)=='table' then
item.KP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Recipe output #- = data|mainlabel=-')
if type(query)=='table' then
item.output = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.name = query[1].data
end
end
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Page')
:done()
:tag('th')
:wikitext('Item name')
:done()
:tag('th')
:wikitext('Recipe Output')
:done()
:tag('th')
:wikitext('Facility')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
:wikitext('KP')
:done()
:tag('th')
:wikitext('duration')
:done()
:tag('th')
:wikitext('Wrong Page (shouldnt exist)')
:done()
:done()
for i,item in ipairs(allWeapons) do
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagename)
:done()
:tag('td')
:wikitext(item.name)
:done()
:tag('td')
:wikitext(item.output)
:done()
:tag('td')
:wikitext(item.facility)
:done()
:tag('td')
:wikitext(item.XP)
:done()
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.duration)
:done()
:tag('td')
:wikitext(item.wrongname)
:done()
:done()
:done()
end
return out
--for debugging
--for debugging
--return '<pre>'..mw.text.jsonEncode(allWeapons, mw.text.JSON_PRETTY)..'</pre>'
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'

end
end


-- goes through a list of results and culls the ones which are not needed for this table
function p.stones()
function p.screenResults(results)
local resultsScreened = {}
-- iterate through products
local variants = {'Coarse','Rugged','Average','Fine','Sturdy','Perfect'}
for _, item in ipairs(results) do
local stones ={'Flint','Basalt','Andesite','Granite','Deathstone'}
local allStones = {}
for i,item in ipairs(variants) do
for j,jtem in ipairs(stones) do
table.insert(allStones,{pagename='[[' .. item .. ' ' .. jtem .. ' (Etched)]]',resource='[[' .. item .. ' ' .. jtem .. ']]'})
end
end

-- if theres only one activity, wrap in table
for i,item in ipairs(allStones) do
if type(item.activityJSON)=='string' then
item.activityJSON = { item.activityJSON }
local query = mw.smw.ask(item.pagename .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.facility = query[1].data
end
end
for j,json in ipairs(item.activityJSON) do
local query = mw.smw.ask(item.pagename .. '|?Activity XP #- = data|mainlabel=-')
if type(query)=='table' then
item.XP = query[1].data
end
local activityJSON = mw.text.jsonDecode(json)
local query = mw.smw.ask(item.pagename .. '|?Activity duration #- = data|mainlabel=-')
if type(query)=='table' then
item.duration = query[1].data
if activityJSON.duration and tonumber(activityJSON.duration)==20 then
local itemNew = {}
itemNew.name = item.name
itemNew.XP = activityJSON.xp
itemNew.lvl = activityJSON.level
itemNew.profession = activityJSON.profession
itemNew.duration = activityJSON.duration
itemNew.product = activityJSON.output[1].name
itemNew.XPperHour = itemNew.XP and tonumber(itemNew.XP) and itemNew.duration and tonumber(itemNew.duration) and tonumber(itemNew.XP) * 3600 / tonumber(itemNew.duration)
itemNew.fitXP = xpdata.knowledge[itemNew.lvl]*4*0.0005
if itemNew.lvl>=200 then
itemNew.fitXP = itemNew.fitXP * 4
end
itemNew.fitXP = math.floor(itemNew.fitXP * 100 ) / 100
local query = mw.smw.ask('[[Sold item::' .. itemNew.product .. ']][[Shop sell price::!~N/A]]|?Shop sell price=data|mainlabel=-')
if type(query)=='table' then
-- price is returned as a number
itemNew.productSellPrice = tonumber(query[1].data)*0.005
else
-- will return nil if the item is not in a shop, or if it is in a shop but can only be sold to the shop
itemNew.productSellPrice = nil
end
table.insert(resultsScreened,itemNew)
end
end
end
local query = mw.smw.ask(item.pagename .. '|?Activity KP #- = data|mainlabel=-')
if type(query)=='table' then
item.KP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Recipe output #- = data|mainlabel=-')
if type(query)=='table' then
item.output = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.name = query[1].data
end
end
end
-- sort the results by recipe level
local out = mw.html.create('table')
table.sort(resultsScreened, function(item1, item2)
:addClass('wikitable sortable')
local lvl1 = item1.lvl
:tag('tr')
local lvl2 = item2.lvl
:tag('th')
if (lvl1 == nil) ~= (lvl2 == nil) then --one of two are empty
:wikitext('Page name')
return lvl2 == nil -- true if lvl2 is nil but not lvl1, false if lvl1 is nil but not lvl2
:done()
end
:tag('th')
if lvl1 == nil then
:wikitext('Item name')
return false -- Both empty, equivalent
:done()
:tag('th')
:wikitext('Resource')
:done()
:tag('th')
:wikitext('Recipe Output')
:done()
:tag('th')
:wikitext('Facility')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
:wikitext('KP')
:done()
:tag('th')
:wikitext('duration')
:done()
:done()
for i,item in ipairs(allStones) do
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagename)
:done()
:tag('td')
:wikitext(item.name)
:done()
:tag('td')
:wikitext(item.resource)
:done()
:tag('td')
:wikitext(item.output)
:done()
:tag('td')
:wikitext(item.facility)
:done()
:tag('td')
:wikitext(item.XP)
:done()
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.duration)
:done()
:done()
:done()
end
end
return lvl1 < lvl2 -- normal comparison
end)
return out
--for debugging
--return '<pre>'..mw.text.jsonEncode(allWeapons, mw.text.JSON_PRETTY)..'</pre>'
end


return resultsScreened
function p.metals()
local metals ={'Laterite Iron','Folrian Cabranese','Sylentnite Flantium','Maloic Adathril',
'Limonite Iron','Aulsian Cabranese','Yehrite Flantium','Rigic Adathril',
'Goethite Iron','Babian Cabranese','Holmitite Flantium','Portoic Adathril',
'Hematite Iron','Morian Cabranese','Amirite Flantium','Caric Adathril',
'Magnetite Iron','Shaprian Cabranese','Eysite Flantium','Masic Adathril',
'Siderite Iron','Temberian Cabranese','Seethalite Flantium','Fortoic Adathril'}
local allMetals = {}
for i,item in ipairs(metals) do
table.insert(allMetals,{pagename='[[' .. item .. ' Ingot]]',resource='[[' .. item .. ' Ore]]'})
end


for i,item in ipairs(allMetals) do
local query = mw.smw.ask(item.pagename .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.facility = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity XP #- = data|mainlabel=-')
if type(query)=='table' then
item.XP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity duration #- = data|mainlabel=-')
if type(query)=='table' then
item.duration = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity KP #- = data|mainlabel=-')
if type(query)=='table' then
item.KP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Recipe output #- = data|mainlabel=-')
if type(query)=='table' then
item.output = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.name = query[1].data
end
end
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Page name')
:done()
:tag('th')
:wikitext('Item name')
:done()
:tag('th')
:wikitext('Resource')
:done()
:tag('th')
:wikitext('Recipe Output')
:done()
:tag('th')
:wikitext('Facility')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
:wikitext('KP')
:done()
:tag('th')
:wikitext('duration')
:done()
:done()
for i,item in ipairs(allMetals) do
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagename)
:done()
:tag('td')
:wikitext(item.name)
:done()
:tag('td')
:wikitext(item.resource)
:done()
:tag('td')
:wikitext(item.output)
:done()
:tag('td')
:wikitext(item.facility)
:done()
:tag('td')
:wikitext(item.XP)
:done()
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.duration)
:done()
:done()
:done()
end
return out
--for debugging
--return '<pre>'..mw.text.jsonEncode(allWeapons, mw.text.JSON_PRETTY)..'</pre>'
end
end


-- make the table
function p.bones()
function p.displayTable(results)
local bones ={'Crooked Goat Horn',
'Yellowing Rams Horn',
'Streaky Bone Spike',
'Cracked Femur Shard',
'Gray Goat Horn',
'Mottled Rams Horn',
'Dappled Bone Spike',
'Dusty Femur Shard',
'Ridged Goat Horn',
'Sturdy Rams Horn',
'Bistre Bone Spike',
'Weathered Femur Shard',
'Smooth Goat Horn',
'Chunky Rams Horn',
'Pointed Bone Spike',
'Striated Femur Shard',
'Long Goat Horn',
'Pristine Rams Horn',
'Jagged Bone Spike',
'Sharp Femur Shard',
'Robust Goat Horn',
'Immaculate Rams Horn',
'Razor Bone Spike',
'Chunky Femur Shard'}
local allBones = {}
for i,item in ipairs(bones) do
table.insert(allBones,{pagename='[[' .. item .. ' (Brewed)]]',resource='[[' .. item .. ']]'})
end

for i,item in ipairs(allBones) do
local query = mw.smw.ask(item.pagename .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.facility = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity XP #- = data|mainlabel=-')
if type(query)=='table' then
item.XP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity duration #- = data|mainlabel=-')
if type(query)=='table' then
item.duration = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity KP #- = data|mainlabel=-')
if type(query)=='table' then
item.KP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Recipe output #- = data|mainlabel=-')
if type(query)=='table' then
item.output = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.name = query[1].data
end
end
local out = mw.html.create('table')
local out = mw.html.create('table')
:addClass('wikitable sortable')
:addClass('wikitable sortable')
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
:wikitext('Page name')
:wikitext('Page')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Item name')
:wikitext('Product')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Resource')
:wikitext('Profession')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Recipe Output')
:wikitext('Level')
:done()
:tag('th')
:wikitext('Facility')
:done()
:done()
:tag('th')
:tag('th')
Line 451: Line 115:
:done()
:done()
:tag('th')
:tag('th')
:wikitext('KP')
:wikitext('0.0005 of levelup XP')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('duration')
:wikitext('sell price<br>per action')
:done()
:done()
-- :tag('th')
-- :wikitext('Duration')
-- :done()
-- :tag('th')
-- :wikitext('XP/hr')
-- :done()
:done()
:done()
for i,item in ipairs(allBones) do
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagename)
:done()
:tag('td')
:wikitext(item.name)
:done()
:tag('td')
:wikitext(item.resource)
:done()
:tag('td')
:wikitext(item.output)
:done()
:tag('td')
:wikitext(item.facility)
:done()
:tag('td')
:wikitext(item.XP)
:done()
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.duration)
:done()
:done()
:done()
end
return out
--for debugging
--return '<pre>'..mw.text.jsonEncode(allWeapons, mw.text.JSON_PRETTY)..'</pre>'
end


for i, item in ipairs(results) do
function p.metalgoods()
local row = out:tag('tr')
allJewels = {
{pagename = '[[Bangle Shinerium Jewelry]]', lvl = 20, tablematerial = '[[Softglow Shinerium]]'},
{pagename = '[[Locket Shinerium Jewelry]]', lvl = 26, tablematerial = '[[Softglow Shinerium]]'},
{pagename = '[[Circlet Shinerium Jewelry]]', lvl = 32, tablematerial = '[[Glitterstream Shinerium]]'},
{pagename = '[[Bangle Silver Jewelry]]', lvl = 39, tablematerial = '[[Winterspirit Silver]]'},
{pagename = '[[Locket Silver Jewelry]]', lvl = 43, tablematerial = '[[Winterspirit Silver]]'},
{pagename = '[[Earrings Shinerium Jewelry]]', lvl = 49, tablematerial = '[[Glitterstream Shinerium]]'},
{pagename = '[[Pendant Shinerium Jewelry]]', lvl = 56, tablematerial = '[[Firefly Shinerium]]'},
{pagename = '[[Necklace Shinerium Jewelry]]', lvl = 60, tablematerial = '[[Firefly Shinerium]]'},
{pagename = '[[Earrings Silver Jewelry]]', lvl = 67, tablematerial = '[[Brightspire Silver]]'},
{pagename = '[[Locket Gold Jewelry]]', lvl = 73, tablematerial = '[[Hearthlight Gold]]'},
{pagename = '[[Necklace Silver Jewelry]]', lvl = 77, tablematerial = '[[Brightspire Silver]]'},
{pagename = '[[Earrings Gold Jewelry]]', lvl = 84, tablematerial = '[[Hearthlight Gold]]'},
{pagename = '[[Circlet Silver Jewelry]]', lvl = 90, tablematerial = '[[Gallant Silver]]'},
{pagename = '[[Ring Shinerium Jewelry]]', lvl = 95, tablematerial = '[[Resplendent Shinerium]]'},
{pagename = '[[Choker Shinerium Jewelry]]', lvl = 101, tablematerial = '[[Resplendent Shinerium]]'},
{pagename = '[[Earrings Purpladium Jewelry]]', lvl = 107, tablematerial = '[[Violet Purpladium]]'},
{pagename = '[[Ring Silver Jewelry]]', lvl = 112, tablematerial = '[[Gallant Silver]]'},
{pagename = '[[Pendant Silver Jewelry]]', lvl = 118, tablematerial = '[[Fullmoon Silver]]'},
{pagename = '[[Bangle Gold Jewelry]]', lvl = 122, tablematerial = '[[Lionsmane Gold]]'},
{pagename = '[[Ring Gold Jewelry]]', lvl = 129, tablematerial = '[[Lionsmane Gold]]'},
{pagename = '[[Choker Silver Jewelry]]', lvl = 135, tablematerial = '[[Fullmoon Silver]]'},
{pagename = '[[Necklace Gold Jewelry]]', lvl = 140, tablematerial = '[[Hightower Gold]]'},
{pagename = '[[Ring Purpladium Jewelry]]', lvl = 146, tablematerial = '[[Violet Purpladium]]'},
{pagename = '[[Bracelet Shinerium Jewelry]]', lvl = 152, tablematerial = '[[Lastwish Shinerium]]'},
{pagename = '[[Signet Ring Shinerium Jewelry]]', lvl = 157, tablematerial = '[[Lastwish Shinerium]]'},
{pagename = '[[Choker Gold Jewelry]]', lvl = 163, tablematerial = '[[Hightower Gold]]'},
{pagename = '[[Locket Purpladium Jewelry]]', lvl = 169, tablematerial = '[[Mulberry Purpladium]]'},
{pagename = '[[Bracelet Silver Jewelry]]', lvl = 174, tablematerial = '[[Whitestar Silver]]'},
{pagename = '[[Signet Ring Silver Jewelry]]', lvl = 180, tablematerial = '[[Whitestar Silver]]'},
{pagename = '[[Choker Purpladium Jewelry]]', lvl = 187, tablematerial = '[[Mulberry Purpladium]]'},
{pagename = '[[Cuff Links Shinerium Jewelry]]', lvl = 191, tablematerial = '[[Constellation Shinerium]]'},
{pagename = '[[Bracelet Gold Jewelry]]', lvl = 197, tablematerial = '[[Morningsun Gold]]'},
{pagename = '[[Signet Ring Gold Jewelry]]', lvl = 206},
{pagename = '[[Brooch Shinerium Jewelry]]', lvl = 226},
{pagename = '[[Necklace Purpladium Jewelry]]', lvl = 247},
{pagename = '[[Circlet Gold Jewelry]]', lvl = 260},
{pagename = '[[Bangle Purpladium Jewelry]]', lvl = 280},
{pagename = '[[Pendant Gold Jewelry]]', lvl = 301},
{pagename = '[[Cuff Links Silver Jewelry]]', lvl = 314},
{pagename = '[[Brooch Silver Jewelry]]', lvl = 334},
{pagename = '[[Signet Ring Purpladium Jewelry]]', lvl = 355},
{pagename = '[[Bracelet Purpladium Jewelry]]', lvl = 368},
{pagename = '[[Circlet Purpladium Jewelry]]', lvl = 388},
{pagename = '[[Brooch Gold Jewelry]]', lvl = 409},
{pagename = '[[Cuff Links Gold Jewelry]]', lvl = 422},
{pagename = '[[Pendant Purpladium Jewelry]]', lvl = 442},
{pagename = '[[Brooch Purpladium Jewelry]]', lvl = 463},
{pagename = '[[Cuff Links Purpladium Jewelry]]', lvl = 476},

}

for i,item in ipairs(allJewels) do
--level
local query = mw.smw.ask(item.pagename .. '|?Uses facility #- = data|mainlabel=-')
:tag('td')
if type(query)=='table' then
:wikitext(item.name)
item.facility = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity XP #- = data|mainlabel=-')
if type(query)=='table' then
item.XP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity duration #- = data|mainlabel=-')
if type(query)=='table' then
item.duration = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Activity KP #- = data|mainlabel=-')
if type(query)=='table' then
item.KP = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Recipe output #- = data|mainlabel=-')
if type(query)=='table' then
item.output = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Uses item #- = data|mainlabel=-')
if type(query)=='table' then
item.input = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.name = query[1].data
end
local query = mw.smw.ask(item.pagename .. '|?Profession Level A #- = data|mainlabel=-')
if type(query)=='table' then
item.recipelvl = query[1].data
end
end
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Page name')
:done()
:done()
:tag('th')
:tag('td')
:wikitext('table lvl')
:wikitext('[[' .. item.product .. ']]')
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Table resource')
:wikitext('[[' .. item.profession .. ']]')
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Item name')
:wikitext(item.lvl)
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Recipe Output')
:wikitext(item.XP)
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Recipe Resource')
:wikitext(item.fitXP)
:done()
:done()
:tag('th')
:tag('td')
:wikitext('Facility')
:wikitext(item.productSellPrice)
:done()
:tag('th')
:wikitext('Item lvl')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
:wikitext('KP')
:done()
:tag('th')
:wikitext('duration')
:done()
:done()
-- :tag('td')
-- :wikitext(item.duration)
-- :done()
-- :tag('td')
-- :wikitext(item.XPperHour)
-- :done()

:done()
:done()
end

for i,item in ipairs(allJewels) do
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagename)
:done()
:tag('td')
:wikitext(item.lvl)
:done()
:tag('td')
:wikitext(item.tablematerial)
:done()
:tag('td')
:wikitext(item.name)
:done()
:tag('td')
:wikitext(item.output)
:done()
:tag('td')
:wikitext(item.input[1])
:done()
:tag('td')
:wikitext(item.facility)
:done()
:tag('td')
:wikitext(item.recipelvl)
:done()
:tag('td')
:wikitext(item.XP)
:done()
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.duration)
:done()
:done()
:done()
end
return out
return out
--for debugging
--return '<pre>'..mw.text.jsonEncode(allWeapons, mw.text.JSON_PRETTY)..'</pre>'
end
end



Revision as of 00:51, 18 December 2024

Module documentation
This documentation is transcluded from Module:Sandbox/User:Alsang/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Sandbox/User:Alsang/doc. [edit]
Module:Sandbox/User:Alsang's function main is invoked by Template:Sandbox/User:Alsang.
Module:Sandbox/User:Alsang requires Module:Currency.
Module:Sandbox/User:Alsang requires Module:Mw.html extension.
Module:Sandbox/User:Alsang requires Module:Paramtest.
Module:Sandbox/User:Alsang requires strict.
Module:Sandbox/User:Alsang loads data from Module:Experience/data.

require('strict')
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local xpdata = mw.loadData('Module:Experience/data')

local p = {}

-- non dynamic module, no inputs
function p.main()
	
	-- returns only directly needed parameter needed for the row,
	-- other parameters are determined by subqueries of chained pages
	local query = {
		'[[Activity JSON::~*]]',
		'? = name',
		'?Activity JSON = activityJSON',
		'limit = 1500'
	}
	local results = mw.smw.ask(query)
	
	results = p.screenResults(results)

	return p.displayTable(results)
	
	--for debugging
	--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'

end

-- goes through a list of results and culls the ones which are not needed for this table
function p.screenResults(results)
	local resultsScreened = {}
	
	-- iterate through products
	for _, item in ipairs(results) do
		
		-- if theres only one activity, wrap in table
		if type(item.activityJSON)=='string' then
			item.activityJSON = { item.activityJSON }
		end
		
		for j,json in ipairs(item.activityJSON) do
		
			local activityJSON = mw.text.jsonDecode(json)
			
			if activityJSON.duration and tonumber(activityJSON.duration)==20 then
				local itemNew = {}
				itemNew.name = item.name
				itemNew.XP = activityJSON.xp
				itemNew.lvl = activityJSON.level
				itemNew.profession = activityJSON.profession
				itemNew.duration = activityJSON.duration
				itemNew.product = activityJSON.output[1].name
				
				itemNew.XPperHour = itemNew.XP and tonumber(itemNew.XP) and itemNew.duration and tonumber(itemNew.duration) and tonumber(itemNew.XP) * 3600 / tonumber(itemNew.duration)
				
				itemNew.fitXP = xpdata.knowledge[itemNew.lvl]*4*0.0005
				if itemNew.lvl>=200 then
					itemNew.fitXP = itemNew.fitXP * 4
				end
				itemNew.fitXP = math.floor(itemNew.fitXP * 100 ) / 100
				
				local query = mw.smw.ask('[[Sold item::' .. itemNew.product .. ']][[Shop sell price::!~N/A]]|?Shop sell price=data|mainlabel=-')
					if type(query)=='table' then
					-- price is returned as a number
					itemNew.productSellPrice = tonumber(query[1].data)*0.005
				else
					-- will return nil if the item is not in a shop, or if it is in a shop but can only be sold to the shop
					itemNew.productSellPrice = nil
				end
				
				table.insert(resultsScreened,itemNew)
			end
		end
	end
	
	-- sort the results by recipe level
	table.sort(resultsScreened, function(item1, item2)
		local lvl1 = item1.lvl
		local lvl2 = item2.lvl
		if (lvl1 == nil) ~= (lvl2 == nil) then --one of two are empty
			return lvl2 == nil -- true if lvl2 is nil but not lvl1, false if lvl1 is nil but not lvl2
		end
		if lvl1 == nil then
			return false  -- Both empty, equivalent
		end
		return lvl1 < lvl2 -- normal comparison
	end)

	return resultsScreened

end

-- make the table
function p.displayTable(results)
	local out = mw.html.create('table')
		:addClass('wikitable sortable')
		:tag('tr')
			:tag('th')
				:wikitext('Page')
			:done()
			:tag('th')
				:wikitext('Product')
			:done()
			:tag('th')
				:wikitext('Profession')
			:done()
			:tag('th')
				:wikitext('Level')
			:done()
			:tag('th')
				:wikitext('XP')
			:done()
			:tag('th')
				:wikitext('0.0005 of levelup XP')
			:done()
			:tag('th')
				:wikitext('sell price<br>per action')
			:done()
--			:tag('th')
--				:wikitext('Duration')
--			:done()
--			:tag('th')
--				:wikitext('XP/hr')
--			:done()
		:done()

	for i, item in ipairs(results) do
		local row = out:tag('tr')
		
			--level
			:tag('td')
				:wikitext(item.name)
			:done()
			:tag('td')
				:wikitext('[[' .. item.product .. ']]')
			:done()
			:tag('td')
				:wikitext('[[' .. item.profession .. ']]')
			:done()
			:tag('td')
				:wikitext(item.lvl)
			:done()
			:tag('td')
				:wikitext(item.XP)
			:done()
			:tag('td')
				:wikitext(item.fitXP)
			:done()
			:tag('td')
				:wikitext(item.productSellPrice)
			:done()
--			:tag('td')
--				:wikitext(item.duration)
--			:done()
--			:tag('td')
--				:wikitext(item.XPperHour)
--			:done()

		:done()
	end

	return out
end

return p