From a19eec77589e7b58d3f389c359e25a13b3cbabfc Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 8 Feb 2016 21:43:40 +0100 Subject: [PATCH] greatly simplified history --- Aux-AddOn.toc | 4 +- auction_listing.lua | 2 +- auctions_frame.lua | 2 +- bids_frame.lua | 2 +- core.lua | 8 +- history.lua | 241 +++++++++++++++++++------------------------- history.xml | 19 ---- persistence.lua | 1 + post_frame.lua | 4 +- scan_util.lua | 4 +- search_frame.lua | 5 +- slash.lua | 12 +-- 12 files changed, 126 insertions(+), 178 deletions(-) delete mode 100644 history.xml diff --git a/Aux-AddOn.toc b/Aux-AddOn.toc index f86f801..dcc7a60 100644 --- a/Aux-AddOn.toc +++ b/Aux-AddOn.toc @@ -1,7 +1,7 @@ ## Interface: 11200 ## Title: Aux ## Notes: A lightweight addon designed to help manage auctions -## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_price_per_unit, aux_market_value_type, aux_scale +## SavedVariablesPerCharacter: aux_recent_searches, aux_favorite_searches, aux_price_per_unit, aux_conservative_value, aux_scale ## SavedVariables: aux_database, aux_auctionable_items slash.lua @@ -20,7 +20,7 @@ post.lua listing.lua auction_listing.lua item_listing.lua -history.xml +history.lua info.xml completion.xml diff --git a/auction_listing.lua b/auction_listing.lua index 6114afa..8784a30 100644 --- a/auction_listing.lua +++ b/auction_listing.lua @@ -192,7 +192,7 @@ local methods = { GetRecordPercent = function(self, record) if not record then return end -- cache the market value on the record - record.market_value = record.market_value or Aux.history.market_value(record.item_key) or 0 + record.market_value = record.market_value or Aux.history.value(record.item_key) or 0 if record.market_value > 0 then if record.unit_buyout_price > 0 then return Aux.round(100 * record.unit_buyout_price / record.market_value, 1) diff --git a/auctions_frame.lua b/auctions_frame.lua index 98b9e21..1846394 100644 --- a/auctions_frame.lua +++ b/auctions_frame.lua @@ -55,7 +55,7 @@ function private.update_listing() local auction_rows = {} for i, auction_record in auction_records or {} do - local market_value = Aux.history.market_value(auction_record.item_key) + local market_value = Aux.history.value(auction_record.item_key) tinsert(auction_rows, { cols = { { value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' }, diff --git a/bids_frame.lua b/bids_frame.lua index 88182d4..2bfbfb7 100644 --- a/bids_frame.lua +++ b/bids_frame.lua @@ -73,7 +73,7 @@ function private.update_listing() else status = RED_FONT_COLOR_CODE..'Outbid'..FONT_COLOR_CODE_CLOSE end - local market_value = Aux.history.market_value(auction_record.item_key) + local market_value = Aux.history.value(auction_record.item_key) tinsert(auction_rows, { cols = { { value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' }, diff --git a/core.lua b/core.lua index 274b50b..47e5a2a 100644 --- a/core.lua +++ b/core.lua @@ -1,4 +1,4 @@ -AuxVersion = '2.4.17' +AuxVersion = '2.4.18' AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)' Aux = { @@ -28,13 +28,13 @@ function Aux.on_load() -- EnhTooltip.AddLine('Seen '..auction_count..' '..Aux_PluralizeIf('time', auction_count)..' at auction', nil, true) -- EnhTooltip.LineColor(0.5, 0.8, 0.1) - local market_value = Aux.history.market_value(item_key) + local market_value = Aux.history.value(item_key) if market_value then local market_value_line if count == 1 then - market_value_line = 'Market Value: '..EnhTooltip.GetTextGSC(market_value) + market_value_line = 'Value: '..EnhTooltip.GetTextGSC(market_value) else - market_value_line = 'Market Value: '..EnhTooltip.GetTextGSC(market_value * count)..' / '..EnhTooltip.GetTextGSC(market_value) + market_value_line = 'Value: '..EnhTooltip.GetTextGSC(market_value * count)..' / '..EnhTooltip.GetTextGSC(market_value) end EnhTooltip.AddLine(market_value_line, nil, true) diff --git a/history.lua b/history.lua index 184c453..cdb789b 100644 --- a/history.lua +++ b/history.lua @@ -1,99 +1,72 @@ local private, public = {}, {} Aux.history = public +aux_conservative_value = false + private.PUSH_INTERVAL = 57600 - -aux_market_value_type = 'buyout' - -local data +private.NEW_RECORD = '####' function private.load_data() local dataset = Aux.persistence.load_dataset() - dataset.history = dataset.history or { - item_records = {}, - next_push = time() + private.PUSH_INTERVAL, - } + dataset.history = dataset.history or { next_push = time() + private.PUSH_INTERVAL, item_data = {} } return dataset.history end -function public.on_login() - data = private.load_data() - for item_key, _ in pairs(data.item_records) do - data.item_records[item_key] = private.deserialize_item_record(data.item_records[item_key]) - end -end - -function public.on_logout() - for item_key, _ in pairs(data.item_records) do - data.item_records[item_key] = private.serialize_item_record(data.item_records[item_key]) - end -end - -function private.serialize_item_record(item_record) - return Aux.persistence.serialize({ - Aux.persistence.serialize(item_record.daily_bid_values, ';'), - Aux.persistence.serialize(item_record.daily_buyout_values, ';'), - Aux.persistence.serialize(item_record.bids_of_today:values(), ';'), - Aux.persistence.serialize(item_record.buyouts_of_today:values(), ';'), - }, '#') -end - -function private.deserialize_item_record(data_string) - local fields = Aux.persistence.deserialize(data_string, '#') - - local bids_of_today = Aux.util.set() - bids_of_today:add_all(Aux.util.map(Aux.persistence.deserialize(fields[3], ';'), function(value) - return tonumber(value) - end)) - - local buyouts_of_today = Aux.util.set() - buyouts_of_today:add_all(Aux.util.map(Aux.persistence.deserialize(fields[4], ';'), function(value) - return tonumber(value) - end)) - - return { - daily_bid_values = Aux.util.map(Aux.persistence.deserialize(fields[1], ';'), function(value) - return tonumber(value) - end), - daily_buyout_values = Aux.util.map(Aux.persistence.deserialize(fields[2], ';'), function(value) - return tonumber(value) - end), - bids_of_today = bids_of_today, - buyouts_of_today = buyouts_of_today, - } -end - -function private.new_item_record() - return { daily_bid_values = {}, daily_buyout_values = {}, bids_of_today = Aux.util.set(), buyouts_of_today = Aux.util.set() } -end - ---function private.price_class(price) --- return Aux.round(math.log(price) / math.log(1.1)) ---end --- ---function private.price_class_price(class) --- return 1.1^class ---end - -function public.process_auction(auction_info) +function private.read_record(item_key) + local data = private.load_data() if data.next_push < time() then + data.next_push = time() + private.PUSH_INTERVAL private.push_data() end + local fields = Aux.persistence.deserialize(data.item_data[item_key] or private.NEW_RECORD, '#') + return { +-- auction_count = tonumber(record[1]), +-- day_count = tonumber(record[2]), + daily_max_bid = tonumber(fields[1]), + daily_min_buyout = tonumber(fields[2]), + daily_max_buyout = tonumber(fields[3]), + market_values = Aux.util.map(Aux.persistence.deserialize(fields[4], ';'), function(value) + return tonumber(value) + end), + conservative_market_values = Aux.util.map(Aux.persistence.deserialize(fields[5], ';'), function(value) + return tonumber(value) + end), + } +end + +function private.write_record(item_key, record) + local data = private.load_data() + data.item_data[item_key] = Aux.persistence.serialize({ + record.daily_max_bid or '', + record.daily_min_buyout or '', + record.daily_max_buyout or '', + Aux.persistence.serialize(record.market_values, ';'), + Aux.persistence.serialize(record.conservative_market_values, ';', 'x'), + },'#') +end + +function public.process_auction(auction_info) + +-- item_record.auction_count = item_record.auction_count + 1 + + local data = private.load_data() + + local item_record = private.read_record(auction_info.item_key) + if auction_info.high_bid > 0 then - data.item_records[auction_info.item_key] = data.item_records[auction_info.item_key] or private.new_item_record() - local bid = Aux.round(auction_info.high_bid / auction_info.aux_quantity) - data.item_records[auction_info.item_key].bids_of_today:add(bid) --- data.item_records[auction_info.item_key].bids_of_today:add(private.price_class(auction_info.high_bid / auction_info.aux_quantity)) + local unit_high_bid = ceil(auction_info.high_bid / auction_info.aux_quantity) + item_record.daily_max_bid = item_record.daily_max_bid and max(item_record.daily_max_bid, unit_high_bid) or unit_high_bid end if auction_info.buyout_price > 0 then - data.item_records[auction_info.item_key] = data.item_records[auction_info.item_key] or private.new_item_record() - local buyout = Aux.round(auction_info.buyout_price / auction_info.aux_quantity) - data.item_records[auction_info.item_key].buyouts_of_today:add(buyout) --- data.item_records[auction_info.item_key].buyouts_of_today:add(private.price_class(auction_info.buyout_price / auction_info.aux_quantity)) + local unit_buyout_price = ceil(auction_info.buyout_price / auction_info.aux_quantity) + item_record.daily_max_buyout = item_record.daily_max_buyout and max(item_record.daily_max_buyout, unit_buyout_price) or unit_buyout_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 end + + private.write_record(auction_info.item_key, item_record) end --function public.price_data(item_key) @@ -101,62 +74,45 @@ end -- return item_record.auction_count, item_record.day_count, private.daily_market_value(item_record.histogram), private.median(item_record.last_daily_values) --end -function public.market_value(item_key) - local record = data.item_records[item_key] +function public.value(item_key) + local item_record = private.read_record(item_key) - if not record then - return - end - - local daily_values = aux_market_value_type == 'buyout' and record.daily_buyout_values or record.daily_bid_values - - if getn(daily_values) == 0 then - if aux_market_value_type == 'buyout' then - return private.daily_buyout_value(item_key) - elseif aux_market_value_type == 'bid' then - return private.daily_bid_value(item_key) - end + local past_market_values + if aux_conservative_value then + past_market_values = item_record.conservative_market_values else - return private.median(daily_values) + past_market_values = item_record.market_values + end + + if getn(past_market_values) > 0 then + return private.median(past_market_values) + elseif aux_conservative_value then + return private.conservative_market_value(item_key) + else + return private.market_value(item_key) end end -function private.daily_bid_value(item_key) - local prices = data.item_records[item_key].bids_of_today:values() +function private.market_value(item_key) + local item_record = private.read_record(item_key) - if getn(prices) == 0 then - return + if item_record.daily_max_bid and item_record.daily_min_buyout then + return max(item_record.daily_max_bid, item_record.daily_min_buyout) + elseif item_record.daily_min_buyout then + return max(ceil(item_record.daily_min_buyout * 1.15), item_record.daily_max_buyout) + elseif item_record.daily_max_bid then + return item_record.daily_max_bid end - - sort(prices, function(a,b) return b < a end) - - local acc = 0 - local cutoff = ceil(getn(prices) * 0.2) - for i=1,cutoff do - acc = acc + prices[i] --- acc = acc + private.price_class_price(prices[i]) - end - - return acc / cutoff end -function private.daily_buyout_value(item_key) - local prices = data.item_records[item_key].buyouts_of_today:values() +function private.conservative_market_value(item_key) + local item_record = private.read_record[item_key] - if getn(prices) == 0 then - return + if item_record.daily_max_bid and item_record.daily_min_buyout then + return min(item_record.daily_max_bid, item_record.daily_min_buyout) + elseif item_record.daily_max_bid then + return item_record.daily_max_bid end - - sort(prices) - - local acc = 0 - local cutoff = ceil(getn(prices) * 0.2) - for i=1,cutoff do - acc = acc + prices[i] --- acc = acc + private.price_class_price(prices[i]) - end - - return acc / cutoff end function private.median(list) @@ -175,28 +131,35 @@ function private.median(list) end function private.push_data() + local data = private.load_data() + local item_data = data.item_data - for item_key, record in pairs(data.item_records) do + for item_key, _ in pairs(item_data) do - local daily_bid_value = private.daily_bid_value(item_key) - if daily_bid_value then - tinsert(record.daily_bid_values, Aux.round(daily_bid_value)) - end - while getn(record.daily_bid_values) > 11 do - tremove(record.daily_bid_values, 1) - end - record.bids_of_today = Aux.util.set() + local item_record = private.read_record(item_key) - local daily_buyout_value = private.daily_buyout_value(item_key) - if daily_buyout_value then - tinsert(record.daily_buyout_values, Aux.round(daily_buyout_value)) + local market_value = private.market_value(item_key) + if market_value then + tinsert(item_record.market_values, market_value) + while getn(item_record.market_values) > 11 do + tremove(item_record.market_values, 1) + end end - while getn(record.daily_buyout_values) > 11 do - tremove(record.daily_buyout_values, 1) - end - record.buyouts_of_today = Aux.util.set() + local conservative_market_value = private.conservative_market_value(item_key) + if conservative_market_value then + tinsert(item_record.conservative_market_values, conservative_market_value) + while getn(item_record.conservative_market_values) > 11 do + tremove(item_record.conservative_market_values, 1) + end + end + + item_record.daily_max_bid = nil + item_record.daily_min_buyout = nil + item_record.daily_max_buyout = nil + + if market_value or conservative_market_value then + private.write_record(item_key, item_record) + end end - - data.next_push = time() + private.PUSH_INTERVAL end \ No newline at end of file diff --git a/history.xml b/history.xml deleted file mode 100644 index 3156b3a..0000000 --- a/history.xml +++ /dev/null @@ -1,19 +0,0 @@ - -