added percentages of market value to tables

This commit is contained in:
Manuel Simon Hirsig
2016-01-18 20:43:43 +01:00
parent ba96d13d7c
commit 094c9d015d
5 changed files with 161 additions and 32 deletions
+15 -1
View File
@@ -1,4 +1,4 @@
AuxVersion = '2.2.11'
AuxVersion = '2.2.12'
AuxAuthors = 'shirsig; Zerf; Zirco (Auctionator); Nimeral (Auctionator backport)'
local lastRightClickAction = GetTime()
@@ -258,6 +258,20 @@ function Aux_Round(v)
return math.floor(v + 0.5)
end
function Aux.price_level_color(pct)
if pct > 135 then
return 1.0,0.0,0.0 -- red
elseif pct > 110 then
return 1.0,0.6,0.1 -- orange
elseif pct > 80 then
return 1.0,1.0,0.0 -- yellow
elseif pct > 50 then
return 0.1,1.0,0.1 -- green
else
return 0.2,0.6,1.0 -- blue
end
end
function Aux_AuctionsButton_OnClick(button)
if arg1 == "LeftButton" then -- because we additionally registered right clicks we only let left ones pass here
Aux.orig.BrowseButton_OnClick(button)
+58
View File
@@ -130,6 +130,34 @@ public.views = {
group_alpha_setter(cell, group)
end,
},
{
title = 'Pct',
width = 40,
comparator = function(group1, group2)
local market_price1 = Aux.history.get_market_value(group1[1].item_key)
local market_price2 = Aux.history.get_market_value(group2[1].item_key)
local factor1 = market_price1 and group1[1].buyout_price_per_unit / market_price1
local factor2 = market_price2 and group2[1].buyout_price_per_unit / market_price2
return Aux.util.compare(factor1, factor2, Aux.util.GT)
end,
cell_initializer = Aux.sheet.default_cell_initializer('RIGHT'),
cell_setter = function(cell, group)
local market_price = Aux.history.get_market_value(group[1].item_key)
local pct = market_price > 0 and ceil(100 / market_price * group[1].buyout_price_per_unit)
if not pct then
cell.text:SetText('N/A')
elseif pct > 999 then
cell.text:SetText('>999%')
else
cell.text:SetText(pct..'%')
end
if pct then
cell.text:SetTextColor(Aux.price_level_color(pct))
end
group_alpha_setter(cell, group)
end,
},
},
sort_order = {{column = 1, order = 'ascending' }, {column = 4, order = 'ascending'}},
},
@@ -455,6 +483,34 @@ public.views = {
auction_alpha_setter(cell, datum)
end,
},
{
title = 'Pct',
width = 40,
comparator = function(row1, row2)
local market_price1 = Aux.history.get_market_value(row1.item_key)
local market_price2 = Aux.history.get_market_value(row2.item_key)
local factor1 = market_price1 and row1.buyout_price_per_unit / market_price1
local factor2 = market_price2 and row2.buyout_price_per_unit / market_price2
return Aux.util.compare(factor1, factor2, Aux.util.GT)
end,
cell_initializer = Aux.sheet.default_cell_initializer('RIGHT'),
cell_setter = function(cell, datum)
local market_price = Aux.history.get_market_value(datum.item_key)
local pct = market_price > 0 and datum.buyout_price_per_unit and ceil(100 / market_price * datum.buyout_price_per_unit)
if not pct then
cell.text:SetText('N/A')
elseif pct > 999 then
cell.text:SetText('>999%')
else
cell.text:SetText(pct..'%')
end
if pct then
cell.text:SetTextColor(Aux.price_level_color(pct))
end
auction_alpha_setter(cell, datum)
end,
},
},
sort_order = {{column = 1, order = 'ascending' }},
},
@@ -777,6 +833,8 @@ function create_auction_record(auction_info, current_page)
suffix_id = auction_info.suffix_id,
unique_id = auction_info.unique_id,
enchant_id = auction_info.enchant_id,
item_key = auction_info.item_key,
key = auction_info.item_signature,
signature = Aux.auction_signature(auction_info.hyperlink, aux_quantity, bid, auction_info.buyout_price),
+2 -2
View File
@@ -18,7 +18,7 @@ function public.read_record(item_key)
day_count = tonumber(record[2]),
EMA5 = tonumber(record[3]),
EMA30 = tonumber(record[4]),
histogram = Aux.util.map(Aux.persistence.deserialize(record[5], ';'), function(value)
histogram = Aux.util.map(Aux.persistence.deserialize(record[5], ';', 'x'), function(value)
return tonumber(value)
end),
}
@@ -31,7 +31,7 @@ function private.write_record(item_key, record)
record.day_count,
record.EMA5,
record.EMA30,
Aux.persistence.serialize(record.histogram, ';'),
Aux.persistence.serialize(record.histogram, ';', 'x'),
},'#')
end
+58
View File
@@ -143,6 +143,34 @@ public.views = {
group_alpha_setter(cell, group)
end,
},
{
title = 'Pct',
width = 40,
comparator = function(group1, group2)
local market_price1 = Aux.history.get_market_value(group1[1].item_key)
local market_price2 = Aux.history.get_market_value(group2[1].item_key)
local factor1 = market_price1 and group1[1].buyout_price_per_unit / market_price1
local factor2 = market_price2 and group2[1].buyout_price_per_unit / market_price2
return Aux.util.compare(factor1, factor2, Aux.util.GT)
end,
cell_initializer = Aux.sheet.default_cell_initializer('RIGHT'),
cell_setter = function(cell, group)
local market_price = Aux.history.get_market_value(group[1].item_key)
local pct = market_price > 0 and ceil(100 / market_price * group[1].buyout_price_per_unit)
if not pct then
cell.text:SetText('N/A')
elseif pct > 999 then
cell.text:SetText('>999%')
else
cell.text:SetText(pct..'%')
end
if pct then
cell.text:SetTextColor(Aux.price_level_color(pct))
end
group_alpha_setter(cell, group)
end,
},
},
sort_order = {{column = 3, order = 'ascending' }},
},
@@ -394,6 +422,34 @@ public.views = {
auction_alpha_setter(cell, datum)
end,
},
{
title = 'Pct',
width = 40,
comparator = function(row1, row2)
local market_price1 = Aux.history.get_market_value(row1.item_key)
local market_price2 = Aux.history.get_market_value(row2.item_key)
local factor1 = market_price1 and row1.buyout_price_per_unit / market_price1
local factor2 = market_price2 and row2.buyout_price_per_unit / market_price2
return Aux.util.compare(factor1, factor2, Aux.util.GT)
end,
cell_initializer = Aux.sheet.default_cell_initializer('RIGHT'),
cell_setter = function(cell, datum)
local market_price = Aux.history.get_market_value(datum.item_key)
local pct = market_price > 0 and datum.buyout_price_per_unit and ceil(100 / market_price * datum.buyout_price_per_unit)
if not pct then
cell.text:SetText('N/A')
elseif pct > 999 then
cell.text:SetText('>999%')
else
cell.text:SetText(pct..'%')
end
if pct then
cell.text:SetTextColor(Aux.price_level_color(pct))
end
auction_alpha_setter(cell, datum)
end,
},
},
sort_order = {},
},
@@ -755,6 +811,8 @@ function create_auction_record(auction_info, current_page)
unique_id = auction_info.unique_id,
enchant_id = auction_info.enchant_id,
item_key = auction_info.item_key,
signature = Aux.auction_signature(auction_info.hyperlink, aux_quantity, bid, auction_info.buyout_price),
name = auction_info.name,
+28 -29
View File
@@ -40,38 +40,23 @@ function public.load_snapshot()
return snapshot
end
--function public.load_scan_records(item_key)
-- local dataset = private.load_dataset()
--
-- local serialized_records = private.deserialize(dataset[item_key] or '', ';')
-- return Aux.util.map(serialized_records, function(serialized_record)
-- local time, count, min_price, accumulated_price = private.deserialize(serialized_record, '#')
-- return {
-- time = time,
-- count = count,
-- min_price = min_price,
-- accumulated_price = accumulated_price,
-- }
-- end)
--end
--
--function public.store_scan_record(item_key, record)
-- local dataset = private.load_dataset()
-- local serialized_record = private.serialize({ record.time, record.count, record.min_price, record.accumulated_price }, '#')
-- local serialized_records = dataset[item_key] or ''
-- serialized_records = serialized_records..(serialized_records == '' and '' or ';')..serialized_record
-- dataset[item_key] = serialized_records
--end
function public.serialize(data, separator)
function public.serialize(data, separator, compactor)
local data_string = ''
for i, datum in ipairs(data) do
data_string = data_string..(i == 1 and '' or separator)..datum
local i = 1
while i <= getn(data) do
local element, count = data[i], 0
repeat
count = count + 1
i = i + 1
until (not compactor) or data[i] ~= element
local part = (count > 1 and compactor) and element..compactor..count or element
data_string = data_string..(data_string == '' and '' or separator)..part
end
return data_string
end
function public.deserialize(data_string, separator)
function public.deserialize(data_string, separator, compactor)
if data_string == '' then
return {}
end
@@ -79,11 +64,25 @@ function public.deserialize(data_string, separator)
local data = {}
while true do
local start_index, _ = strfind(data_string, separator, 1, true)
local part
if start_index then
tinsert(data, string.sub(data_string, 1, start_index - 1))
part = 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)))
part = string.sub(data_string, 1, strlen(data_string))
end
if compactor and strfind(part, compactor, 1, true) then
local compactor_index, _ = strfind(part, compactor, 1, true)
for i=1, tonumber(string.sub(part, compactor_index + 1, strlen(part))) do
tinsert(data, string.sub(part, 1, compactor_index - 1))
end
else
tinsert(data, part)
end
if not start_index then
return data
end
end