Module:Sandbox/User:Alsang/NodeDescriptionChecker: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (Alsang moved page Module:Sandbox/User:Alsang/CarpenterList to Module:Sandbox/User:Alsang/NodeDescriptionChecker: repurpose this page) |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
p = {} |
|||
require('strict') |
|||
require('Module:Mw.html extension') |
|||
local search = require('Module:RecipeTreeSearch') |
|||
local param = require( 'Module:Paramtest' ) |
|||
local currency = require('Module:Currency') |
|||
local lang = mw.getContentLanguage() |
|||
function p.main() |
|||
local p = {} |
|||
local query = {'[[~*(skill node)]]', |
|||
-- non dynamic module, no inputs |
|||
'?= node', |
|||
function p.main() |
|||
'?Description=nodeDesc', |
|||
-- returns only directly needed parameter needed for the row, |
|||
'?Has subobject.Dropped item = item', |
|||
-- other parameters are determined by subqueries of chained pages |
|||
'?Has subobject.Dropped item.Description=itemDesc', |
|||
local query = { |
|||
'limit=500', |
|||
--'[[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 |
|||
'sort=Variant of,Profession Level A' |
|||
'[[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 |
|||
--'[[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) |
||
local same = {} |
|||
results = p.formatResults(results) |
|||
local onlyitem = {} |
|||
local onlynode = {} |
|||
return p.displayTable(results) |
|||
local neither = {} |
|||
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 |
|||
local onlyitemN = 0 |
|||
--for debugging |
|||
for _,_ in ipairs(onlyitem) do |
|||
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>' |
|||
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' }) |
|||
local onlynodeN = 0 |
|||
end |
|||
for _,_ in ipairs(onlynode) do |
|||
onlynodeN = onlynodeN + 1 |
|||
-- do calculations and determine strings to go in cells |
|||
function p.formatResults(results) |
|||
-- 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 |
||
local neitherN = 0 |
|||
return results |
|||
for _,_ in ipairs(neither) do |
|||
end |
|||
neitherN = neitherN + 1 |
|||
end |
|||
-- make the table |
|||
function p.displayTable(results) |
|||
local differentN = 0 |
|||
for _,_ in ipairs(different) do |
|||
differentN = differentN + 1 |
|||
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') |
||
:attr{ colspan = '3' } |
|||
:wikitext('[[File:Stonemason small icon.png|15px]] Level') |
|||
:wikitext('Nodes with no descriptions') |
|||
:done() |
:done() |
||
:tag('td') |
|||
:wikitext(onlyitemN) |
|||
:done() |
|||
:done() |
|||
:tag('tr') |
|||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Node') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext('Node description') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Products') |
|||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Item') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext('Item description') |
|||
:attr{ colspan = '10' } |
|||
: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') |
||
:attr{ colspan = '3' } |
|||
:wikitext('XP<br>(per item)') |
|||
:wikitext('Items with no descriptions') |
|||
:done() |
:done() |
||
:tag('td') |
|||
:wikitext(onlynodeN) |
|||
:done() |
|||
:done() |
|||
:tag('tr') |
|||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Node') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Node description') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Item') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext('Item description') |
|||
:attr{ colspan = '10' } |
|||
:wikitext('Coins/XP') |
|||
:done() |
:done() |
||
:done() |
:done() |
||
for _,page in ipairs(onlynode) do |
|||
local unknown_value_cell = mw.html.create('td') |
|||
: |
out:tag('tr') |
||
: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') |
||
:wikitext(page.node) |
|||
:css{ ['text-align'] = 'center' } |
|||
:wikitext(item.lvl) |
|||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.lvlHigh and item.lvlLow) |
|||
:tag('td') |
:tag('td') |
||
:wikitext(page.nodeDesc) |
|||
:css{ ['text-align'] = 'center' } |
|||
:done() |
|||
:tag('td') |
|||
:wikitext( |
:wikitext(page.item) |
||
: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() |
||
end |
|||
:tag('td') |
|||
:addClass('plinkt-image no-border') |
|||
out:tag('tr') |
|||
:css{ ['border-left'] = '0', ['padding-left'] = '0' } |
|||
:tag('th') |
|||
:wikitext('[[File:' .. item.name .. '.png|link=' .. item.name .. '|30px]]') |
|||
:attr{ colspan = '3' } |
|||
:wikitext('Niether Node nor Item has description') |
|||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:wikitext(neitherN) |
|||
:addClass('plinkt-link no-border') |
|||
: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 |
|||
:tag('tr') |
|||
row |
|||
:tag('th') |
|||
:node(currency_cell(item.buy)) |
|||
: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(neither) do |
|||
out:tag('tr') |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(page.node) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerStone) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(page.nodeDesc) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerSpace) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(page.item) |
||
:done() |
:done() |
||
:ELSE() |
|||
:node(unknown_value_cell) |
|||
:END() |
|||
:IF(item.XPPerHour) |
|||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(page.itemDesc) |
||
:done() |
:done() |
||
: |
:done() |
||
end |
|||
:node(unknown_value_cell) |
|||
out:tag('tr') |
|||
:tag('th') |
|||
:node(currency_cell(item.costPerXP)) |
|||
: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 |
Latest revision as of 15:41, 31 December 2024
Module documentation
This documentation is transcluded from Module:Sandbox/User:Alsang/NodeDescriptionChecker/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Sandbox/User:Alsang/NodeDescriptionChecker/doc. [edit]
Module:Sandbox/User:Alsang/NodeDescriptionChecker's function main is invoked by Template:Sandbox/User:Alsang/NodeDescriptionChecker.
p = {}
function p.main()
local query = {'[[~*(skill node)]]',
'?= node',
'?Description=nodeDesc',
'?Has subobject.Dropped item = item',
'?Has subobject.Dropped item.Description=itemDesc',
'limit=500',
'sort=Variant of,Profession Level A'
}
local results = mw.smw.ask(query)
local same = {}
local onlyitem = {}
local onlynode = {}
local neither = {}
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
local onlyitemN = 0
for _,_ in ipairs(onlyitem) do
onlyitemN = onlyitemN + 1
end
local onlynodeN = 0
for _,_ in ipairs(onlynode) do
onlynodeN = onlynodeN + 1
end
local neitherN = 0
for _,_ in ipairs(neither) do
neitherN = neitherN + 1
end
local differentN = 0
for _,_ in ipairs(different) do
differentN = differentN + 1
end
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:attr{ colspan = '3' }
:wikitext('Nodes with no descriptions')
:done()
:tag('td')
:wikitext(onlyitemN)
:done()
:done()
: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(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')
:attr{ colspan = '3' }
:wikitext('Items with no descriptions')
:done()
:tag('td')
:wikitext(onlynodeN)
:done()
:done()
: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(onlynode) 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')
:attr{ colspan = '3' }
:wikitext('Niether Node nor Item has description')
:done()
:tag('td')
:wikitext(neitherN)
:done()
:done()
: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(neither) 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')
:attr{ colspan = '3' }
:wikitext('Node and Item both have descriptions, but they are different')
:done()
:tag('td')
:wikitext(differentN)
:done()
:done()
: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
end
return p