Editing Module:Sandbox/User:Alsang/NodeDescriptionChecker
Jump to navigation
Jump to search
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') |
|||
p = {} |
|||
require('Module:Mw.html extension') |
|||
local search = require('Module:RecipeTreeSearch') |
|||
local param = require( 'Module:Paramtest' ) |
|||
local currency = require('Module:Currency') |
|||
local lang = mw.getContentLanguage() |
|||
local p = {} |
|||
function p.main() |
|||
-- non dynamic module, no inputs |
|||
local query = {'[[~*(skill node)]]', |
|||
function p.main() |
|||
'?= node', |
|||
-- returns only directly needed parameter needed for the row, |
|||
'?Description=nodeDesc', |
|||
-- other parameters are determined by subqueries of chained pages |
|||
'?Has subobject.Dropped item = item', |
|||
local query = { |
|||
'?Has subobject.Dropped item.Description=itemDesc', |
|||
--'[[Uses facility::One Handed Range (bonewright)||One Handed Melee Workbench (bonewright)||Two Handed Range Workbench (bonewright)||Two Handed Melee Workbench (bonewright)||Shield Vice]', -- bonewright active |
|||
'limit=500', |
|||
'[[Uses facility::One Handed Ranged Workbench (stonemason)||One Handed Melee Workbench (stonemason)||Two Handed Ranged Workbench (stonemason)||Two Handed Melee Workbench (stonemason)||Shield Work Rock]]', -- stonemason active |
|||
'sort=Variant of,Profession Level A' |
|||
--'[[Uses facility::Goblin Forge||Gnome Forge (skill node)]]', -- blacksmith active |
|||
'?Profession Level A = lvlLow', |
|||
'?Profession Level A High = lvlHigh', |
|||
'?Uses facility = facility', |
|||
'? #- = name', |
|||
'?Recipe JSON = recipeJSON', |
|||
'?Activity XP = XP', |
|||
'?Activity duration = duration', |
|||
'?Value = sell', |
|||
'sort = Activity level', |
|||
'limit = 500' |
|||
} |
} |
||
local results = mw.smw.ask(query) |
local results = mw.smw.ask(query) |
||
results = p.screenResults(results,false) |
|||
local same = {} |
|||
local onlyitem = {} |
|||
results = p.formatResults(results) |
|||
local onlynode = {} |
|||
local neither = {} |
|||
return p.displayTable(results) |
|||
local different = {} |
|||
for _,page in ipairs(results) do |
|||
if page.nodeDesc == nil and page.itemDesc == nil then |
|||
table.insert(neither,page) |
|||
elseif page.nodeDesc == nil and page.itemDesc ~= nil then |
|||
table.insert(onlyitem,page) |
|||
elseif page.nodeDesc ~= nil and page.itemDesc == nil then |
|||
table.insert(onlynode,page) |
|||
elseif page.nodeDesc == page.itemDesc then |
|||
table.insert(same,page) |
|||
else |
|||
table.insert(different,page) |
|||
end |
|||
end |
|||
--for debugging |
|||
local onlyitemN = 0 |
|||
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>' |
|||
for _,_ in ipairs(onlyitem) do |
|||
onlyitemN = onlyitemN + 1 |
|||
end |
|||
-- makes the html for the cells containing currency directly |
|||
-- Replaces nil with an "unknown" cell |
|||
local function currency_cell(amount) |
|||
if not amount then |
|||
return mw.html.create('td') |
|||
:addClass('table-bg-gray') |
|||
:css{ ['text-align'] = 'center' } |
|||
:attr{ colspan = '10' } |
|||
:wikitext("''unknown''") |
|||
:done() |
|||
end |
end |
||
return currency._cell(amount, { html = 'yes' }) |
|||
end |
|||
-- Need to split the table into two, lines with crates are passive and lines without are not |
|||
function p.screenResults(results,isPassive) |
|||
local resultsPassive = {} |
|||
local resultsNotPassive = {} |
|||
-- iterate through products |
|||
local onlynodeN = 0 |
|||
for _, |
for _, item in ipairs(results) do |
||
local hasCrate = item.recipeJSON and string.find(item.recipeJSON,'Crate') |
|||
onlynodeN = onlynodeN + 1 |
|||
if hasCrate then |
|||
table.insert(resultsPassive,item) |
|||
else |
|||
table.insert(resultsNotPassive,item) |
|||
end |
|||
end |
end |
||
if isPassive then |
|||
local neitherN = 0 |
|||
return resultsPassive |
|||
for _,_ in ipairs(neither) do |
|||
else |
|||
neitherN = neitherN + 1 |
|||
return resultsNotPassive |
|||
end |
end |
||
end |
|||
local differentN = 0 |
|||
-- do calculations and determine strings to go in cells |
|||
for _,_ in ipairs(different) do |
|||
function p.formatResults(results) |
|||
differentN = differentN + 1 |
|||
-- iterate through products |
|||
for _, item in ipairs(results) do |
|||
-- New module for recipe searching |
|||
local fullRecipe = search.main(item.name) |
|||
item.materials = fullRecipe.materials |
|||
item.outputQuantity = fullRecipe.output[1].quantity |
|||
item.buy = fullRecipe.buyPrice |
|||
item.XP = fullRecipe.xp |
|||
item.duration = fullRecipe.duration |
|||
-- specific to weapon crafting, where properties are a bit different |
|||
item.lvl = fullRecipe.level |
|||
-- iterate through materials, keep track of how many materials are needed from each shop |
|||
item.poleShopTrips = 0 |
|||
item.stoneShopTrips = 0 |
|||
for _, material in ipairs(item.materials) do |
|||
-- query which shop sold it, add to running total |
|||
local shopNameQuery = '[[:+]][[Sold item::' .. material.name .. ']]|?Sold by #-|mainlabel=' .. material.name |
|||
local shopNameResult = mw.smw.ask(shopNameQuery) or {} |
|||
local shopName = '' |
|||
if shopNameResult[1] and shopNameResult[1]["Sold by"] then |
|||
shopName = shopNameResult[1]["Sold by"] or '' |
|||
end |
|||
if shopName=="Timber Merchant Shop" then |
|||
item.poleShopTrips = item.poleShopTrips + material.quantity |
|||
elseif shopName=="Poffit's Interesting Rocks" then |
|||
item.stoneShopTrips = item.stoneShopTrips + material.quantity |
|||
end |
|||
end |
|||
-- direct values |
|||
item.sell = item.sell and item.outputQuantity and item.sell * item.outputQuantity |
|||
item.costPerXP = item.buy and item.XP and math.floor(item.buy / item.XP * 100) / 100 |
|||
item.XPPerStone = item.XP and not(item.stoneShopTrips==0) and math.floor(item.XP / item.stoneShopTrips * 100) / 100 |
|||
item.XPPerSpace = item.XPPerStone and item.poleShopTrips and math.floor(item.XP / (item.stoneShopTrips + item.poleShopTrips) * 100) / 100 |
|||
-- there will be extra time spent buying and selling items, and moving between stations |
|||
-- assume make enough trips to buy 24 of each material from each shop, per batch of 24 weapons |
|||
local batchSize = 24 |
|||
-- 120 seconds moving between stations and selling items per 24 made |
|||
-- 40 seconds per trip to the pole shop |
|||
-- 40 seconds per trip to the stone shop |
|||
-- are these results optimal? no. are they approximate? yes |
|||
local downtime = 120 + item.poleShopTrips * 40 + item.stoneShopTrips * 40 |
|||
item.duration = item.duration and item.duration + downtime/batchSize |
|||
item.productPerHour = item.duration and 1 / item.duration * 3600 |
|||
-- properties per hour |
|||
item.XPPerHour = item.XP and item.productPerHour and math.floor(item.XP * item.productPerHour) |
|||
end |
end |
||
return results |
|||
end |
|||
-- make the table |
|||
function p.displayTable(results) |
|||
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('[[File:Stonemason small icon.png|15px]] Level') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Nodes with no descriptions') |
|||
:done() |
:done() |
||
:tag('td') |
|||
:wikitext(onlyitemN) |
|||
:done() |
|||
:done() |
|||
:tag('tr') |
|||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('[[File:Hammermage small icon.png|15px]] Levels') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:attr{ colspan = '3' } |
|||
:wikitext('Node description') |
|||
:wikitext('Products') |
|||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Materials') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:attr{ colspan = '10' } |
|||
:wikitext('Item description') |
|||
:wikitext('Buy Value') |
|||
:done() |
:done() |
||
:done() |
|||
for _,page in ipairs(onlyitem) do |
|||
out:tag('tr') |
|||
:tag('td') |
|||
:wikitext(page.node) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.nodeDesc) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.item) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.itemDesc) |
|||
:done() |
|||
:done() |
|||
end |
|||
out:tag('tr') |
|||
:tag('th') |
:tag('th') |
||
:wikitext('XP<br>(per item)') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Items with no descriptions') |
|||
:done() |
:done() |
||
:tag('td') |
|||
:wikitext(onlynodeN) |
|||
:done() |
|||
:done() |
|||
:tag('tr') |
|||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('XP<br>(per stome)') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('XP<br>(per space)') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('XP/hr') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:attr{ colspan = '10' } |
|||
:wikitext('Item description') |
|||
:wikitext('Coins/XP') |
|||
:done() |
:done() |
||
:done() |
:done() |
||
local unknown_value_cell = mw.html.create('td') |
|||
for _,page in ipairs(onlynode) do |
|||
:addClass('table-bg-gray') |
|||
:css{ ['text-align'] = 'center' } |
|||
:wikitext("''unknown''") |
|||
for i, item in ipairs(results) do |
|||
local row = out:tag('tr') |
|||
:IF(item.lvl) |
|||
:tag('td') |
:tag('td') |
||
:css{ ['text-align'] = 'center' } |
|||
:wikitext(page.node) |
|||
:wikitext(item.lvl) |
|||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.lvlHigh and item.lvlLow) |
|||
:tag('td') |
:tag('td') |
||
:css{ ['text-align'] = 'center' } |
|||
:wikitext(page.nodeDesc) |
|||
: |
:wikitext(item.lvlLow) |
||
: |
:wikitext(' – ') |
||
:wikitext( |
:wikitext(item.lvlHigh) |
||
:done() |
|||
:tag('td') |
|||
:wikitext(page.itemDesc) |
|||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:tag('td') |
|||
:css{ ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' } |
|||
:attr{ ['data-sort-value'] = item.name } |
|||
:wikitext(item.outputQuantity .. ' ×') |
|||
:done() |
:done() |
||
:tag('td') |
|||
end |
|||
:addClass('plinkt-image no-border') |
|||
:css{ ['border-left'] = '0', ['padding-left'] = '0' } |
|||
out:tag('tr') |
|||
:wikitext('[[File:' .. item.name .. '.png|link=' .. item.name .. '|30px]]') |
|||
:tag('th') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Niether Node nor Item has description') |
|||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:addClass('plinkt-link no-border') |
|||
:wikitext(neitherN) |
|||
:wikitext('[[' .. item.name .. ']]') |
|||
:done() |
:done() |
||
:done() |
|||
local materialCell = row:tag('td') |
|||
for i, _ in ipairs(item.materials) do |
|||
materialCell:wikitext(item.materials[i].quantity .. '× [[File:' .. item.materials[i].name .. '.png|18px|link=' .. item.materials[i].name .. ']] [[' .. item.materials[i].name .. ']]<br>') |
|||
end |
|||
row |
|||
:tag('tr') |
|||
:node(currency_cell(item.buy)) |
|||
:tag('th') |
|||
:wikitext('Node') |
|||
: |
:IF(item.XP) |
||
:tag('th') |
|||
:wikitext('Node description') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Item') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Item description') |
|||
:done() |
|||
:done() |
|||
for _,page in ipairs(neither) do |
|||
out:tag('tr') |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(item.XP and lang:formatNum(tonumber(item.XP))) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerStone) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(item.XPPerStone and lang:formatNum(tonumber(item.XPPerStone))) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerSpace) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(item.XPPerSpace and lang:formatNum(tonumber(item.XPPerSpace))) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerHour) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(item.XPPerHour and lang:formatNum(tonumber(item.XPPerHour))) |
||
:done() |
:done() |
||
: |
:ELSE() |
||
:node(unknown_value_cell) |
|||
end |
|||
:END() |
|||
out:tag('tr') |
|||
:node(currency_cell(item.costPerXP)) |
|||
:tag('th') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Node and Item both have descriptions, but they are different') |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(differentN) |
|||
:done() |
|||
:done() |
:done() |
||
end |
|||
:tag('tr') |
|||
:tag('th') |
|||
:wikitext('Node') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Node description') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Item') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Item description') |
|||
:done() |
|||
:done() |
|||
for _,page in ipairs(different) do |
|||
out:tag('tr') |
|||
:tag('td') |
|||
:wikitext(page.node) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.nodeDesc) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.item) |
|||
:done() |
|||
:tag('td') |
|||
:wikitext(page.itemDesc) |
|||
:done() |
|||
:done() |
|||
end |
|||
return out |
return out |
||
end |
end |
||
return p |
return p |