Browse Source

attempt to update scan data on searches

no-attributes-dev
parent
commit
1a80d3f148
  1. 52
      TradeSkillMaster_AuctionDB/Modules/data.lua
  2. 3
      TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua
  3. 6
      TradeSkillMaster_Shopping/modules/Util.lua

52
TradeSkillMaster_AuctionDB/Modules/data.lua

@ -130,15 +130,58 @@ function Data:GetMarketValue(scans)
return totalWeight > 0 and floor(totalAmount / totalWeight + 0.5) or 0 return totalWeight > 0 and floor(totalAmount / totalWeight + 0.5) or 0
end 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. --- Process a table of new market scan data.
-- @param scanData The 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] 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. -- @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. -- 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. -- NOTE: This will retry itself over and over until it's able to process.
if TSM.processingData then 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 end
@ -184,6 +227,7 @@ function Data:ProcessData(scanData, groupItems, verifyNewAlgorithm)
-- pausing between each chunk to allow the game client to avoid freezing. -- pausing between each chunk to allow the game client to avoid freezing.
local index = 1 local index = 1
local day = Data:GetDay() local day = Data:GetDay()
local scanTimestamp = scanTime or TSM.db.realm.lastCompleteScan
local function DoDataProcessing() local function DoDataProcessing()
for i = 1, 500 do for i = 1, 500 do
-- Abort if we've reached the end of the processing queue. -- 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 -- item contains a "greater than 0" buyout value. That was mostly
-- necessary in the past, when TSM sloppily included bid-only items -- 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! -- 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].minBuyout = data.minBuyout > 0 and data.minBuyout or nil
TSM.data[itemID].quantity = data.quantity -- Counts all items of all stacks. TSM.data[itemID].quantity = data.quantity -- Counts all items of all stacks.
Data:UpdateMarketValue(TSM.data[itemID]) Data:UpdateMarketValue(TSM.data[itemID])
@ -666,4 +710,4 @@ function Data:CalculateMarketValue(data, hide_oldschool_warning)
return corrected_mean return corrected_mean
end end
end end

3
TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua

@ -75,6 +75,7 @@ function TSM:RegisterModule()
{ key = "lastCompleteScan", callback = TSM.GetLastCompleteScan }, { key = "lastCompleteScan", callback = TSM.GetLastCompleteScan },
{ key = "lastCompleteScanTime", callback = TSM.GetLastCompleteScanTime }, { key = "lastCompleteScanTime", callback = TSM.GetLastCompleteScanTime },
{ key = "adbScans", callback = TSM.GetScans }, { key = "adbScans", callback = TSM.GetScans },
{ key = "processScanData", callback = "Data:ProcessExternalScanData" },
--{ key = "adbOppositeFaction", callback = TSM.GetOppositeFactionData }, --{ key = "adbOppositeFaction", callback = TSM.GetOppositeFactionData },
} }
TSM.tooltipOptions = {callback = "Config:LoadTooltipOptions"} TSM.tooltipOptions = {callback = "Config:LoadTooltipOptions"}
@ -563,4 +564,4 @@ function TSM:GetMinBuyout(itemID)
if not itemID or not TSM.data[itemID] then return end if not itemID or not TSM.data[itemID] then return end
TSM:DecodeItemData(itemID) TSM:DecodeItemData(itemID)
return TSM.data[itemID].minBuyout return TSM.data[itemID].minBuyout
end end

6
TradeSkillMaster_Shopping/modules/Util.lua

@ -231,6 +231,10 @@ function private.ScanCallback(event, ...)
elseif event == "SCAN_COMPLETE" then elseif event == "SCAN_COMPLETE" then
if not private.filterList or not private.filterList[1] then return end -- protect against sniper scan starts causing issues if not private.filterList or not private.filterList[1] then return end -- protect against sniper scan starts causing issues
local data = ... 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 if private.filterList[1].items then
for _, itemString in ipairs(private.filterList[1].items) do for _, itemString in ipairs(private.filterList[1].items) do
if data[itemString] then if data[itemString] then
@ -511,4 +515,4 @@ function private:AddPostedAuction(postInfo)
private.auctions[postInfo.itemString]:PopulateCompactRecords() private.auctions[postInfo.itemString]:PopulateCompactRecords()
private:UpdateRT() private:UpdateRT()
private.searchFrame.rt:SetSelectedAuction() private.searchFrame.rt:SetSelectedAuction()
end end

Loading…
Cancel
Save