refactoring
This commit is contained in:
+8
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user