Editing Module:Sandbox/User:Alsang

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
require('strict')
require('Module:Mw.html extension')
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 = {}
local p = {}


function sort_entries(entry1, entry2)
-- non dynamic module, no inputs
-- Sort the variants based on the sum of the profession levels
function p.main()
local entry1_value = (entry1['Profession Level A'] or 0) + (entry1['Profession Level B'] or 0)
local entry2_value = (entry2['Profession Level A'] or 0) + (entry2['Profession Level B'] or 0)
-- returns only directly needed parameter needed for the row,
return entry1_value < entry2_value
-- other parameters are determined by subqueries of chained pages
end

function get_table_info(args, get_images)
local variant_name = args.variant or mw.title.getCurrentTitle().fullText
local query = {
local query = {
'[[Activity JSON::~*]]',
'[[Variant of::'..variant_name..']]',
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link
'? = name',
'?Activity JSON = activityJSON',
'?Profession B #',
'limit = 1500'
'?Profession Level A',
'?Profession Level B',
'?Profession Level A High',
'?Profession Level B High',
'?Variant name',
get_images and '?Image#64px;x64px = Image' or nil,
limit = args.limit or 500,
}
}
local results = mw.smw.ask(query)
local smw_data = mw.smw.ask(query)
if not smw_data then
return nil
results = p.screenResults(results)
end

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

end
end


function p.variants_header(args)
-- goes through a list of results and culls the ones which are not needed for this table
local smw_data = get_table_info(args)
function p.screenResults(results)
local resultsScreened = {}
local contents
if smw_data then
local formatted = {}
-- iterate through products
for _, item in ipairs(results) do
for _, entry in ipairs(smw_data) do
local variant_name = entry['Variant name']
if variant_name then
-- if theres only one activity, wrap in table
local page = entry[1]
if type(item.activityJSON)=='string' then
local pipe = page:find('|')
item.activityJSON = { item.activityJSON }
if pipe then
end
page = page:sub(3, pipe-1)
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
else
page = page:sub(3, -3)
-- 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
end

if page:sub(1, 1 + #variant_name + #' (grade ') == ':' .. variant_name .. ' (grade ' and page:sub(-1) == ')' then
table.insert(resultsScreened,itemNew)
local grade_number = page:sub(2 + #variant_name + #' (grade ', -2)
mw.log('"' .. grade_number .. '"')
variant_name = 'Grade ' .. grade_number
end

table.insert(formatted, ('[[%s|%s]]'):format(page, variant_name))
else
table.insert(formatted, entry[1])
end
end
end
end
contents = table.concat(formatted, '&nbsp;•&nbsp;')
else
contents = '[[Category:Empty variant list]]'
end
end
return mw.html.create('div')
:addClass('variants-header')
-- sort the results by recipe level
:wikitext(contents)
table.sort(resultsScreened, function(item1, item2)
:done()
local lvl1 = item1.lvl
end
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


function p.main(frame)
local args = frame:getParent().args
args.variant = args[1] or args.variant
return p.variants_header(args)
end
end


function p.variants_table(args)
-- make the table
local smw_data = get_table_info(args, true)
function p.displayTable(results)
if not smw_data then
local out = mw.html.create('table')
return ':No variants found.'
:addClass('wikitable sortable')
end
local profession_b_flag = false
for _, entry in ipairs(smw_data) do
if entry['Profession B'] or entry['Profession Level B'] then
profession_b_flag = true
end
break
end
local table = mw.html.create('table')
:addClass('sortable wikitable')
:tag('tr')
:tag('tr')
:tag('th')
:tag('th')
:wikitext('Page')
:attr{ colspan = '2' }
:done()
:wikitext('Item')
:tag('th')
:wikitext('Product')
:done()
:tag('th')
:wikitext('Profession')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Level')
:wikitext('Level')
:attrIf(profession_b_flag, 'colspan', 2)
:done()
: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()
:done()
local function formatProfessionLevel(profession, level, high)
if not (profession or level) then
return nil
end
profession = profession or 'Unknown profession'
local level_text = tostring(level or '?')
if high then
level_text = ('%s➨%d'):format(level_text, high)
end
return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession)
end


for i, item in ipairs(results) do
for _, entry in ipairs(smw_data) do
local profession_level_a = entry['Profession Level A'] or '?'
local row = out:tag('tr')
local profession_level_b = entry['Profession Level B'] or '?'
local profession_a = entry['Profession A'] or ''
--level
local profession_b = entry['Profession B'] or ''
:tag('td')
table
:wikitext(item.name)
:tag('tr')
:tag('td')
:css{ ['border-right'] = 'none' }
:wikitext(entry.Image)
:done()
:tag('td')
:css{ ['border-left'] = 'none' }
:wikitext(entry[1])
:done()
:tag('td')
:css{ ['text-align'] = 'right' }
:wikitext(formatProfessionLevel(entry['Profession A'], entry['Profession Level A'], entry['Profession Level A High']))
:IF(profession_b_flag)
:tag('td')
:IF(entry['Profession B'])
:css{ ['text-align'] = 'right' }
:wikitext(formatProfessionLevel(entry['Profession B'], entry['Profession Level B'], entry['Profession Level B High']))
:done()
:END()
:done()
:done()
end
: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()


return table
:done()
end
end


function p.main_table(frame)
return out
local args = frame:getParent().args
args.variant = args[1] or args.variant
return p.variants_table(args)
end
end


Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see Brighter Shores:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

This page is a member of a hidden category: