diff --git a/TradeSkillMaster_AuctionDB/Modules/data.lua b/TradeSkillMaster_AuctionDB/Modules/data.lua index b1d350b..3a975cc 100644 --- a/TradeSkillMaster_AuctionDB/Modules/data.lua +++ b/TradeSkillMaster_AuctionDB/Modules/data.lua @@ -130,15 +130,58 @@ function Data:GetMarketValue(scans) return totalWeight > 0 and floor(totalAmount / totalWeight + 0.5) or 0 end +function Data:ProcessExternalScanData(scanData, groupItems, scanTime) + if type(scanData) ~= "table" then return end + + local data = {} + local groupSet = {} + if type(groupItems) == "table" then + if #groupItems > 0 then + for _, itemString in ipairs(groupItems) do + groupSet[itemString] = true + end + else + for itemString in pairs(groupItems) do + groupSet[itemString] = true + end + end + end + for itemString, obj in pairs(scanData) do + if TSMAPI:GetBaseItemString(itemString) == itemString then + local itemID = obj:GetItemID() + local quantity, minBuyout = 0, 0 + local records = {} + for _, record in ipairs(obj.records) do + if record.buyout and record.buyout > 0 then + local itemBuyout = record:GetItemBuyout() + if itemBuyout then + if (itemBuyout < minBuyout or minBuyout == 0) then + minBuyout = itemBuyout + end + quantity = quantity + record.count + tinsert(records, {record.count, itemBuyout}) + end + end + end + data[itemID] = {records=records, minBuyout=minBuyout, quantity=quantity} + groupSet[itemString] = true + end + end + + if not next(data) then return end + Data:ProcessData(data, groupSet, nil, scanTime or time()) +end + --- Process a table of new market scan data. -- @param scanData The market scan data. -- @param[opt] groupItems Affects how the minBuyout data is wiped. Use nil for regular behavior. -- @param[opt] verifyNewAlgorithm Boolean 'true' if you want to benchmark and verify the new market value algorithm. -function Data:ProcessData(scanData, groupItems, verifyNewAlgorithm) +-- @param[opt] scanTime Unix time to use for lastScan values. +function Data:ProcessData(scanData, groupItems, verifyNewAlgorithm, scanTime) -- If we're currently processing data, retry in 0.2 seconds. -- NOTE: This will retry itself over and over until it's able to process. if TSM.processingData then - return TSMAPI:CreateTimeDelay(0.2, function() Data:ProcessData(scanData, groupItems, verifyNewAlgorithm) end) + return TSMAPI:CreateTimeDelay(0.2, function() Data:ProcessData(scanData, groupItems, verifyNewAlgorithm, scanTime) end) end @@ -184,6 +227,7 @@ function Data:ProcessData(scanData, groupItems, verifyNewAlgorithm) -- pausing between each chunk to allow the game client to avoid freezing. local index = 1 local day = Data:GetDay() + local scanTimestamp = scanTime or TSM.db.realm.lastCompleteScan local function DoDataProcessing() for i = 1, 500 do -- Abort if we've reached the end of the processing queue. @@ -316,7 +360,7 @@ function Data:ProcessData(scanData, groupItems, verifyNewAlgorithm) -- item contains a "greater than 0" buyout value. That was mostly -- necessary in the past, when TSM sloppily included bid-only items -- in the data, but should no longer be able to happen with our new code! - TSM.data[itemID].lastScan = TSM.db.realm.lastCompleteScan + TSM.data[itemID].lastScan = scanTimestamp TSM.data[itemID].minBuyout = data.minBuyout > 0 and data.minBuyout or nil TSM.data[itemID].quantity = data.quantity -- Counts all items of all stacks. Data:UpdateMarketValue(TSM.data[itemID]) @@ -666,4 +710,4 @@ function Data:CalculateMarketValue(data, hide_oldschool_warning) return corrected_mean end -end \ No newline at end of file +end diff --git a/TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua b/TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua index 275f657..721b716 100644 --- a/TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua +++ b/TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua @@ -75,6 +75,7 @@ function TSM:RegisterModule() { key = "lastCompleteScan", callback = TSM.GetLastCompleteScan }, { key = "lastCompleteScanTime", callback = TSM.GetLastCompleteScanTime }, { key = "adbScans", callback = TSM.GetScans }, + { key = "processScanData", callback = "Data:ProcessExternalScanData" }, --{ key = "adbOppositeFaction", callback = TSM.GetOppositeFactionData }, } TSM.tooltipOptions = {callback = "Config:LoadTooltipOptions"} @@ -563,4 +564,4 @@ function TSM:GetMinBuyout(itemID) if not itemID or not TSM.data[itemID] then return end TSM:DecodeItemData(itemID) return TSM.data[itemID].minBuyout -end \ No newline at end of file +end diff --git a/TradeSkillMaster_Shopping/modules/Util.lua b/TradeSkillMaster_Shopping/modules/Util.lua index 680dc66..8a73332 100644 --- a/TradeSkillMaster_Shopping/modules/Util.lua +++ b/TradeSkillMaster_Shopping/modules/Util.lua @@ -231,6 +231,10 @@ function private.ScanCallback(event, ...) elseif event == "SCAN_COMPLETE" then if not private.filterList or not private.filterList[1] then return end -- protect against sniper scan starts causing issues local data = ... + local groupItems = private.filterList[1].items + if not private.isLastPageScan then + TSMAPI:ModuleAPI("AuctionDB", "processScanData", data, groupItems, time()) + end if private.filterList[1].items then for _, itemString in ipairs(private.filterList[1].items) do if data[itemString] then @@ -511,4 +515,4 @@ function private:AddPostedAuction(postInfo) private.auctions[postInfo.itemString]:PopulateCompactRecords() private:UpdateRT() private.searchFrame.rt:SetSelectedAuction() -end \ No newline at end of file +end