refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-29 13:44:18 +02:00
parent 4b8b0cd9d0
commit 2ea9a9d665
11 changed files with 126 additions and 122 deletions
+8 -8
View File
@@ -17,19 +17,19 @@ do
end
do
local time = 0
local cache = 0
function private.next_push.get()
if time() > time then
if time() > cache then
local date = date('*t')
date.hour, date.min, date.sec = 24, 0, 0
time = time(date)
cache = time(date)
end
return time
return cache
end
end
function private.new_record.get()
return -object('next_push', next_push, 'data_points', t)
return T('next_push', next_push, 'data_points', t)
end
function read_record(item_key)
@@ -78,7 +78,7 @@ function public.value(item_key)
for _, data_point in item_record.data_points do
local weight = .99 ^ round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24))
total_weight = total_weight + weight
tinsert(weighted_values, -object('value', data_point.market_value, 'weight', weight))
tinsert(weighted_values, T('value', data_point.market_value, 'weight', weight))
end
for _, weighted_value in weighted_values do
weighted_value.weight = weighted_value.weight / total_weight
@@ -87,7 +87,7 @@ function public.value(item_key)
else
value = calculate_market_value(item_record)
end
value_cache[item_key] = -object('value', value, 'next_push', item_record.next_push)
value_cache[item_key] = T('value', value, 'next_push', item_record.next_push)
end
return value_cache[item_key].value
end
@@ -113,7 +113,7 @@ end
function push_record(item_record)
for market_value in present(calculate_market_value(item_record)) do
tinsert(item_record.data_points, 1, -object('market_value', market_value, 'time', item_record.next_push))
tinsert(item_record.data_points, 1, T('market_value', market_value, 'time', item_record.next_push))
while getn(item_record.data_points) > 11 do
tremove(item_record.data_points)
end