Module:Sandbox/User:Alsang/NodeDescriptionChecker: Difference between revisions

working for stonemason, need to check all data
No edit summary
(working for stonemason, need to check all data)
Line 1:
require('strict')
require('Module:Mw.html extension')
local recipesearch = require('Module:Infobox RecipeRecipeTreeSearch') -- to make use of its extensive material searching function
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local discount = require('Module:MerchantHideDiscount')
local lang = mw.getContentLanguage()
 
Line 13 ⟶ 12:
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
-- this is in testing, uncomment out one line to test that type of query
-- requires pages to be made and have recipes on them or it tends to get an error
-- query types that include non-recipe passive activities behave weird and need to be fixed
local query = {
--'[[Uses facility::One Handed Range (bonewright)||One Handed Melee Workbench (bonewright)||Two Handed Range Workbench (bonewright)||Two Handed Melee Workbench (bonewright)||Shield Vice (bonewright)]]', -- bonewright active
'[[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
'[[Variant of::Knickknacks||Divination||Sabertooth Cat Skeleton||Wooly Mammoth Skeleton||Triceratops Skeleton||T-Rex Skeleton||Wendigo Skeleton||Bonemeal Cement]]', -- bonewright passive
--'[[Uses facility::One Handed Range (stonemason)||One Handed Melee Workbench (stonemason)||Two Handed Range Workbench (stonemason)||Two Handed Melee Workbench (stonemason)||Shield Vice (stonemason)]]', -- stonemason active
--'[[Uses facility::Goblin Forge||Gnome Forge (skill node)]]', -- blacksmith active
'?VariantProfession ofLevel #-A = variantlvlLow',
'?Profession Level A High = lvllvlHigh',
'?Uses facility = facility',
'? #- = name',
'?Recipe JSON = recipeJSON',
Line 29 ⟶ 24:
'?Activity duration = duration',
'?Value = sell',
'?Activity coinssort = coinsActivity level',
'sort = Profession Level A',
'limit = 500'
}
local results = mw.smw.ask(query)
 
results = p.screenResults(results,false)
-- criterion for if an entry is a recipe, or a passive activity
 
for _, item in ipairs(results) do
item.passiveActivity = not(item.variant=='Knickknacks' or item.variant=='Bonemeal Cement' )
end
results = p.formatResults(results)
 
Line 61 ⟶ 52:
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
for _, item in ipairs(results) do
local hasCrate = item.recipeJSON and string.find(item.recipeJSON,'Crate')
if hasCrate then
table.insert(resultsPassive,item)
else
table.insert(resultsNotPassive,item)
end
end
if isPassive then
return resultsPassive
else
return resultsNotPassive
end
end
 
-- do calculations and determine strings to go in cells
function p.formatResults(results)
 
-- iterate through products
for _, item in ipairs(results) do
-- recipeNew inmodule afor workablerecipe formatsearching
local fullRecipe = search.main(item.name)
if item.passiveActivity then
item.materials = fullRecipe.materials
item.outputQuantity = fullRecipe.output[1].quantity
-- if it is a passive activity that is not a recipe
item.buy = fullRecipe.buyPrice
-- some fields are easy to work out
item.outputQuantityXP = 1fullRecipe.xp
item.materialsduration = {}fullRecipe.duration
item.intermediates = {}
-- specific to weapon crafting, where properties are a bit different
item.buy = 0
item.selllvl = itemfullRecipe.coinslevel
-- 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
else
shopName = shopNameResult[1]["Sold by"] or ''
local unpackJSON = mw.text.jsonDecode(item.recipeJSON)
item.outputQuantity = unpackJSON.output[1].quantity
-- call the module:infobox recipe to extensively search for
-- all raw materials (to add to prices)
-- all intermediate materials (for intermediate XP and duration)
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials)
if next(Materials) ~= nil then
item.materials = Materials.rawMaterials
item.intermediates = Materials.intermediateMaterials
end
if shopName=="Timber Merchant Shop" then
-- iterate through materials, adding buy price to running total (individuals not needed)
item.poleShopTrips = item.poleShopTrips + material.quantity
item.buy = 0
elseif shopName=="Poffit's Interesting Rocks" then
for _, material in ipairs(item.materials) do
item.stoneShopTrips = item.stoneShopTrips + material.quantity
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. material.name .. ']]|?Shop buy price|mainlabel=' .. material.name
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPrice = 0
if shopPriceResult[1] and shopPriceResult[1]["Shop buy price"] then
shopPrice = tonumber(shopPriceResult[1]["Shop buy price"]) or 0
else
item.buy = nil
end
item.buy = item.buy and item.buy + shopPrice * material.quantity
end
 
