refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-02 14:29:13 +02:00
parent 54a2846f62
commit 2624fba4a2
8 changed files with 35 additions and 80 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ function public.value(item_key)
local weighted_values = {} local weighted_values = {}
local total_weight = 0 local total_weight = 0
for _, data_point in item_record.data_points do for _, data_point in item_record.data_points do
local weight = 0.99^Aux.round((item_record.data_points[1].time - data_point.time) / (60*60*24)) local weight = 0.99^Aux.util.round((item_record.data_points[1].time - data_point.time) / (60*60*24))
total_weight = total_weight + weight total_weight = total_weight + weight
tinsert(weighted_values, {value = data_point.market_value, weight = weight}) tinsert(weighted_values, {value = data_point.market_value, weight = weight})
end end
+1 -1
View File
@@ -32,7 +32,7 @@ function private.post_auction(slot, k)
ClickAuctionSellItemButton() ClickAuctionSellItemButton()
ClearCursor() ClearCursor()
StartAuction(max(1, Aux.round(m.state.unit_start_price * item_info.aux_quantity)), Aux.round(m.state.unit_buyout_price * item_info.aux_quantity), m.state.duration) StartAuction(max(1, Aux.util.round(m.state.unit_start_price * item_info.aux_quantity)), Aux.util.round(m.state.unit_buyout_price * item_info.aux_quantity), m.state.duration)
local c = Aux.control.await(function() local c = Aux.control.await(function()
m.state.posted = m.state.posted + 1 m.state.posted = m.state.posted + 1
+1 -1
View File
@@ -117,7 +117,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
end end
if aux_tooltip_daily then if aux_tooltip_daily then
local market_value = Aux.history.market_value(item_key) local market_value = Aux.history.market_value(item_key)
tooltip:AddLine('Today: '..(market_value and Aux.util.format_money(market_value * quantity)..' ('..Aux.auction_listing.percentage_historical(Aux.round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b) tooltip:AddLine('Today: '..(market_value and Aux.util.format_money(market_value * quantity)..' ('..Aux.auction_listing.percentage_historical(Aux.util.round(market_value / value * 100))..')' or GRAY_FONT_COLOR_CODE..'---'..FONT_COLOR_CODE_CLOSE), color.r, color.g, color.b)
end end
end end
-4
View File
@@ -406,10 +406,6 @@ function private.on_auction_house_closed()
AuxFrame:Hide() AuxFrame:Hide()
end end
function public.round(v)
return floor(v + 0.5)
end
function public.min_bid_increment(current_bid) function public.min_bid_increment(current_bid)
return max(1, floor(current_bid / 100) * 5) return max(1, floor(current_bid / 100) * 5)
end end
+2 -2
View File
@@ -520,9 +520,9 @@ function private.record_percentage(record)
local historical_value = Aux.history.value(record.item_key) or 0 local historical_value = Aux.history.value(record.item_key) or 0
if historical_value > 0 then if historical_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 / historical_value, 1) return Aux.util.round(100 * record.unit_buyout_price / historical_value, 1)
end end
return nil, Aux.round(100 * record.unit_bid_price / historical_value, 1) return nil, Aux.util.round(100 * record.unit_bid_price / historical_value, 1)
end end
end end
+6 -6
View File
@@ -144,9 +144,9 @@ function private.update_auction_listing()
{ value=Aux.auction_listing.time_left(auction_record.duration) }, { value=Aux.auction_listing.time_left(auction_record.duration) },
{ value=auction_record.stack_size == stack_size and GREEN_FONT_COLOR_CODE..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size }, { value=auction_record.stack_size == stack_size and GREEN_FONT_COLOR_CODE..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size },
{ value=Aux.money.to_string(auction_record.unit_blizzard_bid, true, nil, 3, bid_color) }, { value=Aux.money.to_string(auction_record.unit_blizzard_bid, true, nil, 3, bid_color) },
{ value=historical_value and Aux.auction_listing.percentage_historical(Aux.round(auction_record.unit_blizzard_bid / historical_value * 100)) or '---' }, { value=historical_value and Aux.auction_listing.percentage_historical(Aux.util.round(auction_record.unit_blizzard_bid / historical_value * 100)) or '---' },
{ value=auction_record.unit_buyout_price > 0 and Aux.money.to_string(auction_record.unit_buyout_price, true, nil, 3, buyout_color) or '---' }, { value=auction_record.unit_buyout_price > 0 and Aux.money.to_string(auction_record.unit_buyout_price, true, nil, 3, buyout_color) or '---' },
{ value=auction_record.unit_buyout_price > 0 and historical_value and Aux.auction_listing.percentage_historical(Aux.round(auction_record.unit_buyout_price / historical_value * 100)) or '---' }, { value=auction_record.unit_buyout_price > 0 and historical_value and Aux.auction_listing.percentage_historical(Aux.util.round(auction_record.unit_buyout_price / historical_value * 100)) or '---' },
}, },
record = auction_record, record = auction_record,
}) })
@@ -189,12 +189,12 @@ function private.price_update()
local start_price_input = m.get_unit_start_price() local start_price_input = m.get_unit_start_price()
settings.start_price = start_price_input settings.start_price = start_price_input
local historical_value = Aux.history.value(m.selected_item.key) local historical_value = Aux.history.value(m.selected_item.key)
m.start_price_percentage:SetText(historical_value and Aux.auction_listing.percentage_historical(Aux.round(start_price_input / historical_value * 100)) or '---') m.start_price_percentage:SetText(historical_value and Aux.auction_listing.percentage_historical(Aux.util.round(start_price_input / historical_value * 100)) or '---')
local buyout_price_input = m.get_unit_buyout_price() local buyout_price_input = m.get_unit_buyout_price()
settings.buyout_price = buyout_price_input settings.buyout_price = buyout_price_input
local historical_value = Aux.history.value(m.selected_item.key) local historical_value = Aux.history.value(m.selected_item.key)
m.buyout_price_percentage:SetText(historical_value and Aux.auction_listing.percentage_historical(Aux.round(buyout_price_input / historical_value * 100)) or '---') m.buyout_price_percentage:SetText(historical_value and Aux.auction_listing.percentage_historical(Aux.util.round(buyout_price_input / historical_value * 100)) or '---')
m.write_settings(settings) m.write_settings(settings)
end end
@@ -327,8 +327,8 @@ function private.update_item_configuration()
end end
function private.undercut(record, stack_size, stack) function private.undercut(record, stack_size, stack)
local start_price = Aux.round(record.unit_blizzard_bid * (stack and record.stack_size or stack_size)) local start_price = Aux.util.round(record.unit_blizzard_bid * (stack and record.stack_size or stack_size))
local buyout_price = Aux.round(record.unit_buyout_price * (stack and record.stack_size or stack_size)) local buyout_price = Aux.util.round(record.unit_buyout_price * (stack and record.stack_size or stack_size))
if not record.own then if not record.own then
start_price = max(0, start_price - 1) start_price = max(0, start_price - 1)
+3 -3
View File
@@ -432,13 +432,13 @@ end
function private.blizzard_page_index(str) function private.blizzard_page_index(str)
if tonumber(str) then if tonumber(str) then
return Aux.round(max(0, tonumber(str) - 1)) return Aux.util.round(max(0, tonumber(str) - 1))
end end
end end
function private.blizzard_level(str) function private.blizzard_level(str)
if tonumber(str) then if tonumber(str) then
return Aux.round(max(1, min(60, tonumber(str)))) return Aux.util.round(max(1, min(60, tonumber(str))))
end end
end end
@@ -872,7 +872,7 @@ function private.add_post_component()
local filter = name local filter = name
if not Aux.filter.filters[name] and filter == 'and' or filter == 'or' then if not Aux.filter.filters[name] and filter == 'and' or filter == 'or' then
local arity = m.filter_input:GetText() local arity = m.filter_input:GetText()
arity = tonumber(arity) and Aux.round(tonumber(arity)) arity = tonumber(arity) and Aux.util.round(tonumber(arity))
if arity and arity < 2 then if arity and arity < 2 then
Aux.log('Invalid operator suffix') Aux.log('Invalid operator suffix')
return return
+21 -62
View File
@@ -19,24 +19,28 @@ function public.product(...)
return x return x
end end
function public.id(value) function public.id(x)
return value return x
end end
function public.const(value) function public.const(x)
return function() return function()
return value return x
end end
end end
function public.size(table) function public.size(t)
local x = 0 local x = 0
for _ in table do for _ in t do
x = x + 1 x = x + 1
end end
return x return x
end end
function public.round(x)
return floor(x + 0.5)
end
function public.eq(t1, t2) function public.eq(t1, t2)
if not t1 or not t2 then if not t1 or not t2 then
return false return false
@@ -57,18 +61,18 @@ function public.eq(t1, t2)
return true return true
end end
function public.wipe(table) function public.wipe(t)
while getn(table) > 0 do while getn(t) > 0 do
tremove(table) tremove(t)
end end
for k, _ in table do for k, _ in t do
table[k] = nil t[k] = nil
end end
end end
function public.copy(table) function public.copy(t)
local copy = {} local copy = {}
for k, v in table do for k, v in t do
copy[k] = v copy[k] = v
end end
return copy return copy
@@ -80,10 +84,10 @@ function public.cons(element, list)
return new_list return new_list
end end
function public.trim(string) function public.trim(str)
string = gsub(string, '^%s*', '') str = gsub(str, '^%s*', '')
string = gsub(string, '%s*$', '') str = gsub(str, '%s*$', '')
return string return str
end end
function public.inventory() function public.inventory()
@@ -203,51 +207,6 @@ function public.key(value, t)
end end
end end
local GSC_GOLD = "ffd100"
local GSC_SILVER = "e6e6e6"
local GSC_COPPER = "c8602c"
local GSC_RED = "ff0000"
local GSC_3 = "|cff"..GSC_GOLD.."%d|cff000000.|cff"..GSC_SILVER.."%02d|cff000000.|cff"..GSC_COPPER.."%02d|r"
local GSC_2 = "|cff"..GSC_SILVER.."%d|cff000000.|cff"..GSC_COPPER.."%02d|r"
local GSC_1 = "|cff"..GSC_COPPER.."%d|r"
local GSC_3N = "|cff"..GSC_RED.."(|cff"..GSC_GOLD.."%d|cff000000.|cff"..GSC_SILVER.."%02d|cff000000.|cff"..GSC_COPPER.."%02d|cff"..GSC_RED..")|r"
local GSC_2N = "|cff"..GSC_RED.."(|cff"..GSC_SILVER.."%d|cff000000.|cff"..GSC_COPPER.."%02d|cff"..GSC_RED..")|r"
local GSC_1N = "|cff"..GSC_RED.."(|cff"..GSC_COPPER.."%d|cff"..GSC_RED..")|r"
function public.money_string(money)
money = floor(tonumber(money) or 0)
local negative = money < 0
money = abs(money)
local g = floor(money / 10000)
money = money - g * 10000
local s = floor(money / 100)
money = money - s * 100
local c = money
if g > 0 then
if negative then
return format(GSC_3N, g, s, c)
else
return format(GSC_3, g, s, c)
end
elseif s > 0 then
if negative then
return format(GSC_2N, s, c)
else
return format(GSC_2, s, c)
end
else
if negative then
return format(GSC_1N, c)
else
return format(GSC_1, c)
end
end
end
function public.group_by(tables, equal) function public.group_by(tables, equal)
local groups = {} local groups = {}
for _, table in ipairs(tables) do for _, table in ipairs(tables) do