Skip to content

Commit bb52c37

Browse files
committed
Defer loading of trade stat data and fix tests
1 parent 3890daa commit bb52c37

5 files changed

Lines changed: 36 additions & 13 deletions

File tree

spec/System/TestTradeQueryGenerator_spec.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ describe("TradeQueryGenerator", function()
55
-- Pass: Mod line maps correctly to trade stat entry without error
66
-- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries
77
it("handles special curse case", function()
8-
local mod = { tradeHashes = {[30642521] = {"You can apply an additional Curse"}} }
9-
local tradeStatsParsed = { result = { [2] = { entries = { { text = "You can apply # additional Curses", id = "explicit.stat_30642521" } } } } }
10-
mock_queryGen.modData = { Explicit = true }
11-
mock_queryGen:ProcessMod(mod, tradeStatsParsed, 1)
8+
local mod = { tradeHashes = {[30642521] = {"You can apply an additional Curse"}}, type = "Prefix", weightKey = {}, weightVal = {} }
9+
mock_queryGen.modData = { Explicit = {} }
10+
mock_queryGen:ProcessMod(mod)
1211
-- Simplified assertion; in full impl, check modData
1312
assert.is_true(true)
1413
end)

src/Classes/TradeHelpers.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,25 @@ function M.modLineValue(line)
3232
return tonumber(line:match("%-?[%d]+%.?[%d]*"))
3333
end
3434

35+
local _tradeStats
36+
3537
---@return table? tradeStats
3638
function M.getTradeStats()
39+
if _tradeStats then return _tradeStats end
3740
local file = io.open("./Data/trade_site_stats.json")
3841
if not file then return nil end
3942
local fileContents = file:read("*a")
4043
local parsed = dkjson.decode(fileContents)
41-
return parsed and parsed.result
44+
_tradeStats = parsed and parsed.result
45+
return _tradeStats
4246
end
4347

48+
local _optionTradeStatMap
49+
4450
---@param tradeStats table table of data from https://www.pathofexile.com/api/trade2/data/stats
4551
---@return table optionTradeStatMap table containing helper data for matching trade option filters
4652
local function getOptionTradeStatMap(tradeStats)
53+
if _optionTradeStatMap then return _optionTradeStatMap end
4754
local optionTradeStatMap = {}
4855
for _, cat in ipairs(tradeStats) do
4956
if cat.id == "enchant" or cat.id == "explicit" or cat.id == "implicit" then
@@ -62,7 +69,8 @@ local function getOptionTradeStatMap(tradeStats)
6269
end
6370
end
6471
end
65-
return optionTradeStatMap
72+
_optionTradeStatMap = optionTradeStatMap
73+
return _optionTradeStatMap
6674
end
6775

6876
-- Map source types used in OpenBuySimilarPopup to trade API category labels
@@ -152,8 +160,6 @@ function M.formatDatabaseText(text)
152160
return text
153161
end
154162

155-
local tradeStats = M.getTradeStats()
156-
local optionTradeStatMap = getOptionTradeStatMap(tradeStats)
157163

158164
-- Helper: find the trade stat ID for a mod line
159165
---@param item table
@@ -191,7 +197,9 @@ function M.findTradeHash(item, modLine, modType, isDesecrated)
191197
end
192198
end
193199

194-
if not tradeStats then return end
200+
local tradeStats = M.getTradeStats()
201+
local optionTradeStatMap = getOptionTradeStatMap(tradeStats)
202+
if not tradeStats or not optionTradeStatMap then return end
195203

196204
for _, v in ipairs(optionTradeStatMap[modType] or {}) do
197205
if v.pattern then

src/Classes/TradeQuery.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ function TradeQueryClass:GetResultEvaluation(row_idx, result_index, calcFunc, ba
777777
self.onlyWeightedBaseOutput[row_idx][result_index] = onlyWeightedBaseOutput
778778
self.lastComparedWeightList[row_idx][result_index] = self.statSortSelectionList
779779
end
780-
780+
781781
local slotName = self.slotTables[row_idx].nodeId and "Jewel " .. tostring(self.slotTables[row_idx].nodeId) or self.slotTables[row_idx].slotName
782782
if slotName == "Megalomaniac" then
783783
local addedNodes = {}
@@ -787,7 +787,7 @@ function TradeQueryClass:GetResultEvaluation(row_idx, result_index, calcFunc, ba
787787
addedNodes[node] = true
788788
end
789789
end
790-
790+
791791
local output = self:ReduceOutput(calcFunc({ addNodes = addedNodes }))
792792
local weight = self.tradeQueryGenerator.WeightedRatioOutputs(baseOutput, output, self.statSortSelectionList)
793793
result.evaluation = {{ output = output, weight = weight }}
@@ -971,7 +971,9 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
971971
if self.tradeQueryGenerator.lastAugmentBehaviour == "Copy Current" or self.tradeQueryGenerator.lastAnointBehaviour == "Copy Current" then
972972
for i, _ in ipairs(items) do
973973
local item = new("Item", items[i].item_string)
974-
self.itemsTab:CopyAnointsAndAugments(item, true, true, context.slotTbl.slotName)
974+
if item.base then
975+
self.itemsTab:CopyAnointsAndAugments(item, true, true, context.slotTbl.slotName)
976+
end
975977
items[i].item_string = item:BuildRaw()
976978
end
977979
elseif self.tradeQueryGenerator.lastAugmentBehaviour == "Remove" then

src/Classes/TradeQueryGenerator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ for type, bases in pairs(data.itemBaseLists) do
8181
end
8282
end
8383

84-
local tradeStats = tradeHelpers.getTradeStats()
8584

8685
---@return table[]? category list of entries for the mod type
8786
local function getStatEntries(modType)
87+
local tradeStats = tradeHelpers.getTradeStats()
8888
local tradeStatCategoryIndices = {
8989
["Explicit"] = "explicit",
9090
["Implicit"] = "implicit",

src/Data/QueryMods.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22385,10 +22385,17 @@ return {
2238522385
},
2238622386
},
2238722387
["3759663284"] = {
22388+
<<<<<<< HEAD
2238822389
["Bow"] = {
2238922390
["max"] = 20,
2239022391
["min"] = 20,
2239122392
},
22393+
=======
22394+
["2HWeapon"] = {
22395+
["max"] = 20,
22396+
["min"] = 20,
22397+
},
22398+
>>>>>>> 44955925b (Defer loading of trade stat data and fix tests)
2239222399
["specialCaseData"] = {
2239322400
},
2239422401
["tradeMod"] = {
@@ -22528,10 +22535,17 @@ return {
2252822535
},
2252922536
},
2253022537
["3885405204"] = {
22538+
<<<<<<< HEAD
2253122539
["Bow"] = {
2253222540
["max"] = 1,
2253322541
["min"] = 1,
2253422542
},
22543+
=======
22544+
["2HWeapon"] = {
22545+
["max"] = 1,
22546+
["min"] = 1,
22547+
},
22548+
>>>>>>> 44955925b (Defer loading of trade stat data and fix tests)
2253522549
["specialCaseData"] = {
2253622550
["overrideModLineSingular"] = "Bow Attacks fire an additional Arrow",
2253722551
},

0 commit comments

Comments
 (0)