refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-23 12:45:23 +02:00
parent 99ba3e7fdc
commit deb85ad030
18 changed files with 169 additions and 152 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
module 'cache'
module 'cache' import 'info'
MIN_ITEM_ID = 1
MAX_ITEM_ID = 30000
@@ -148,7 +148,7 @@ function merchant_buy_scan()
end
function merchant_sell_scan()
for slot in inventory do
for slot in info.inventory do
local item_info = info.container_item(unpack(slot))
if item_info then
_g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity
+4 -4
View File
@@ -39,7 +39,7 @@ do
end
function LOAD()
ARMOR = set
ARMOR = -set
'INVTYPE_HEAD'
'INVTYPE_NECK'
'INVTYPE_SHOULDER'
@@ -55,7 +55,7 @@ function LOAD()
'INVTYPE_TRINKET'
'INVTYPE_CLOAK'
'INVTYPE_HOLDABLE'
WEAPON = set
WEAPON = -set
'INVTYPE_2HWEAPON'
'INVTYPE_WEAPONMAINHAND'
'INVTYPE_WEAPON'
@@ -80,7 +80,7 @@ end
function public.distribution(slot, quality, level)
if not (ARMOR[slot] or WEAPON[slot]) or level == 0 then
return tt
return t
end
local function p(probability_armor, probability_weapon)
@@ -191,5 +191,5 @@ function public.distribution(slot, quality, level)
return {{item_id=20725, min_quantity=1, max_quantity=2, probability=1}}
end
end
return tt
return t
end
+19 -14
View File
@@ -1,21 +1,27 @@
module 'history'
module 'history' import 'persistence'
--local history_schema = tuple('#')
-- :next_push 'number'
-- :daily_min_buyout 'number'
-- :daily_max_price 'number'
-- :data_points (list(';') (tuple('@') :market_value 'number' :time 'number'))
local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}}}
value_cache = {}
value_cache = t
function next_push()
local date = date('*t')
function accessor.next_push()
local date = date '*t'
date.hour, date.min, date.sec = 24, 0, 0
return time(date)
end
function new_record()
return { next_push = next_push(), data_points = {} }
return -object :next_push(next_push) :data_points(t)
end
function load_data()
local dataset = persistence.load_dataset()
dataset.history = dataset.history or {}
dataset.history = dataset.history or t
return dataset.history
end
@@ -69,23 +75,22 @@ function public.value(item_key)
local value
if getn(item_record.data_points) > 0 then
local weighted_values = {}
local weighted_values = tt
local total_weight = 0
for _, data_point in item_record.data_points do
local weight = 0.99^round((item_record.data_points[1].time - data_point.time) / (60*60*24))
local weight = 0.99^round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24))
total_weight = total_weight + weight
tinsert(weighted_values, {value = data_point.market_value, weight = weight})
tinsert(weighted_values, -object :value(data_point.market_value) :weight(weight))
end
for _, weighted_value in weighted_values do
weighted_value.weight = weighted_value.weight / total_weight
end
value = weighted_median(weighted_values)
else
value = calculate_market_value(item_record)
end
value_cache[item_key] = {value=value, next_push=item_record.next_push}
value_cache[item_key] = -object :value(value) :next_push(item_record.next_push)
end
return value_cache[item_key].value
@@ -101,7 +106,7 @@ function calculate_market_value(item_record)
end
function weighted_median(list)
local sorted_list = {}
local sorted_list = tt
for _, e in list do
tinsert(sorted_list, e)
end
@@ -120,7 +125,7 @@ function push_record(item_record)
local market_value = calculate_market_value(item_record)
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, -object :market_value(market_value) :time(item_record.next_push))
while getn(item_record.data_points) > 11 do
tremove(item_record.data_points)
end
@@ -128,5 +133,5 @@ function push_record(item_record)
item_record.daily_min_buyout = nil
item_record.daily_max_price = nil
item_record.next_push = next_push()
item_record.next_push = next_push
end
+6 -3
View File
@@ -1,4 +1,8 @@
module 'scan'
module 'scan' import 'info'
function LOAD()
import 'history'
end
PAGE_SIZE = 50
@@ -6,7 +10,7 @@ do
local scan_states = {}
function public.start(params)
for _, old_state in {scan_states[params.type]} do
for old_state in present(scan_states[params.type]) do
abort(old_state.id)
end
local thread_id = thread(L(wait_for_callback, params.on_scan_start, scan))
@@ -38,7 +42,6 @@ do
end
function accessor.state()
log (thread_id)
local _, state = next(filter(scan_states, function(state) return state.id == thread_id end))
return state
end
+4 -4
View File
@@ -1,4 +1,4 @@
module 'stack'
module 'stack' import 'info'
state = nil
@@ -23,7 +23,7 @@ function locked(slot)
end
function find_item_slot(partial)
for slot in inventory do
for slot in info.inventory do
if matching_item(slot, partial) and not eq(slot, state.target_slot) then
return slot
end
@@ -36,7 +36,7 @@ function matching_item(slot, partial)
end
function find_empty_slot()
for slot, type in inventory do
for slot, type in info.inventory do
if type == 1 and not GetContainerItemInfo(unpack(slot)) then
return slot
end
@@ -44,7 +44,7 @@ function find_empty_slot()
end
function find_charge_item_slot()
for slot in inventory do
for slot in info.inventory do
if matching_item(slot) and charges(slot) == state.target_size then
return slot
end
+2 -2
View File
@@ -1,4 +1,4 @@
module 'tooltip'
module 'tooltip' import 'info'
_g.aux_tooltip_value = true
@@ -232,7 +232,7 @@ end
function game_tooltip_hooks:SetAuctionSellItem()
local name, _, quantity = GetAuctionSellItemInfo()
if name then
for slot in inventory do
for slot in info.inventory do
local link = GetContainerItemLink(unpack(slot))
if link and select(5, info.parse_link(link)) == name then
extend_tooltip(GameTooltip, link, quantity)