-- iterate through intermediaries to add to XP and duration parameters
for _, intermediate in ipairs(item.intermediates) do
-- look up activity XP and add it to running total
local XPQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Activity XP|mainlabel=' .. intermediate.name
local XPResult = mw.smw.ask(XPQuery) or {}
local XPIncrease = 0
if XPResult[1] and XPResult[1]["Activity XP"] then
XPIncrease = tonumber(XPResult[1]["Activity XP"]) or 0
else
XPIncrease = nil
end
-- need to look up both the amount of the item used in this recipe and created in its own recipe to know how much of this xp to use
local QTYused = intermediate.quantity
local QTYQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Recipe JSON|mainlabel=' .. intermediate.name
local QTYResult = mw.smw.ask(QTYQuery) or {}
local QTYmade = 0
if QTYResult[1] and QTYResult[1]["Recipe JSON"] then
QTYmade = mw.text.jsonDecode(QTYResult[1]["Recipe JSON"]) or {}
end
QTYmade = QTYmade.output[1].quantity
item.XP = item.XP and XPIncrease and item.XP + XPIncrease * QTYused / QTYmade;
-- look up activity duration and add it to running total
local durationQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Activity duration|mainlabel=' .. intermediate.name
local durationResult = mw.smw.ask(durationQuery) or {}
local durationIncrease = 0
if durationResult[1] and durationResult[1]["Activity duration"] then
durationIncrease = tonumber(durationResult[1]["Activity duration"]) or 0
else
durationIncrease = nil
end
item.duration = item.duration and durationIncrease and item.duration + durationIncrease * intermediate.quantity
end
end
-- direct values
item.sell = item.sell and item.outputQuantity and item.sell * item.outputQuantity
item.profitcostPerXP = item.sellbuy and item.buyXP and math.floor(item.sellbuy -/ item.buyXP * 100) / 100
item.profitPerXPXPPerStone = item.profitXP and not(item.XPstoneShopTrips==0) and math.floor(item.profitXP / item.XPstoneShopTrips * 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
-- a lot of downtime in leatherworker
-- assume make enough trips to buy 24 of each material from each shop, per batch of 24 weapons
-- 1min 40s to go from hide stall to tannery, run round the tannery, run to leather stall, then back to hide stall
local batchSize = 24
-- 120 seconds moving between stations and selling items per 24 made
local downtime = 100
-- 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
Line 168 ⟶ 136:
-- properties per hour
item.XPPerHour = item.XP and item.productPerHour and math.floor(item.XP * item.productPerHour)
item.profitPerHour = item.profit and item.productPerHour and math.floor(item.profit * item.productPerHour)
end
 
Line 181 ⟶ 148:
:tag('th')
:wikitext('[[File:Stonemason small icon.png|15px]] Level')
:done()
:tag('th')
:wikitext('[[File:Hammermage small icon.png|15px]] Levels')
:done()
:tag('th')
:attr{ colspan = '3' }
:wikitext('ProductProducts')
:done()
:tag('th')
Line 194 ⟶ 164:
:done()
:tag('th')
:wikitext('XP<br>(per item)')
:attr{ colspan = '10' }
:wikitext('Sell Value')
:done()
:tag('th')
:wikitext('XP<br>(per stome)')
:attr{ colspan = '10' }
:wikitext('Profit')
:done()
:tag('th')
:wikitext('XP<br>(per space)')
:attr{ colspan = '10' }
:wikitext('Profit/hr')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
Line 228 ⟶ 192:
:css{ ['text-align'] = 'center' }
:wikitext(item.lvl)
:done()
:ELSE()
:node(unknown_value_cell)
:END()
:IF(item.lvlHigh and item.lvlLow)
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(item.lvlLow)
:wikitext(' – ')
:wikitext(item.lvlHigh)
:done()
:ELSE()
Line 247 ⟶ 221:
:wikitext('[[' .. item.name .. ']]')
:done()
:IF(not(item.passiveActivity))
 
local materialCell = row:tag('td')
 
for i, _ in ipairs(item.materials) do
materialCell:wikitext(item.materials[i].quantity .. '&times; [[File:' .. item.materials[i].name .. '.png|30px18px|link=' .. item.materials[i].name .. ']]' .. '[[' .. item.materials[i].name .. ']]<br>')
end
row
:node(currency_cell(item.buy))
:node(currency_cell(item.sell))
:ELSE()
:tag('td')
:addClass('table-na')
:attr{ colspan = '21' }
:wikitext('N/A')
:done()
:END()
row
:node(currency_cell(item.profit))
:node(currency_cell(item.profitPerHourbuy))
 
:IF(item.XP)
:tag('td')
:wikitext(item.XP and lang:formatNum(tonumber(item.XP)))
:done()
:ELSE()
:node(unknown_value_cell)
:END()
 
:IF(item.XPPerStone)
:tag('td')
:wikitext(item.XPPerStone and lang:formatNum(tonumber(item.XPPerStone)))
:done()
:ELSE()
:node(unknown_value_cell)
:END()
 
:IF(item.XPPerSpace)
:tag('td')
:wikitext(item.XPPerSpace and lang:formatNum(tonumber(item.XPPerSpace)))
:done()
:ELSE()
Line 288 ⟶ 263:
:END()
 
:node(currency_cell(item.profitPerXPcostPerXP))
 
:done()
21,283

edits