refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-23 16:33:58 +02:00
parent f26f966d5e
commit 303ef7f9c3
2 changed files with 22 additions and 29 deletions
+13 -15
View File
@@ -14,9 +14,9 @@ do
local data
function accessor.data()
if not data then
local dataset = persistence.load_dataset()
dataset.history = dataset.history or t
data = dataset.history
local dataset = persistence.dataset
data = dataset.history or t
dataset.history = data
end
return data
end
@@ -56,10 +56,14 @@ function public.process_auction(auction_record)
local item_record = read_record(auction_record.item_key)
local unit_bid_price = ceil(auction_record.bid_price / auction_record.aux_quantity)
local unit_buyout_price = ceil(auction_record.buyout_price / auction_record.aux_quantity)
if auction_record.buyout_price > 0 then
item_record.daily_min_buyout = item_record.daily_min_buyout and min(item_record.daily_min_buyout, unit_buyout_price) or unit_buyout_price
local max_unit_price = max(unit_buyout_price, unit_bid_price)
if unit_buyout_price > 0 and unit_buyout_price < (item_record.daily_min_buyout or huge) then
item_record.daily_min_buyout = unit_buyout_price
elseif max_unit_price > item_record.daily_max_price or 0 then
item_record.daily_max_price = max_unit_price
else
return
end
item_record.daily_max_price = max(item_record.daily_max_price or 0, unit_buyout_price, unit_bid_price)
write_record(auction_record.item_key, item_record)
end
@@ -100,13 +104,9 @@ function calculate_market_value(item_record)
end
function weighted_median(list)
local sorted_list = tt
for _, e in list do
tinsert(sorted_list, e)
end
sort(sorted_list, function(a,b) return a.value < b.value end)
sort(list, function(a,b) return a.value < b.value end)
local weight = 0
for _, element in sorted_list do
for _, element in list do
weight = weight + element.weight
if weight >= .5 then
return element.value
@@ -121,7 +121,5 @@ function push_record(item_record)
tremove(item_record.data_points)
end
end
item_record.daily_min_buyout = nil
item_record.daily_max_price = nil
item_record.next_push = next_push
item_record.next_push, item_record.daily_min_buyout, item_record.daily_max_price = next_push, nil, nil
end
+9 -14
View File
@@ -3,20 +3,15 @@ module 'persistence'
_g.aux_datasets = t
do
local realm, faction
function LOAD()
thread(when, function() faction = UnitFactionGroup 'player' return faction end, function() end)
realm = GetCVar 'realmName'
end
function accessor.dataset_key() return realm..'|'..faction end
end
function public.load_dataset()
local dataset_key = dataset_key
_g.aux_datasets[dataset_key] = _g.aux_datasets[dataset_key] or t
return _g.aux_datasets[dataset_key]
local dataset
function public.accessor.dataset()
if not dataset then
local dataset_key = format('%s|%s', GetCVar 'realmName', UnitFactionGroup 'player')
dataset = _g.aux_datasets[dataset_key] or t
_g.aux_datasets[dataset_key] = dataset
end
return dataset
end
end
--do TODO syntactic sugar record '#' {key='string'} {foo='number'}