better buy reporting and some refactoring

This commit is contained in:
Simon Hirsig
2015-09-27 18:39:21 +02:00
parent 348d965d33
commit baab07d496
2 changed files with 64 additions and 37 deletions
+58 -31
View File
@@ -1,9 +1,9 @@
Aux.buy = {} Aux.buy = {}
local record_auction, createOrder, updateOrder local record_auction, createOrder, updateOrder, set_message, report
local entries local entries
local selectedEntries = {} local selectedEntries = {}
local searchQuery local search_query
----------------------------------------- -----------------------------------------
@@ -17,23 +17,27 @@ end
----------------------------------------- -----------------------------------------
function AuxBuySearchButton_OnClick() function AuxBuySearchButton_OnClick()
entries = nil entries = nil
selectedEntries = {} selectedEntries = {}
Aux_Buy_ScrollbarUpdate() Aux_Buy_ScrollbarUpdate()
searchQuery = Aux.scan.create_query{
search_query = Aux.scan.create_query{
name = AuxBuySearchBox:GetText(), name = AuxBuySearchBox:GetText(),
exactMatch = true, exactMatch = true,
} }
Aux.buy.set_message('Scanning auctions ...')
set_message('Scanning auctions ...')
Aux.scan.start{ Aux.scan.start{
query = searchQuery, query = search_query,
on_start_page = function(i) on_start_page = function(i)
Aux.buy.set_message('Scanning auctions: page ' .. i .. ' ...') set_message('Scanning auctions: page ' .. i .. ' ...')
end, end,
on_read_auction = function(i) on_read_auction = function(i)
local auction_item = Aux.info.auction_item(i) local auction_item = Aux.info.auction_item(i)
local stack_size = auction_item.charges or auction_item.count local stack_size = auction_item.charges or auction_item.count
if auction_item.name == searchQuery.name then if auction_item.name == search_query.name then
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink) record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
end end
end, end,
@@ -65,7 +69,7 @@ end
----------------------------------------- -----------------------------------------
function Aux.buy.set_message(msg) function set_message(msg)
AuxBuyMessage:SetText(msg) AuxBuyMessage:SetText(msg)
AuxBuyMessage:Show() AuxBuyMessage:Show()
end end
@@ -74,23 +78,27 @@ end
function AuxBuyBuySelectedButton_OnClick() function AuxBuyBuySelectedButton_OnClick()
AuxBuySearchButton:Disable()
AuxBuyBuySelectedButton:Disable()
local order = createOrder(selectedEntries) local order = createOrder(selectedEntries)
local orderedCount = Aux_SetSize(selectedEntries) local orderedCount = Aux_SetSize(selectedEntries)
local purchasedCount = 0
entries = nil entries = nil
selectedEntries = {} selectedEntries = {}
Aux_Buy_ScrollbarUpdate() Aux_Buy_ScrollbarUpdate()
AuxBuySearchButton:Disable()
AuxBuyBuySelectedButton:Disable()
Aux.buy.set_message('Scanning auctions ...') local progress = {
auctions = 0,
units = 0,
expense = 0,
}
set_message('Scanning auctions ...')
Aux.scan.start{ Aux.scan.start{
query = searchQuery, query = search_query,
on_start_page = function(i) on_start_page = function(i)
Aux.buy.set_message('Scanning auctions: page ' .. i .. ' ...') set_message('Scanning auctions: page ' .. i .. ' ...')
end, end,
on_read_auction = function(i) on_read_auction = function(i)
local auction_item = Aux.info.auction_item(i) local auction_item = Aux.info.auction_item(i)
@@ -101,7 +109,9 @@ function AuxBuyBuySelectedButton_OnClick()
if GetMoney() >= auction_item.buyout_price then if GetMoney() >= auction_item.buyout_price then
PlaceAuctionBid("list", i, auction_item.buyout_price) PlaceAuctionBid("list", i, auction_item.buyout_price)
purchasedCount = purchasedCount + 1 progress.auctions = progress.auctions + 1
progress.units = progress.units + auction_item.count
progress.expense = progress.expense + auction_item.buyout_price
end end
if order[key] > 1 then if order[key] > 1 then
@@ -111,7 +121,7 @@ function AuxBuyBuySelectedButton_OnClick()
end end
else else
local stack_size = auction_item.charges or auction_item.count local stack_size = auction_item.charges or auction_item.count
if auction_item.name == searchQuery.name then if auction_item.name == search_query.name then
record_auction(auction_item.name, stack_size, auction_item.charges, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink) record_auction(auction_item.name, stack_size, auction_item.charges, auction_item.buyout_price, auction_item.quality, auction_item.owner, auction_item.itemlink)
end end
end end
@@ -121,12 +131,12 @@ function AuxBuyBuySelectedButton_OnClick()
entries = entries or {} entries = entries or {}
Aux_Buy_ScrollbarUpdate() Aux_Buy_ScrollbarUpdate()
AuxBuySearchButton:Enable() AuxBuySearchButton:Enable()
Aux_Buy_ShowReport(true, orderedCount, purchasedCount) report(true, search_query.name, orderedCount, progress)
end, end,
on_abort = function() on_abort = function()
entries = nil entries = nil
AuxBuySearchButton:Enable() AuxBuySearchButton:Enable()
Aux_Buy_ShowReport(false, orderedCount, purchasedCount) report(false, search_query.name, orderedCount, progress)
end end
} }
end end
@@ -188,7 +198,7 @@ end
function Aux_Buy_ScrollbarUpdate() function Aux_Buy_ScrollbarUpdate()
if entries and getn(entries) == 0 then if entries and getn(entries) == 0 then
Aux.buy.set_message("No auctions were found") set_message("No auctions were found")
else else
AuxBuyMessage:Hide() AuxBuyMessage:Hide()
end end
@@ -258,17 +268,34 @@ function Aux_Buy_ScrollbarUpdate()
end end
end end
function Aux_Buy_ShowReport(completed, orderedCount, purchasedCount) function report(completed, item_name, ordered_count, progress)
AuxBuyReport:Show() AuxBuyReport:Show()
AuxBuyReportHTML:SetText("<html><body>" AuxBuyReportHTML:SetText(string.format(
.."<h1>Aux Buy Report</h1><br/>" [[
.."<h1>Status: "..(completed and "Completed" or "Aborted").."</h1><br/>" <html>
.."<p>" <body>
..string.format("%i out of the %i ordered auctions have been purchased", purchasedCount, orderedCount) <h1>Aux Buy Report</h1><br/>
.."</p>" <h1>Exit status: %s</h1><br/>
.."</body></html>") <p>
%i out of %i ordered auctions for %s purchased
</p>
<p>
Total units purchased: %i
</p>
<p>
Total expense: %i
</p>
</body>
</html>
]],
completed and 'Completed' or 'Aborted',
progress.auctions,
ordered_count,
progress.units,
progress.expense
))
AuxBuyReportHTML:SetSpacing(3) AuxBuyReportHTML:SetSpacing(3)
end end
end end
+6 -6
View File
@@ -10,7 +10,7 @@ local currentAuction
----------------------------------------- -----------------------------------------
local record_auction, undercut, ItemType2AuctionClass, SubType2AuctionSubclass local record_auction, undercut, ItemType2AuctionClass, SubType2AuctionSubclass, set_message
----------------------------------------- -----------------------------------------
@@ -111,7 +111,7 @@ end
----------------------------------------- -----------------------------------------
function Aux.sell.set_message(msg) function set_message(msg)
Aux_HideElems(Aux.tabs.sell.recommendationElements) Aux_HideElems(Aux.tabs.sell.recommendationElements)
AuxMessage:SetText(msg) AuxMessage:SetText(msg)
AuxMessage:Show() AuxMessage:Show()
@@ -156,7 +156,7 @@ function Aux_UpdateRecommendation()
Aux_Sell_SetStackSize(0) Aux_Sell_SetStackSize(0)
Aux_Sell_SetStackCount(0) Aux_Sell_SetStackCount(0)
Aux.sell.set_message("Drag an item to the Auction Item area\n\nto see recommended pricing information") set_message("Drag an item to the Auction Item area\n\nto see recommended pricing information")
else else
AuxSellRefreshButton:Enable() AuxSellRefreshButton:Enable()
@@ -209,7 +209,7 @@ function Aux_UpdateRecommendation()
AuxRecommendBasisText:SetText("(based on auction selected below)") AuxRecommendBasisText:SetText("(based on auction selected below)")
end end
elseif auxSellEntries[currentAuction.name] then elseif auxSellEntries[currentAuction.name] then
Aux.sell.set_message("No auctions were found for \n\n"..currentAuction.name) set_message("No auctions were found for \n\n"..currentAuction.name)
auxSellEntries[currentAuction.name] = nil auxSellEntries[currentAuction.name] = nil
else else
Aux_HideElems(Aux.tabs.sell.shownElements) Aux_HideElems(Aux.tabs.sell.shownElements)
@@ -298,7 +298,7 @@ function Aux_RefreshEntries()
local currentAuctionClass = ItemType2AuctionClass(sType) local currentAuctionClass = ItemType2AuctionClass(sType)
local currentAuctionSubclass = nil -- SubType2AuctionSubclass(currentAuctionClass, sSubType) local currentAuctionSubclass = nil -- SubType2AuctionSubclass(currentAuctionClass, sSubType)
Aux.sell.set_message('Scanning auctions ...') set_message('Scanning auctions ...')
Aux.scan.start{ Aux.scan.start{
query = Aux.scan.create_query{ query = Aux.scan.create_query{
name = name, name = name,
@@ -306,7 +306,7 @@ function Aux_RefreshEntries()
subclassIndex = currentAuctionSubclass subclassIndex = currentAuctionSubclass
}, },
on_start_page = function(i) on_start_page = function(i)
Aux.sell.set_message('Scanning auctions: page ' .. i .. ' ...') set_message('Scanning auctions: page ' .. i .. ' ...')
end, end,
on_read_auction = function(i) on_read_auction = function(i)
local auction_item = Aux.info.auction_item(i) local auction_item = Aux.info.auction_item(i)