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 local data
function accessor.data() function accessor.data()
if not data then if not data then
local dataset = persistence.load_dataset() local dataset = persistence.dataset
dataset.history = dataset.history or t data = dataset.history or t
data = dataset.history dataset.history = data
end end
return data return data
end end
@@ -56,10 +56,14 @@ function public.process_auction(auction_record)
local item_record = read_record(auction_record.item_key) local item_record = read_record(auction_record.item_key)
local unit_bid_price = ceil(auction_record.bid_price / auction_record.aux_quantity) 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) local unit_buyout_price = ceil(auction_record.buyout_price / auction_record.aux_quantity)
if auction_record.buyout_price > 0 then local max_unit_price = max(unit_buyout_price, unit_bid_price)
item_record.daily_min_buyout = item_record.daily_min_buyout and min(item_record.daily_min_buyout, unit_buyout_price) or unit_buyout_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 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) write_record(auction_record.item_key, item_record)
end end
@@ -100,13 +104,9 @@ function calculate_market_value(item_record)
end end
function weighted_median(list) function weighted_median(list)
local sorted_list = tt sort(list, function(a,b) return a.value < b.value end)
for _, e in list do
tinsert(sorted_list, e)
end
sort(sorted_list, function(a,b) return a.value < b.value end)
local weight = 0 local weight = 0
for _, element in sorted_list do for _, element in list do
weight = weight + element.weight weight = weight + element.weight
if weight >= .5 then if weight >= .5 then
return element.value return element.value
@@ -121,7 +121,5 @@ function push_record(item_record)
tremove(item_record.data_points) tremove(item_record.data_points)
end end
end end
item_record.daily_min_buyout = nil item_record.next_push, item_record.daily_min_buyout, item_record.daily_max_price = next_push, nil, nil
item_record.daily_max_price = nil
item_record.next_push = next_push
end end
+9 -14
View File
@@ -3,20 +3,15 @@ module 'persistence'
_g.aux_datasets = t _g.aux_datasets = t
do do
local realm, faction local dataset
function public.accessor.dataset()
function LOAD() if not dataset then
thread(when, function() faction = UnitFactionGroup 'player' return faction end, function() end) local dataset_key = format('%s|%s', GetCVar 'realmName', UnitFactionGroup 'player')
realm = GetCVar 'realmName' dataset = _g.aux_datasets[dataset_key] or t
end _g.aux_datasets[dataset_key] = dataset
end
function accessor.dataset_key() return realm..'|'..faction end return dataset
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]
end end
--do TODO syntactic sugar record '#' {key='string'} {foo='number'} --do TODO syntactic sugar record '#' {key='string'} {foo='number'}