|
|
|
|
@ -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 |
|
|
|
|
end |
|
|
|
|
|