refactoring
This commit is contained in:
@@ -72,7 +72,7 @@ function public.value(item_key)
|
||||
local weighted_values = {}
|
||||
local total_weight = 0
|
||||
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
|
||||
tinsert(weighted_values, {value = data_point.market_value, weight = weight})
|
||||
end
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ function private.post_auction(slot, k)
|
||||
ClickAuctionSellItemButton()
|
||||
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()
|
||||
m.state.posted = m.state.posted + 1
|
||||
|
||||
@@ -117,7 +117,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
||||
end
|
||||
if aux_tooltip_daily then
|
||||
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
|
||||
|
||||
|
||||
@@ -406,10 +406,6 @@ function private.on_auction_house_closed()
|
||||
AuxFrame:Hide()
|
||||
end
|
||||
|
||||
function public.round(v)
|
||||
return floor(v + 0.5)
|
||||
end
|
||||
|
||||
function public.min_bid_increment(current_bid)
|
||||
return max(1, floor(current_bid / 100) * 5)
|
||||
end
|
||||
|
||||
@@ -520,9 +520,9 @@ function private.record_percentage(record)
|
||||
local historical_value = Aux.history.value(record.item_key) or 0
|
||||
if historical_value > 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
|
||||
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
|
||||
|
||||
|
||||
+6
-6
@@ -144,9 +144,9 @@ function private.update_auction_listing()
|
||||
{ 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=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 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,
|
||||
})
|
||||
@@ -189,12 +189,12 @@ function private.price_update()
|
||||
local start_price_input = m.get_unit_start_price()
|
||||
settings.start_price = start_price_input
|
||||
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()
|
||||
settings.buyout_price = buyout_price_input
|
||||
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)
|
||||
end
|
||||
@@ -327,8 +327,8 @@ function private.update_item_configuration()
|
||||
end
|
||||
|
||||
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 buyout_price = Aux.round(record.unit_buyout_price * (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.util.round(record.unit_buyout_price * (stack and record.stack_size or stack_size))
|
||||
|
||||
if not record.own then
|
||||
start_price = max(0, start_price - 1)
|
||||
|
||||
@@ -432,13 +432,13 @@ end
|
||||
|
||||
function private.blizzard_page_index(str)
|
||||
if tonumber(str) then
|
||||
return Aux.round(max(0, tonumber(str) - 1))
|
||||
return Aux.util.round(max(0, tonumber(str) - 1))
|
||||
end
|
||||
end
|
||||
|
||||
function private.blizzard_level(str)
|
||||
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
|
||||
|
||||
@@ -872,7 +872,7 @@ function private.add_post_component()
|
||||
local filter = name
|
||||
if not Aux.filter.filters[name] and filter == 'and' or filter == 'or' then
|
||||
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
|
||||
Aux.log('Invalid operator suffix')
|
||||
return
|
||||
|
||||
+21
-62
@@ -19,24 +19,28 @@ function public.product(...)
|
||||
return x
|
||||
end
|
||||
|
||||
function public.id(value)
|
||||
return value
|
||||
function public.id(x)
|
||||
return x
|
||||
end
|
||||
|
||||
function public.const(value)
|
||||
function public.const(x)
|
||||
return function()
|
||||
return value
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
function public.size(table)
|
||||
function public.size(t)
|
||||
local x = 0
|
||||
for _ in table do
|
||||
for _ in t do
|
||||
x = x + 1
|
||||
end
|
||||
return x
|
||||
end
|
||||
|
||||
function public.round(x)
|
||||
return floor(x + 0.5)
|
||||
end
|
||||
|
||||
function public.eq(t1, t2)
|
||||
if not t1 or not t2 then
|
||||
return false
|
||||
@@ -57,18 +61,18 @@ function public.eq(t1, t2)
|
||||
return true
|
||||
end
|
||||
|
||||
function public.wipe(table)
|
||||
while getn(table) > 0 do
|
||||
tremove(table)
|
||||
function public.wipe(t)
|
||||
while getn(t) > 0 do
|
||||
tremove(t)
|
||||
end
|
||||
for k, _ in table do
|
||||
table[k] = nil
|
||||
for k, _ in t do
|
||||
t[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function public.copy(table)
|
||||
function public.copy(t)
|
||||
local copy = {}
|
||||
for k, v in table do
|
||||
for k, v in t do
|
||||
copy[k] = v
|
||||
end
|
||||
return copy
|
||||
@@ -80,10 +84,10 @@ function public.cons(element, list)
|
||||
return new_list
|
||||
end
|
||||
|
||||
function public.trim(string)
|
||||
string = gsub(string, '^%s*', '')
|
||||
string = gsub(string, '%s*$', '')
|
||||
return string
|
||||
function public.trim(str)
|
||||
str = gsub(str, '^%s*', '')
|
||||
str = gsub(str, '%s*$', '')
|
||||
return str
|
||||
end
|
||||
|
||||
function public.inventory()
|
||||
@@ -203,51 +207,6 @@ function public.key(value, t)
|
||||
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)
|
||||
local groups = {}
|
||||
for _, table in ipairs(tables) do
|
||||
|
||||
Reference in New Issue
Block a user