lots of polish for the stat modules but the interface is still clumsy

This commit is contained in:
Manuel Simon Hirsig
2016-01-17 10:15:46 +01:00
parent 9c520df47c
commit 4ea7aaeb6f
4 changed files with 36 additions and 122 deletions
+14 -11
View File
@@ -34,7 +34,7 @@ function Aux_OnLoad()
local item_id, suffix_id = EnhTooltip.BreakLink(link)
local item_key = item_id..':'..suffix_id
local auction_count = unpack(Aux.stat_average.read_record(item_key))
local auction_count, seen_days, daily_average, EMA3, EMA7, EMA14 = Aux.stat_average.get_price_data(item_key)
if auction_count == 0 then
EnhTooltip.AddLine('Never seen at auction', nil, true)
@@ -43,20 +43,23 @@ function Aux_OnLoad()
EnhTooltip.AddLine('Seen '..auction_count..' '..Aux_PluralizeIf('time', auction_count)..' at auction', nil, true)
EnhTooltip.LineColor(0.5, 0.8, 0.1)
local unit_value = Aux.stat_average.get_mean(item_key)
local median = Aux.stat_histogram.get_price_data(item_key)
if count == 1 then
EnhTooltip.AddLine('AVG: '..Aux.util.money_string(unit_value), nil, true)
EnhTooltip.AddLine('Median: '..Aux.util.money_string(median), nil, true)
else
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)
EnhTooltip.AddLine('Median: '..Aux.util.money_string(median * count)..' ('..Aux.util.money_string(median)..' ea.)', nil, true)
end
EnhTooltip.LineColor(0.1,0.8,0.5)
-- EnhTooltip.AddLine('AVG TDA: '..(daily_average > 0 and Aux.util.money_string(daily_average) or RED_FONT_COLOR_CODE..'n/a'..FONT_COLOR_CODE_CLOSE), nil, true)
-- EnhTooltip.LineColor(0.1,0.8,0.5)
-- EnhTooltip.AddLine('EMA3: '..(EMA3 > 0 and Aux.util.money_string(EMA3) or RED_FONT_COLOR_CODE..'n/a'..FONT_COLOR_CODE_CLOSE), nil, true)
-- EnhTooltip.LineColor(0.1,0.8,0.5)
-- EnhTooltip.AddLine('EMA7: '..(EMA7 > 0 and Aux.util.money_string(EMA7) or RED_FONT_COLOR_CODE..'n/a'..FONT_COLOR_CODE_CLOSE), nil, true)
-- EnhTooltip.LineColor(0.1,0.8,0.5)
-- EnhTooltip.AddLine('EMA14: '..(EMA14 > 0 and Aux.util.money_string(EMA14) or RED_FONT_COLOR_CODE..'n/a'..FONT_COLOR_CODE_CLOSE), nil, true)
-- EnhTooltip.LineColor(0.1,0.8,0.5)
end
end)
end
+2 -2
View File
@@ -31,12 +31,12 @@ function public.start_scan()
private.process_auction(auction_info)
end,
on_complete = function()
Aux.log('Scan complete: Old auctions were removed from the snapshot.')
Aux.log('Scan complete.')
-- AuxHistoryStopButton:Hide()
-- AuxHistoryScanButton:Show()
end,
on_abort = function()
Aux.log('Scanning aborted.')
Aux.log('Scan aborted.')
-- AuxHistoryStopButton:Hide()
-- AuxHistoryScanButton:Show()
end,
+17 -106
View File
@@ -2,7 +2,7 @@ local private, public = {}, {}
Aux.stat_average = public
private.PUSH_INTERVAL = 57600
private.NEW_RECORD = '0:0:0:0:0:0:0:0:0:0'
private.NEW_RECORD = '0:0:0:0:0:0:0:0'
function private.load_data()
local dataset = Aux.persistence.load_dataset()
@@ -34,93 +34,21 @@ function public.process_auction(auction_info)
private.push_data()
end
local buyout = auction_info.buyout_price / auction_info.count
local item_record = public.read_record(auction_info.item_key)
item_record[1] = item_record[1] + 1 -- auction count
item_record[2] = item_record[2] + 1 -- daily auction count
item_record[3] = item_record[3] + auction_info.count -- daily unit count
item_record[4] = item_record[4] + auction_info.buyout_price -- daily accumulated buyout
item_record[5] = item_record[5] ~= 0 and min(item_record[4], auction_info.buyout_price / auction_info.count) or auction_info.buyout_price / auction_info.count -- daily min buyout
item_record[3] = item_record[3] + buyout -- daily accumulated buyout
private.write_record(auction_info.item_key, item_record)
end
function public.get_mean(item_key)
local auction_count, daily_auction_count, daily_unit_count, daily_accumulated_buyout, daily_min_buyout, seen_days, EMA3, EMA7, EMA14, average_min_buyout = unpack(public.read_record(item_key))
local mean = 0
if seen_days == 0 then
if daily_auction_count > 0 then
mean = daily_accumulated_buyout / daily_unit_count
end
elseif seen_days <= 3 then -- No EMAs before day 4
mean = EMA3
if daily_auction_count > 0 then
mean = (mean * seen_days + daily_accumulated_buyout / daily_unit_count) / (seen_days + 1)
end
else
-- we have 4 or more days of data, potentially enough to perform mean and stddev calculations
local count = 0
local valueset, weightset = {}, {}
-- include daily data if available
if daily_auction_count > 0 then
count = 1
valueset[count] = daily_accumulated_buyout / daily_unit_count
weightset[count] = 1
end
-- EMA3: standard weight 3, reduced if seenDays < 6, reduced if there was daily data, but never less than 1
local weight = 3 - count
if seen_days < 6 then
weight = seen_days - 3
if weight > 1 then
weight = weight - count
end
end
count = count + 1
valueset[count] = EMA3
weightset[count] = weight
-- EMA7: standard weight 4, reduced if seenDays < 10
if seen_days > 6 then
count = count + 1
valueset[count] = EMA7
if seen_days < 10 then
weightset[count] = seen_days - 6
else
weightset[count] = 4
end
end
-- EMA14: standard weight 7, reduced if seenDays < 17
if seen_days > 10 then
count = count + 1
valueset[count] = EMA14
if seen_days < 17 then
weightset[count] = seen_days - 10
else
weightset[count] = 7
end
end
-- we will use a weighted incremental algorithm, based on sample code by West and Knuth http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
local sumWeight, sumSquares = 0, 0 -- actually "sum of squares of differences from the (current) mean", but that's rather long for a variable name.
for i=1,count do
local value, weight = valueset[i], weightset[i]
local nextweight = weight + sumWeight
local valuediff = value - mean
local meanadjust = valuediff * weight / nextweight
mean = mean + meanadjust
sumSquares = sumSquares + sumWeight * valuediff * meanadjust
sumWeight = nextweight
end
-- stddev = sqrt(sumSquares / sumWeight * count / (count - 1))
end
return mean
function public.get_price_data(item_key)
local auction_count, daily_auction_count, daily_accumulated_buyout, seen_days, EMA3, EMA7, EMA14 = unpack(public.read_record(item_key))
local daily_average = daily_accumulated_buyout / daily_auction_count
return auction_count, seen_days, daily_average, EMA3, EMA7, EMA14
end
function private.push_data()
@@ -130,16 +58,15 @@ function private.push_data()
for item_key, _ in pairs(item_data) do
local item_record = public.read_record(item_key)
local _, daily_auction_count, daily_unit_count, daily_accumulated_buyout, daily_min_buyout, seen_days, EMA3, EMA7, EMA14, average_min_buyout = unpack(item_record)
local _, daily_auction_count, daily_accumulated_buyout, seen_days, EMA3, EMA7, EMA14 = unpack(item_record)
if daily_auction_count > 0 then
local daily_average = daily_accumulated_buyout / daily_unit_count
local daily_average = daily_accumulated_buyout / daily_auction_count
if seen_days < 3 then
-- for first 3 days perform plain average instead of EMAs
EMA3 = (EMA3 * seen_days + daily_average) / (seen_days + 1)
average_min_buyout = (average_min_buyout * seen_days + daily_min_buyout) / (seen_days + 1)
EMA7 = EMA3
EMA14 = EMA3
else
@@ -147,34 +74,18 @@ function private.push_data()
EMA3 = (EMA3 * 2 + daily_average) / 3
EMA7 = (EMA7 * 6 + daily_average) / 7
EMA14 = (EMA14 * 13 + daily_average) / 14
if daily_min_buyout / average_min_buyout < 0.9 then
average_min_buyout = (average_min_buyout + daily_min_buyout) / 2
else
average_min_buyout = (average_min_buyout * 7 + daily_min_buyout) / 8
end
end
seen_days = seen_days + 1
daily_auction_count = 0
daily_unit_count = 0
daily_accumulated_buyout = 0
daily_min_buyout = 0
item_record[2] = daily_auction_count
item_record[3] = daily_unit_count
item_record[4] = daily_accumulated_buyout
item_record[5] = daily_min_buyout
item_record[6] = seen_days
item_record[7] = EMA3
item_record[8] = EMA7
item_record[9] = EMA14
item_record[10] = average_min_buyout
item_record[2] = 0 -- daily auction count
item_record[3] = 0 -- daily accumulated buyout
item_record[4] = seen_days + 1 -- seen days
item_record[5] = EMA3 -- EMA3
item_record[6] = EMA7 -- EMA7
item_record[7] = EMA14 -- EMA14
private.write_record(item_key, item_record)
end
end
data.next_push = time() + private.PUSH_INTERVAL
end
end
+3 -3
View File
@@ -91,15 +91,15 @@ function public.get_price_data(item_key)
if private.current_record.step > median / 85 and private.current_record.step > 1 then
private.refactor(median * 3, 300)
private.write_current_record()
return private.GetPriceData()
return public.get_price_data(item_key)
elseif private.current_record.step < median / 115 then
private.refactor(median * 3, 300)
private.write_current_record()
return private.GetPriceData()
return public.get_price_data(item_key)
end
end
return median, Q1, Q3, private.current_record.step, percent40, percent30, private.current_record.count
return median, Q1, Q3, percent30, percent40, private.current_record.count, private.current_record.step
end
function public.process_auction(auction_info)