some work on scanning and the auctions/bids tab
This commit is contained in:
+53
-57
@@ -1,5 +1,5 @@
|
||||
local on_load, load_dataset, new_dataset, get_dataset_key, get_snapshot, save_snapshot, get_item_record, save_item_record
|
||||
local encode_median_list, decode_median_list, serialize, deserialize, deserializing_iterator
|
||||
local on_load, load_dataset, new_dataset, get_dataset_key, get_snapshot, load_item_record, store_item_record, load_item_history, add_historical_point
|
||||
local encode_median_list, decode_median_list, serialize, deserialize
|
||||
|
||||
local DATABASE_VERSION = 0
|
||||
|
||||
@@ -24,9 +24,9 @@ end
|
||||
|
||||
function new_dataset()
|
||||
return {
|
||||
snapshot = '',
|
||||
scan_data = '',
|
||||
snapshot = {},
|
||||
item_data = {},
|
||||
item_history = {}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -38,61 +38,62 @@ end
|
||||
|
||||
function get_snapshot()
|
||||
local dataset = load_dataset()
|
||||
local signatures = deserialize(dataset.snapshot, '#')
|
||||
local snapshot = Aux.util.set()
|
||||
snapshot.add_all(signatures)
|
||||
snapshot.set_data(dataset.snapshot)
|
||||
return snapshot
|
||||
end
|
||||
|
||||
function save_snapshot(snapshot)
|
||||
local dataset = load_dataset()
|
||||
dataset.snapshot = serialize(snapshot.values(), '#')
|
||||
function load_item_history(item_key)
|
||||
local dataset = load_dataset()
|
||||
|
||||
local serialized_points = deserialize(dataset.item_history(item_key) or '', ';')
|
||||
return Aux.util.map(serialized_points, function(serialized_point)
|
||||
local time, market_price = deserialize(serialized_point, '#')
|
||||
return { time=time, market_price=market_price }
|
||||
end)
|
||||
end
|
||||
|
||||
--function load_scan_data()
|
||||
--
|
||||
--end
|
||||
--
|
||||
--function store_scan_data()
|
||||
--
|
||||
--end
|
||||
function add_historical_point(item_key)
|
||||
local dataset = load_dataset()
|
||||
local serialized_historical_point = serialize({time(), Aux.history.get_market_value(item_key) }, '#')
|
||||
local serialized_history = dataset.item_history[item_key] or ''
|
||||
serialized_history = (serialized_history == '' and serialized_history..';' or '')..serialized_historical_point
|
||||
dataset.item_history[item_key] = serialized_history
|
||||
end
|
||||
|
||||
function get_item_record(item_key)
|
||||
function load_item_record(item_key)
|
||||
local dataset = load_dataset()
|
||||
|
||||
if dataset.item_data[item_key] then
|
||||
local serialized_record = dataset.item_data[item_key]
|
||||
local count, accumulated_price, encoded_price_list = unpack(deserialize(serialized_record, '|'))
|
||||
local price_list = decode_median_list(encoded_price_list)
|
||||
local count, accumulated_price, encoded_median_list = unpack(deserialize(serialized_record, '|'))
|
||||
assert(count and accumulated_price and encode_median_list)
|
||||
local median_list = decode_median_list(encoded_median_list)
|
||||
|
||||
return {
|
||||
count = count,
|
||||
accumulated_price = accumulated_price,
|
||||
price_list = price_list
|
||||
median_list = median_list
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function save_item_record(item_key, record)
|
||||
function store_item_record(item_key, record)
|
||||
local dataset = load_dataset()
|
||||
|
||||
local encoded_price_list = encode_median_list(record.price_list)
|
||||
local serialized_record = serialize({record.count, record.acumulated_price, encoded_price_list}, '|')
|
||||
local encoded_median_list = encode_median_list(record.median_list)
|
||||
local serialized_record = serialize({record.count, record.accumulated_price, encoded_median_list}, '|')
|
||||
|
||||
dataset.item_data[item_key] = serialized_record
|
||||
end
|
||||
|
||||
-- AuctionConfig.data[auctKey][itemKey] = string.format("%s|%s", iData.data, hist);
|
||||
-- AuctionConfig.info[itemKey] = string.format("%s|%s", iData.category, iData.name);
|
||||
-- Auctioneer.Storage.SetHistMed(auctKey, itemKey, Auctioneer.Statistic.GetMedian(iData.buyoutPricesHistoryList))
|
||||
|
||||
function encode_median_list(list)
|
||||
local encoded_list = ''
|
||||
local function extend(last, n)
|
||||
if n == 1 then
|
||||
encoded_list = encoded_list == '' and last or string.format('%s:%d', encoded_list, last)
|
||||
elseif n > 1 then
|
||||
encoded_list = encoded_list == '' and string.format('%dx%d', last, n) or string.format('%s:%dx%d', encoded_list, last, n)
|
||||
local function extend(value, count)
|
||||
if count == 1 then
|
||||
encoded_list = encoded_list == '' and value or string.format('%s:%d', encoded_list, value)
|
||||
elseif count > 1 then
|
||||
encoded_list = encoded_list == '' and string.format('%dx%d', value, count) or string.format('%s:%dx%d', encoded_list, value, count)
|
||||
end
|
||||
end
|
||||
local n = 0
|
||||
@@ -111,58 +112,53 @@ function encode_median_list(list)
|
||||
return encoded_list
|
||||
end
|
||||
|
||||
function decode_median_list(str)
|
||||
function decode_median_list(encoded_list)
|
||||
local array = {}
|
||||
for x, c in string.gfind(str, '([^%:]*)(%:?)') do
|
||||
local _, _, y, n = strfind(x, '(%d*)x(%d*)')
|
||||
if y == nil then
|
||||
tinsert(array, tonumber(x))
|
||||
for part, separator in string.gfind(encoded_list, '([^%:]*)(%:?)') do
|
||||
local _, _, value, count = strfind(part, '(%d*)x(%d*)')
|
||||
if not count then
|
||||
tinsert(array, tonumber(part))
|
||||
else
|
||||
for i = 1,n do
|
||||
tinsert(array, tonumber(y))
|
||||
for i = 1,count do
|
||||
tinsert(array, tonumber(value))
|
||||
end
|
||||
end
|
||||
if c == '' then break end
|
||||
if separator == '' then break end
|
||||
end
|
||||
return array
|
||||
end
|
||||
|
||||
function serialize(data, separator)
|
||||
assert(getn(data) == 3)
|
||||
local data_string = ''
|
||||
for i, datum in ipairs(data) do
|
||||
data_string = data_string..(i == 1 and separator or '')..datum
|
||||
data_string = data_string..(i == 1 and '' or separator)..datum
|
||||
end
|
||||
return data_string
|
||||
end
|
||||
|
||||
function deserialize(data_string, separator)
|
||||
if data_string == '' then
|
||||
return {}
|
||||
end
|
||||
|
||||
local data = {}
|
||||
while true do
|
||||
local start_index, _ = strfind(data_string, separator, 1, true)
|
||||
if start_index then
|
||||
local datum = string.sub(data_string, 1, start_index - 1)
|
||||
tinsert(data, datum)
|
||||
tinsert(data, string.sub(data_string, 1, start_index - 1))
|
||||
data_string = string.sub(data_string, start_index + 1, strlen(data_string))
|
||||
else
|
||||
tinsert(data, string.sub(data_string, 1, strlen(data_string)))
|
||||
return data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function deserializing_iterator(data_string, separator)
|
||||
return function()
|
||||
local start_index, _ = strfind(data_string, separator, 1, true)
|
||||
if start_index then
|
||||
local datum = string.sub(data_string, 1, start_index - 1)
|
||||
data_string = string.sub(data_string, start_index, strlen(data_string))
|
||||
return datum
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Aux.persistence = {
|
||||
get_item_record = get_item_record,
|
||||
save_item_record = save_item_record,
|
||||
load_item_record = load_item_record,
|
||||
store_item_record = store_item_record,
|
||||
load_item_history = load_item_history,
|
||||
add_historical_point = add_historical_point,
|
||||
get_snapshot = get_snapshot,
|
||||
save_snapshot = save_snapshot,
|
||||
}
|
||||
Reference in New Issue
Block a user