greatly simplified history

This commit is contained in:
Manuel Simon Hirsig
2016-02-08 21:43:40 +01:00
parent ab11da7039
commit a19eec7758
12 changed files with 126 additions and 178 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
## Interface: 11200 ## Interface: 11200
## Title: Aux ## Title: Aux
## Notes: A lightweight addon designed to help manage auctions ## 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 ## SavedVariables: aux_database, aux_auctionable_items
slash.lua slash.lua
@@ -20,7 +20,7 @@ post.lua
listing.lua listing.lua
auction_listing.lua auction_listing.lua
item_listing.lua item_listing.lua
history.xml history.lua
info.xml info.xml
completion.xml completion.xml
+1 -1
View File
@@ -192,7 +192,7 @@ local methods = {
GetRecordPercent = function(self, record) GetRecordPercent = function(self, record)
if not record then return end if not record then return end
-- cache the market value on the record -- 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.market_value > 0 then
if record.unit_buyout_price > 0 then if record.unit_buyout_price > 0 then
return Aux.round(100 * record.unit_buyout_price / record.market_value, 1) return Aux.round(100 * record.unit_buyout_price / record.market_value, 1)
+1 -1
View File
@@ -55,7 +55,7 @@ function private.update_listing()
local auction_rows = {} local auction_rows = {}
for i, auction_record in auction_records or {} do 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, { tinsert(auction_rows, {
cols = { cols = {
{ value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' }, { value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' },
+1 -1
View File
@@ -73,7 +73,7 @@ function private.update_listing()
else else
status = RED_FONT_COLOR_CODE..'Outbid'..FONT_COLOR_CODE_CLOSE status = RED_FONT_COLOR_CODE..'Outbid'..FONT_COLOR_CODE_CLOSE
end 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, { tinsert(auction_rows, {
cols = { cols = {
{ value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' }, { value='|c'..Aux.quality_color(auction_record.quality)..'['..auction_record.name..']'..'|r' },
+4 -4
View File
@@ -1,4 +1,4 @@
AuxVersion = '2.4.17' AuxVersion = '2.4.18'
AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)' AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)'
Aux = { Aux = {
@@ -28,13 +28,13 @@ function Aux.on_load()
-- EnhTooltip.AddLine('Seen '..auction_count..' '..Aux_PluralizeIf('time', auction_count)..' at auction', nil, true) -- EnhTooltip.AddLine('Seen '..auction_count..' '..Aux_PluralizeIf('time', auction_count)..' at auction', nil, true)
-- EnhTooltip.LineColor(0.5, 0.8, 0.1) -- 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 if market_value then
local market_value_line local market_value_line
if count == 1 then if count == 1 then
market_value_line = 'Market Value: '..EnhTooltip.GetTextGSC(market_value) market_value_line = 'Value: '..EnhTooltip.GetTextGSC(market_value)
else 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 end
EnhTooltip.AddLine(market_value_line, nil, true) EnhTooltip.AddLine(market_value_line, nil, true)
+102 -139
View File
@@ -1,99 +1,72 @@
local private, public = {}, {} local private, public = {}, {}
Aux.history = public Aux.history = public
aux_conservative_value = false
private.PUSH_INTERVAL = 57600 private.PUSH_INTERVAL = 57600
private.NEW_RECORD = '####'
aux_market_value_type = 'buyout'
local data
function private.load_data() function private.load_data()
local dataset = Aux.persistence.load_dataset() local dataset = Aux.persistence.load_dataset()
dataset.history = dataset.history or { dataset.history = dataset.history or { next_push = time() + private.PUSH_INTERVAL, item_data = {} }
item_records = {},
next_push = time() + private.PUSH_INTERVAL,
}
return dataset.history return dataset.history
end end
function public.on_login() function private.read_record(item_key)
data = private.load_data() local 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)
if data.next_push < time() then if data.next_push < time() then
data.next_push = time() + private.PUSH_INTERVAL
private.push_data() private.push_data()
end 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 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 unit_high_bid = ceil(auction_info.high_bid / auction_info.aux_quantity)
local bid = Aux.round(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
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))
end end
if auction_info.buyout_price > 0 then 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 unit_buyout_price = ceil(auction_info.buyout_price / auction_info.aux_quantity)
local buyout = Aux.round(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
data.item_records[auction_info.item_key].buyouts_of_today:add(buyout) item_record.daily_min_buyout = item_record.daily_min_buyout and min(item_record.daily_min_buyout, unit_buyout_price) or unit_buyout_price
-- data.item_records[auction_info.item_key].buyouts_of_today:add(private.price_class(auction_info.buyout_price / auction_info.aux_quantity))
end end
private.write_record(auction_info.item_key, item_record)
end end
--function public.price_data(item_key) --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) -- return item_record.auction_count, item_record.day_count, private.daily_market_value(item_record.histogram), private.median(item_record.last_daily_values)
--end --end
function public.market_value(item_key) function public.value(item_key)
local record = data.item_records[item_key] local item_record = private.read_record(item_key)
if not record then local past_market_values
return if aux_conservative_value then
end past_market_values = item_record.conservative_market_values
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
else 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
end end
function private.daily_bid_value(item_key) function private.market_value(item_key)
local prices = data.item_records[item_key].bids_of_today:values() local item_record = private.read_record(item_key)
if getn(prices) == 0 then if item_record.daily_max_bid and item_record.daily_min_buyout then
return 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 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 end
function private.daily_buyout_value(item_key) function private.conservative_market_value(item_key)
local prices = data.item_records[item_key].buyouts_of_today:values() local item_record = private.read_record[item_key]
if getn(prices) == 0 then if item_record.daily_max_bid and item_record.daily_min_buyout then
return 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 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 end
function private.median(list) function private.median(list)
@@ -175,28 +131,35 @@ function private.median(list)
end end
function private.push_data() 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) local item_record = private.read_record(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 daily_buyout_value = private.daily_buyout_value(item_key) local market_value = private.market_value(item_key)
if daily_buyout_value then if market_value then
tinsert(record.daily_buyout_values, Aux.round(daily_buyout_value)) tinsert(item_record.market_values, market_value)
while getn(item_record.market_values) > 11 do
tremove(item_record.market_values, 1)
end
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 end
data.next_push = time() + private.PUSH_INTERVAL
end end
-19
View File
@@ -1,19 +0,0 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="history.lua"/>
<Frame>
<Scripts>
<OnLoad>
this:RegisterEvent('PLAYER_LOGIN')
this:RegisterEvent('PLAYER_LOGOUT')
</OnLoad>
<OnEvent>
if event == 'PLAYER_LOGIN' then
Aux.history.on_login()
elseif event == 'PLAYER_LOGOUT' then
Aux.history.on_logout()
end
</OnEvent>
</Scripts>
</Frame>
</Ui>
+1
View File
@@ -19,6 +19,7 @@ function public.load_dataset()
end end
function public.serialize(data, separator, compactor) function public.serialize(data, separator, compactor)
local data_string = '' local data_string = ''
local i = 1 local i = 1
while i <= getn(data) do while i <= getn(data) do
+2 -2
View File
@@ -45,7 +45,7 @@ function private.update_auction_listing()
if selected_item then if selected_item then
for i, auction_record in ipairs(existing_auctions[selected_item.key] or {}) do for i, auction_record in ipairs(existing_auctions[selected_item.key] or {}) do
local stack_size = auction_record.stack_size == private.stack_size_slider:GetValue() and GREEN_FONT_COLOR_CODE..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size local stack_size = auction_record.stack_size == private.stack_size_slider:GetValue() and GREEN_FONT_COLOR_CODE..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size
local market_value = Aux.history.market_value(auction_record.item_key) local market_value = Aux.history.value(auction_record.item_key)
tinsert(auction_rows, { tinsert(auction_rows, {
cols = { cols = {
{ value=auction_record.count }, { value=auction_record.count },
@@ -612,7 +612,7 @@ function private.undercutting_suggestion()
end end
function private.market_value_suggestion() function private.market_value_suggestion()
local price_suggestion = Aux.history.market_value(selected_item.key) and 1.2 * Aux.history.market_value(selected_item.key) local price_suggestion = Aux.history.value(selected_item.key) and 1.2 * Aux.history.value(selected_item.key)
if not price_suggestion then if not price_suggestion then
return 0, 0 return 0, 0
end end
+2 -2
View File
@@ -292,8 +292,8 @@ function m.validator(filter)
return return
end end
if filter.max_percent and (record.unit_buyout_price == 0 if filter.max_percent and (record.unit_buyout_price == 0
or not Aux.history.market_value(record.item_key) or not Aux.history.value(record.item_key)
or record.unit_buyout_price / Aux.history.market_value(record.item_key) * 100 > filter.max_percent) or record.unit_buyout_price / Aux.history.value(record.item_key) * 100 > filter.max_percent)
then then
return return
end end
+4 -1
View File
@@ -198,7 +198,10 @@ function public.on_load()
btn:SetWidth(60) btn:SetWidth(60)
btn:SetHeight(25) btn:SetHeight(25)
btn:SetText('Search') btn:SetText('Search')
btn:SetScript('OnClick', public.start_search) btn:SetScript('OnClick', function()
private.search_box:ClearFocus()
public.start_search()
end)
private.search_button = btn private.search_button = btn
end end
do do
+6 -6
View File
@@ -11,11 +11,11 @@ function SlashCmdList.AUX(parameter)
elseif parameter == 'delete item cache' then elseif parameter == 'delete item cache' then
aux_auctionable_items = nil aux_auctionable_items = nil
Aux.log('Item cache deleted; falling back to the default.') Aux.log('Item cache deleted; falling back to the default.')
elseif parameter == 'market bid' then elseif parameter == 'conservative value on' then
aux_market_value_type = 'bid' aux_conservative_value = true
Aux.log('Set market value to bid based.') Aux.log('Conservative value activated')
elseif parameter == 'market buyout' then elseif parameter == 'conservative value off' then
aux_market_value_type = 'buyout' aux_conservative_value = false
Aux.log('Set market value to buyout based.') Aux.log('Conservative value deactivated.')
end end
end end