made historical median time-weighted
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
Aux = {
|
Aux = {
|
||||||
version = '2.6.18',
|
version = '2.6.19',
|
||||||
blizzard_ui_shown = false,
|
blizzard_ui_shown = false,
|
||||||
orig = {},
|
orig = {},
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-19
@@ -83,15 +83,19 @@ function public.value(item_key)
|
|||||||
if not private.value_cache[item_key] then
|
if not private.value_cache[item_key] then
|
||||||
local item_record = private.read_record(item_key)
|
local item_record = private.read_record(item_key)
|
||||||
|
|
||||||
local i = 1
|
if getn(item_record.data_points) > 0 then
|
||||||
local median_list = {}
|
local weighted_values = {}
|
||||||
while getn(median_list) <= 11 and i <= getn(item_record.data_points) do
|
local total_weight = 0
|
||||||
tinsert(median_list, item_record.data_points[i].market_value)
|
for _, data_point in item_record.data_points do
|
||||||
i = i + 1
|
local weight = 0.95^Aux.round((data_point.time - item_record.data_points[1].time)/(60*60*24))
|
||||||
end
|
total_weight = total_weight + weight
|
||||||
|
tinsert(weighted_values, {value = data_point.market_value, weight = weight})
|
||||||
|
end
|
||||||
|
for _, weighted_value in weighted_values do
|
||||||
|
weighted_value.weight = weighted_value.weight / total_weight
|
||||||
|
end
|
||||||
|
|
||||||
if getn(median_list) > 0 then
|
private.value_cache[item_key] = private.weighted_median(weighted_values)
|
||||||
private.value_cache[item_key] = private.median(median_list)
|
|
||||||
else
|
else
|
||||||
private.value_cache[item_key] = private.market_value(item_record)
|
private.value_cache[item_key] = private.market_value(item_record)
|
||||||
end
|
end
|
||||||
@@ -109,19 +113,20 @@ function private.market_value(item_record)
|
|||||||
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
return item_record.daily_min_buyout and min(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_price)
|
||||||
end
|
end
|
||||||
|
|
||||||
function private.median(list)
|
function private.weighted_median(list)
|
||||||
if getn(list) == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local sorted_list = {}
|
local sorted_list = {}
|
||||||
for _, v in ipairs(list) do
|
for _, e in list do
|
||||||
tinsert(sorted_list, v)
|
tinsert(sorted_list, e)
|
||||||
end
|
end
|
||||||
sort(sorted_list)
|
sort(sorted_list, function(a,b) return a.value < b.value end)
|
||||||
|
|
||||||
local middle = (getn(sorted_list) + 1) / 2
|
local weight = 0
|
||||||
return (sorted_list[floor(middle)] + sorted_list[ceil(middle)]) / 2
|
for _, element in sorted_list do
|
||||||
|
weight = weight + element.weight
|
||||||
|
if weight >= 0.5 then
|
||||||
|
return element.value
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function private.push_record(item_record)
|
function private.push_record(item_record)
|
||||||
@@ -129,7 +134,7 @@ function private.push_record(item_record)
|
|||||||
local market_value = private.market_value(item_record)
|
local market_value = private.market_value(item_record)
|
||||||
if market_value then
|
if market_value then
|
||||||
tinsert(item_record.data_points, 1, { market_value = market_value, time = item_record.next_push })
|
tinsert(item_record.data_points, 1, { market_value = market_value, time = item_record.next_push })
|
||||||
while getn(item_record.data_points) > 31 do
|
while getn(item_record.data_points) > 11 do
|
||||||
tremove(item_record.data_points)
|
tremove(item_record.data_points)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user