added notion of expiration to snapshot. Full scan to trim the snapshot is no longer needed
This commit is contained in:
@@ -45,9 +45,16 @@ function Aux_OnLoad()
|
||||
|
||||
local unit_value = Aux.stat_average.get_mean(item_key)
|
||||
if count == 1 then
|
||||
EnhTooltip.AddLine(Aux.util.money_string(unit_value), nil, true)
|
||||
EnhTooltip.AddLine('AVG: '..Aux.util.money_string(unit_value), nil, true)
|
||||
else
|
||||
EnhTooltip.AddLine(Aux.util.money_string(unit_value * count)..' ('..Aux.util.money_string(unit_value)..' ea.)', nil, true)
|
||||
EnhTooltip.AddLine('AVG: '..Aux.util.money_string(unit_value * count)..' ('..Aux.util.money_string(unit_value)..' ea.)', nil, true)
|
||||
end
|
||||
EnhTooltip.LineColor(0.1,0.8,0.5)
|
||||
local unit_value = Aux.stat_histogram.get_price_data(item_key)
|
||||
if count == 1 then
|
||||
EnhTooltip.AddLine('Median: '..Aux.util.money_string(unit_value), nil, true)
|
||||
else
|
||||
EnhTooltip.AddLine('Median: '..Aux.util.money_string(unit_value * count)..' ('..Aux.util.money_string(unit_value)..' ea.)', nil, true)
|
||||
end
|
||||
EnhTooltip.LineColor(0.1,0.8,0.5)
|
||||
end
|
||||
|
||||
+36
-2
@@ -36,8 +36,7 @@ end
|
||||
function public.load_snapshot()
|
||||
local dataset = public.load_dataset()
|
||||
dataset.snapshot = dataset.snapshot or {}
|
||||
local snapshot = Aux.util.set()
|
||||
snapshot.set_data(dataset.snapshot)
|
||||
local snapshot = private.snapshot(dataset.snapshot)
|
||||
return snapshot
|
||||
end
|
||||
|
||||
@@ -89,3 +88,38 @@ function public.deserialize(data_string, separator)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.snapshot(data)
|
||||
local self = {}
|
||||
|
||||
function self.add(signature, duration)
|
||||
local HOUR = 60 * 60 * 60
|
||||
local seconds
|
||||
if duration == 1 then
|
||||
seconds = HOUR / 2
|
||||
elseif duration == 2 then
|
||||
seconds = HOUR * 2
|
||||
elseif duration == 3 then
|
||||
seconds = HOUR * 8
|
||||
elseif duration == 4 then
|
||||
seconds = HOUR * 24
|
||||
end
|
||||
data[signature] = time() + seconds
|
||||
end
|
||||
|
||||
function self.contains(signature)
|
||||
return data[signature] ~= nil and data[signature] >= time()
|
||||
end
|
||||
|
||||
function self.signatures()
|
||||
local signatures = {}
|
||||
for signature, _ in pairs(data) do
|
||||
if data[signature] >= time() then
|
||||
tinsert(signatures, signature)
|
||||
end
|
||||
end
|
||||
return signatures
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -149,8 +149,9 @@ function scan_auctions_helper(i, n, k)
|
||||
|
||||
local snapshot = Aux.persistence.load_snapshot()
|
||||
if not snapshot.contains(auction_info.signature) then
|
||||
snapshot.add(auction_info.signature)
|
||||
snapshot.add(auction_info.signature, auction_info.duration)
|
||||
Aux.stat_average.process_auction(auction_info)
|
||||
Aux.stat_histogram.process_auction(auction_info)
|
||||
end
|
||||
else
|
||||
recurse()
|
||||
|
||||
@@ -31,13 +31,11 @@ function public.start_scan()
|
||||
private.process_auction(auction_info)
|
||||
end,
|
||||
on_complete = function()
|
||||
private.update_snapshot()
|
||||
Aux.log('Scan complete: Old auctions were removed from the snapshot.')
|
||||
-- AuxHistoryStopButton:Hide()
|
||||
-- AuxHistoryScanButton:Show()
|
||||
end,
|
||||
on_abort = function()
|
||||
|
||||
Aux.log('Scanning aborted.')
|
||||
-- AuxHistoryStopButton:Hide()
|
||||
-- AuxHistoryScanButton:Show()
|
||||
@@ -55,15 +53,6 @@ function public.stop_scan()
|
||||
Aux.scan.abort()
|
||||
end
|
||||
|
||||
function private.update_snapshot()
|
||||
local snapshot = Aux.persistence.load_snapshot()
|
||||
for _, sig in ipairs(snapshot.values()) do
|
||||
if not private.scanned_signatures.contains(sig) then
|
||||
snapshot.remove(sig)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.process_auction(auction_info)
|
||||
private.scanned_signatures.add(auction_info.signature)
|
||||
end
|
||||
|
||||
+32
-17
@@ -1,7 +1,7 @@
|
||||
local private, public = {}, {}
|
||||
Aux.stat_histogram = public
|
||||
|
||||
private.NEW_RECORD = '0:0:0:0'
|
||||
private.NEW_RECORD = '0:0:0:0:'
|
||||
|
||||
function private.load_data()
|
||||
local dataset = Aux.persistence.load_dataset()
|
||||
@@ -19,11 +19,10 @@ function private.read_current_record(item_key)
|
||||
step = tonumber(record[3]),
|
||||
count = tonumber(record[4]),
|
||||
}
|
||||
local values = Aux.persistence.deserialize(record[5], ',')
|
||||
for i, value in ipairs(values) do
|
||||
values[i] = tonumber(value)
|
||||
private.current_record.values = {}
|
||||
for i=5, getn(record) do
|
||||
private.current_record.values[private.current_record.min - 5 + i] = tonumber(record[i])
|
||||
end
|
||||
private.current_record.values = values
|
||||
private.current_item_key = item_key
|
||||
end
|
||||
end
|
||||
@@ -31,21 +30,26 @@ end
|
||||
function private.write_current_record()
|
||||
local data = private.load_data()
|
||||
|
||||
local values = {}
|
||||
for i=private.current_record.min,private.current_record.max do
|
||||
tinsert(values, private.current_record.values[i])
|
||||
end
|
||||
|
||||
data.item_data[private.current_item_key] = Aux.persistence.serialize({
|
||||
private.current_record.min,
|
||||
private.current_record.max,
|
||||
private.current_record.step,
|
||||
private.current_record.count,
|
||||
Aux.persistence.serialize(private.current_record.values, ','),
|
||||
Aux.persistence.serialize(values, ':'),
|
||||
}, ':')
|
||||
end
|
||||
|
||||
function public.GetPriceData(item_key)
|
||||
function public.get_price_data(item_key)
|
||||
private.read_current_record(item_key)
|
||||
|
||||
local median = 0
|
||||
local Qone = 0
|
||||
local Qthree = 0
|
||||
local Q1 = 0
|
||||
local Q3 = 0
|
||||
local percent40 = 0
|
||||
local percent30 = 0
|
||||
local recount = 0
|
||||
@@ -55,9 +59,9 @@ function public.GetPriceData(item_key)
|
||||
else
|
||||
for i = private.current_record.min, private.current_record.max do
|
||||
recount = recount + private.current_record.values[i]
|
||||
if Qone == 0 and private.current_record.count > 4 then -- Q1 is meaningless with very little data
|
||||
if Q1 == 0 and private.current_record.count > 4 then -- Q1 is meaningless with very little data
|
||||
if recount >= private.current_record.count / 4 then
|
||||
Qone = i * private.current_record.step
|
||||
Q1 = i * private.current_record.step
|
||||
end
|
||||
end
|
||||
if percent30 == 0 then
|
||||
@@ -75,9 +79,9 @@ function public.GetPriceData(item_key)
|
||||
median = i * private.current_record.step
|
||||
end
|
||||
end
|
||||
if Qthree == 0 and private.current_record.count > 4 then -- Q3 is meaningless with very little data
|
||||
if Q3 == 0 and private.current_record.count > 4 then -- Q3 is meaningless with very little data
|
||||
if recount >= private.current_record.count * 3 / 4 then
|
||||
Qthree = i * private.current_record.step
|
||||
Q3 = i * private.current_record.step
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -95,7 +99,7 @@ function public.GetPriceData(item_key)
|
||||
end
|
||||
end
|
||||
|
||||
return median, Qone, Qthree, private.current_record.step, percent40, percent30, private.current_record.count
|
||||
return median, Q1, Q3, private.current_record.step, percent40, percent30, private.current_record.count
|
||||
end
|
||||
|
||||
function public.process_auction(auction_info)
|
||||
@@ -121,7 +125,7 @@ function public.process_auction(auction_info)
|
||||
index = 100
|
||||
end
|
||||
|
||||
if not private.current_record.min then
|
||||
if private.current_record.min == 0 then
|
||||
private.current_record.min = index
|
||||
private.current_record.max = index
|
||||
private.current_record.values[index] = 0
|
||||
@@ -130,12 +134,17 @@ function public.process_auction(auction_info)
|
||||
private.current_record.values[i] = 0
|
||||
end
|
||||
private.current_record.min = index
|
||||
elseif private.current_record.max < index then
|
||||
for i = private.current_record.max + 1, index do
|
||||
private.current_record.values[i] = 0
|
||||
end
|
||||
private.current_record.max = index
|
||||
end
|
||||
|
||||
private.current_record.values[index] = private.current_record.values[index] + 1
|
||||
private.current_record.count = private.current_record.count + 1
|
||||
|
||||
private.write_record()
|
||||
private.write_current_record()
|
||||
|
||||
elseif index <= 300 then
|
||||
|
||||
@@ -158,7 +167,7 @@ function public.process_auction(auction_info)
|
||||
private.current_record.values[index] = private.current_record.values[index] + 1
|
||||
private.current_record.count = private.current_record.count + 1
|
||||
|
||||
private.write_record()
|
||||
private.write_current_record()
|
||||
|
||||
end
|
||||
end
|
||||
@@ -166,6 +175,12 @@ end
|
||||
function private.refactor(pmax, precision)
|
||||
|
||||
local new_step = ceil(pmax / precision)
|
||||
|
||||
if getn(private.current_record.values) == 0 then
|
||||
private.current_record.step = new_step
|
||||
return
|
||||
end
|
||||
|
||||
local conversion = private.current_record.step / new_step
|
||||
local new_min = ceil(conversion * private.current_record.min)
|
||||
local new_max = ceil(conversion * private.current_record.max)
|
||||
|
||||
Reference in New Issue
Block a user