Module:Sandbox/User:Alsang/PriceChecker: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Californ1a (talk | contribs) mNo edit summary |
No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
⚫ | |||
-- Utility function to clean up number strings by removing commas |
|||
local function cleanNumberString(value) |
|||
⚫ | |||
return value:gsub(",", "") |
|||
⚫ | |||
return value |
|||
⚫ | |||
⚫ | |||
function p.main() |
function p.main() |
||
-- returns only directly needed parameter needed for the row, |
|||
-- other parameters are determined by subqueries of chained pages |
|||
local query = { |
|||
'[[-Sold item.Shop sell price::+]]', |
|||
'?=Name', |
|||
'?-Sold item.Shop sell price=ShopValue', |
|||
'?Value=InfoboxValue', |
|||
'limit = 500' |
|||
} |
|||
'order = asc' |
|||
} |
|||
local results = mw.smw.ask(query) |
|||
⚫ | |||
⚫ | |||
local shopValues = item.ShopValue -- Could be an array or a single value |
|||
if shopValues ~= nil then |
|||
if type(shopValues) == "string" then |
|||
shopValues = { shopValues } -- Normalize to a table for consistency |
|||
end |
|||
local out = {} |
|||
⚫ | |||
if infoboxValue == nil then |
|||
⚫ | |||
infoboxValue = 0 |
|||
local s = item.ShopValue |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if i==tonumber(s) or not(tonumber(s)) then |
|||
add = false |
|||
end |
end |
||
⚫ | |||
local hasMismatch = false |
|||
⚫ | |||
if i==tonumber(shop) or not(tonumber(shop)) then |
|||
for _, shopValue in ipairs(shopValues) do |
|||
add = false |
|||
if shopValue ~= "N/A" then |
|||
⚫ | |||
-- Compare numeric values |
|||
end |
|||
local cleanShopValue = cleanNumberString(shopValue) |
|||
end |
|||
local numericShopValue = tonumber(cleanShopValue) |
|||
if add then |
|||
if numericShopValue and numericShopValue ~= infoboxValue then |
|||
⚫ | |||
hasMismatch = true |
|||
end |
|||
break |
|||
⚫ | |||
end |
|||
end |
|||
return table.concat(out, '<br>') |
|||
end |
|||
-- Add the item to the output if any shopValue mismatched InfoboxValue |
|||
if hasMismatch then |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
-- Format the output to display each item's details |
|||
local output = {} |
|||
⚫ | |||
table.insert(output, mw.text.jsonEncode(item)) -- Convert each item to a JSON string for display |
|||
⚫ | |||
return table.concat(output, '<br>') -- Concatenate the JSON representations with a line break |
|||
end |
end |
||
Revision as of 20:02, 6 January 2025
Module documentation
This documentation is transcluded from Module:Sandbox/User:Alsang/PriceChecker/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Sandbox/User:Alsang/PriceChecker/doc. [edit]
Module:Sandbox/User:Alsang/PriceChecker's function main is invoked by Template:Sandbox/User:Alsang/PriceChecker.
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 = {
'[[-Sold item.Shop sell price::+]]',
'?=Name',
'?-Sold item.Shop sell price=ShopValue',
'?Value=InfoboxValue',
'limit = 500'
}
local results = mw.smw.ask(query)
local out = {}
for _,item in ipairs(results) do
local i = tonumber(item.InfoboxValue)
local s = item.ShopValue
local add = true
if type(s)=='string' then
if i==tonumber(s) or not(tonumber(s)) then
add = false
end
elseif type(s)=='table' then
for _,shop in ipairs(s) do
if i==tonumber(shop) or not(tonumber(shop)) then
add = false
end
end
end
if add then
table.insert(out,item.Name)
end
end
return table.concat(out, '<br>')
end
return p