working on big scan/control refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-02-25 15:13:12 +01:00
parent b26c5dba08
commit 8d888f4e96
8 changed files with 182 additions and 174 deletions
+3 -3
View File
@@ -97,9 +97,9 @@ function public.scan_auctions()
selected_auction = nil selected_auction = nil
private.update_listing() private.update_listing()
Aux.scan.start{ Aux.scan.start{
type = 'owner',
queries = { queries = {
{ {
type = 'owner',
start_page = 0, start_page = 0,
} }
}, },
@@ -144,7 +144,7 @@ function private.find_auction_and_cancel(record)
return return
end end
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
if Aux.util.index_of(record, auction_records) then if Aux.util.index_of(record, auction_records) then
CancelAuction(index) CancelAuction(index)
private.record_remover(record)() private.record_remover(record)()
@@ -162,7 +162,7 @@ do
found_index = nil found_index = nil
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
found_index = index found_index = index
+3 -3
View File
@@ -117,9 +117,9 @@ function public.scan_bids()
selected_auction = nil selected_auction = nil
private.update_listing() private.update_listing()
Aux.scan.start{ Aux.scan.start{
type = 'bidder',
queries = { queries = {
{ {
type = 'bidder',
start_page = 0, start_page = 0,
} }
}, },
@@ -164,7 +164,7 @@ function private.find_auction_and_bid(record, buyout_mode)
return return
end end
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
if Aux.util.index_of(record, auction_records) then if Aux.util.index_of(record, auction_records) then
Aux.place_bid('bidder', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record)) Aux.place_bid('bidder', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
end end
@@ -181,7 +181,7 @@ do
found_index = nil found_index = nil
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
found_index = index found_index = index
+22 -26
View File
@@ -203,35 +203,31 @@ function Aux.on_auction_house_closed()
end end
function Aux.on_tab_click(index) function Aux.on_tab_click(index)
Aux.post.stop() Aux.search_frame.on_close()
Aux.stack.stop() Aux.post_frame.on_close()
Aux.scan.abort(function() Aux.auctions_frame.on_close()
Aux.search_frame.on_close() Aux.bids_frame.on_close()
Aux.post_frame.on_close()
Aux.auctions_frame.on_close()
Aux.bids_frame.on_close()
AuxSearchFrame:Hide() AuxSearchFrame:Hide()
AuxPostFrame:Hide() AuxPostFrame:Hide()
AuxAuctionsFrame:Hide() AuxAuctionsFrame:Hide()
AuxBidsFrame:Hide() AuxBidsFrame:Hide()
if index == 1 then if index == 1 then
AuxSearchFrame:Show() AuxSearchFrame:Show()
Aux.search_frame.on_open() Aux.search_frame.on_open()
elseif index == 2 then elseif index == 2 then
AuxPostFrame:Show() AuxPostFrame:Show()
Aux.post_frame.on_open() Aux.post_frame.on_open()
elseif index == 3 then elseif index == 3 then
AuxAuctionsFrame:Show() AuxAuctionsFrame:Show()
Aux.auctions_frame.on_open() Aux.auctions_frame.on_open()
elseif index == 4 then elseif index == 4 then
AuxBidsFrame:Show() AuxBidsFrame:Show()
Aux.bids_frame.on_open() Aux.bids_frame.on_open()
end end
Aux.active_panel = index Aux.active_panel = index
end)
end end
function Aux.round(v) function Aux.round(v)
+1
View File
@@ -778,6 +778,7 @@ function private.refresh_entries()
private.status_bar:set_text('Scanning auctions...') private.status_bar:set_text('Scanning auctions...')
Aux.scan.start{ Aux.scan.start{
type = 'list',
no_wait_owner = true, no_wait_owner = true,
queries = { query }, queries = { query },
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
+31 -21
View File
@@ -20,14 +20,19 @@ function current_query()
end end
function current_thread() function current_thread()
return threads[Aux.control.thread_id] for _, thread in pairs(threads) do
if thread.id == Aux.control.thread_id then
return thread
end
end
end end
function public.start(params) function public.start(params)
private.abort(params.type) private.abort(params.type)
local thread_id = Aux.control.new(private.scan) local thread_id = Aux.control.new(private.scan)
threads[thread_id] = { threads[params.type] = {
id = thread_id,
params = params, params = params,
} }
end end
@@ -41,13 +46,13 @@ function public.abort(k)
end end
function private.abort(type) function private.abort(type)
for thread_id, thread in pairs(threads) do for t, thread in pairs(threads) do
if not type or type == thread.type then if not type or type == t then
if thread.on_abort then if thread.params.on_abort then
thread.on_abort() thread.params.on_abort()
end end
threads[thread_id] = nil threads[t] = nil
Aux.control.kill(thread_id) Aux.control.kill(thread.id)
end end
end end
end end
@@ -61,11 +66,11 @@ function private.as_soon_as(p, k)
end end
function private.wait_for_results(k) function private.wait_for_results(k)
if current_thread().type == 'bidder' then if current_thread().params.type == 'bidder' then
return private.wait_for_bidder_results(k) return private.wait_for_bidder_results(k)
elseif current_thread().type == 'owner' then elseif current_thread().params.type == 'owner' then
return private.wait_for_owner_results(k) return private.wait_for_owner_results(k)
elseif current_thread().type == 'list' then elseif current_thread().params.type == 'list' then
return private.wait_for_list_results(k) return private.wait_for_list_results(k)
end end
end end
@@ -80,9 +85,13 @@ end
function private.wait_for_owner_results(k) function private.wait_for_owner_results(k)
local updated local updated
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function() if current_thread().page == Aux.current_owner_page then
updated = true updated = true
end) else
Aux.control.on_next_event('AUCTION_OWNED_LIST_UPDATE', function()
updated = true
end)
end
private.as_soon_as(function() return updated end, k) private.as_soon_as(function() return updated end, k)
end end
@@ -109,9 +118,9 @@ function private.owner_data_complete()
if current_thread().params.no_wait_owner then if current_thread().params.no_wait_owner then
return true return true
end end
local count, _ = GetNumAuctionItems(current_thread().type) local count, _ = GetNumAuctionItems(current_thread().params.type)
for i=1,count do for i=1,count do
local auction_info = Aux.info.auction(i, current_thread().type) local auction_info = Aux.info.auction(i, current_thread().params.type)
if auction_info and not auction_info.owner then if auction_info and not auction_info.owner then
return false return false
end end
@@ -164,7 +173,7 @@ function private.process_query()
submit_query(function() submit_query(function()
local count, _ = GetNumAuctionItems(current_thread().type) local count, _ = GetNumAuctionItems(current_thread().params.type)
scan_auctions(count, function() scan_auctions(count, function()
@@ -198,11 +207,12 @@ function scan_auctions_helper(i, n, k)
end end
end end
local auction_info = Aux.info.auction(i, current_thread().type) local auction_info = Aux.info.auction(i, current_thread().params.type)
if auction_info then if auction_info then
auction_info.index = i auction_info.index = i
auction_info.page = current_thread().page auction_info.page = current_thread().page
auction_info.query = current_query() auction_info.query = current_query()
auction_info.query_type = current_thread().params.type
Aux.history.process_auction(auction_info) Aux.history.process_auction(auction_info)
@@ -216,14 +226,14 @@ end
function submit_query(k) function submit_query(k)
if current_thread().page then if current_thread().page then
private.as_soon_as(function() return current_thread().type ~= 'list' or CanSendAuctionQuery() end, function() private.as_soon_as(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
if current_thread().params.on_submit_query then if current_thread().params.on_submit_query then
current_thread().params.on_submit_query() current_thread().params.on_submit_query()
end end
if current_thread().type == 'bidder' then if current_thread().params.type == 'bidder' then
GetBidderAuctionItems(current_thread().page) GetBidderAuctionItems(current_thread().page)
elseif current_thread().type == 'owner' then elseif current_thread().params.type == 'owner' then
GetOwnerAuctionItems(current_thread().page) GetOwnerAuctionItems(current_thread().page)
else else
QueryAuctionItems( QueryAuctionItems(
@@ -239,7 +249,7 @@ function submit_query(k)
) )
end end
private.wait_for_results(function() private.wait_for_results(function()
local _, total_count = GetNumAuctionItems(current_thread().type) local _, total_count = GetNumAuctionItems(current_thread().params.type)
current_thread().total_pages = math.ceil(total_count / PAGE_SIZE) current_thread().total_pages = math.ceil(total_count / PAGE_SIZE)
if current_thread().total_pages >= current_thread().page + 1 then if current_thread().total_pages >= current_thread().page + 1 then
wait_for_callback{current_thread().params.on_page_loaded or Aux.util.pass, current_thread().page, current_thread().total_pages, function() wait_for_callback{current_thread().params.on_page_loaded or Aux.util.pass, current_thread().page, current_thread().total_pages, function()
+1 -1
View File
@@ -22,8 +22,8 @@ function public.start_scan()
Aux.log('Scanning auctions ...') Aux.log('Scanning auctions ...')
Aux.scan.start{ Aux.scan.start{
type = 'list',
queries = {{ queries = {{
type = 'list',
start_page = 0, start_page = 0,
}}, }},
on_page_loaded = function(page, total_pages) on_page_loaded = function(page, total_pages)
+46 -43
View File
@@ -1,55 +1,59 @@
local m = {} local m = {}
Aux.scan_util = m Aux.scan_util = m
function m.find(test, query, page, status_bar, on_abort, on_failure, on_success) function m.find(auction_record, status_bar, on_abort, on_failure, on_success)
Aux.scan.abort(function() local function test(index)
local auction_info = Aux.info.auction(index, auction_record.query_type)
return auction_info and auction_info.search_signature == auction_record.search_signature
end
status_bar:update_status(0, 0) Aux.scan.abort(auction_record.query_type)
status_bar:set_text('Searching auction...')
local pages = page > 0 and { page, page - 1 } or { page } status_bar:update_status(0, 0)
status_bar:set_text('Searching auction...')
local new_query = { local pages = auction_record.page > 0 and { auction_record.page, auction_record.page - 1 } or { auction_record.page }
type = query.type,
validator = function(auction_info) return test(auction_info.index) end,
blizzard_query = query.blizzard_query,
next_page = function()
if getn(pages) == 1 then
status_bar:update_status(50, 50)
end
local page = pages[1]
tremove(pages, 1)
return page
end,
}
local found local query = {
Aux.scan.start{ validator = function(auction_info) return test(auction_info.index) end,
queries = { new_query }, blizzard_query = auction_record.query.blizzard_query,
on_read_auction = function(auction_info, ctrl) next_page = function()
if test(auction_info.index) then if getn(pages) == 1 then
found = true status_bar:update_status(50, 50)
ctrl.suspend() end
status_bar:update_status(100, 100) local page = pages[1]
status_bar:set_text('Auction found') tremove(pages, 1)
return on_success(auction_info.index) return page
end end,
end, }
on_abort = function()
if not found then local found
status_bar:update_status(100, 100) Aux.scan.start{
status_bar:set_text('Auction not found') type = auction_record.query_type,
return on_abort() queries = { query },
end on_read_auction = function(auction_info, ctrl)
end, if test(auction_info.index) then
on_complete = function() found = true
ctrl.suspend()
status_bar:update_status(100, 100)
status_bar:set_text('Auction found')
return on_success(auction_info.index)
end
end,
on_abort = function()
if not found then
status_bar:update_status(100, 100) status_bar:update_status(100, 100)
status_bar:set_text('Auction not found') status_bar:set_text('Auction not found')
return on_failure() return on_abort()
end, end
} end,
end) on_complete = function()
status_bar:update_status(100, 100)
status_bar:set_text('Auction not found')
return on_failure()
end,
}
end end
function m.create_item_query(item_id) function m.create_item_query(item_id)
@@ -59,7 +63,6 @@ function m.create_item_query(item_id)
if item_info then if item_info then
local filter = m.filter_from_string(item_info.name..'/exact') local filter = m.filter_from_string(item_info.name..'/exact')
return { return {
type = 'list',
start_page = 0, start_page = 0,
validator = m.validator(filter), validator = m.validator(filter),
blizzard_query = m.blizzard_query(filter), blizzard_query = m.blizzard_query(filter),
+75 -77
View File
@@ -767,94 +767,94 @@ end
end end
function public.stop_search() function public.stop_search()
Aux.scan.abort() Aux.scan.abort('list')
end end
function public.start_search(filter_string) function public.start_search(filter_string)
Aux.scan.abort(function() Aux.scan.abort('list')
if filter_string then
private.search_box:SetText(filter_string)
end
local queries if filter_string then
private.search_box:SetText(filter_string)
end
local filters = Aux.scan_util.parse_filter_string(private.search_box:GetText()) local queries
if filters then
queries = Aux.util.map(filters, function(filter)
return {
start_page = 0,
blizzard_query = Aux.scan_util.blizzard_query(filter),
validator = Aux.scan_util.validator(filter),
}
end)
else
return
end
tinsert(aux_recent_searches, 1, { filter_string = private.search_box:GetText(), prettified = private.prettify_search(private.search_box:GetText()) }) local filters = Aux.scan_util.parse_filter_string(private.search_box:GetText())
while getn(aux_recent_searches) > 50 do if filters then
tremove(aux_recent_searches) queries = Aux.util.map(filters, function(filter)
end return {
private.update_search_listings() start_page = 0,
blizzard_query = Aux.scan_util.blizzard_query(filter),
validator = Aux.scan_util.validator(filter),
}
end)
else
return
end
private.search_button:Hide() tinsert(aux_recent_searches, 1, { filter_string = private.search_box:GetText(), prettified = private.prettify_search(private.search_box:GetText()) })
private.stop_button:Show() while getn(aux_recent_searches) > 50 do
tremove(aux_recent_searches)
end
private.update_search_listings()
private.update_tab(RESULTS) private.search_button:Hide()
private.stop_button:Show()
private.status_bar:update_status(0,0) private.update_tab(RESULTS)
private.status_bar:set_text('Scanning auctions...')
private.results_listing:Clear() private.status_bar:update_status(0,0)
local scanned_records = {} private.status_bar:set_text('Scanning auctions...')
private.results_listing:SetDatabase(scanned_records)
local current_page, current_total_pages, current_query private.results_listing:Clear()
Aux.scan.start{ local scanned_records = {}
type = 'list', private.results_listing:SetDatabase(scanned_records)
queries = queries,
on_page_loaded = function(page, total_pages) local current_page, current_total_pages, current_query
current_page = page + 1 Aux.scan.start{
current_total_pages = total_pages type = 'list',
queries = queries,
on_page_loaded = function(page, total_pages)
current_page = page + 1
current_total_pages = total_pages
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages))
end,
on_page_scanned = function()
private.results_listing:SetDatabase()
end,
on_start_query = function(query_index)
current_query = query_index
if current_page then
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages)) private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages))
end, else
on_page_scanned = function() private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 0) -- TODO
private.results_listing:SetDatabase() private.status_bar:set_text(format('Scanning %d / %d', current_query, getn(queries)))
end, end
on_start_query = function(query_index) end,
current_query = query_index on_read_auction = function(auction_info)
if current_page then if getn(scanned_records) < 1000 then -- TODO static popup, remove discard
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page - 1) / current_total_pages) -- TODO tinsert(scanned_records, auction_info)
private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page, current_total_pages)) end
else end,
private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 0) -- TODO on_complete = function()
private.status_bar:set_text(format('Scanning %d / %d', current_query, getn(queries))) private.results_listing:SetDatabase()
end private.status_bar:update_status(100, 100)
end, private.status_bar:set_text('Done Scanning')
on_read_auction = function(auction_info)
if getn(scanned_records) < 1000 then -- TODO static popup, remove discard
tinsert(scanned_records, auction_info)
end
end,
on_complete = function()
private.results_listing:SetDatabase()
private.status_bar:update_status(100, 100)
private.status_bar:set_text('Done Scanning')
private.stop_button:Hide() private.stop_button:Hide()
private.search_button:Show() private.search_button:Show()
end, end,
on_abort = function() on_abort = function()
private.results_listing:SetDatabase() private.results_listing:SetDatabase()
private.status_bar:update_status(100, 100) private.status_bar:update_status(100, 100)
private.status_bar:set_text('Done Scanning') private.status_bar:set_text('Done Scanning')
private.stop_button:Hide() private.stop_button:Hide()
private.search_button:Show() private.search_button:Show()
end, end,
} }
end)
end end
function private.test(record) function private.test(record)
@@ -875,7 +875,7 @@ function private.find_auction_and_bid(record, buyout_mode)
return return
end end
Aux.scan_util.find(private.test(record), record.query, record.page, private.status_bar, Aux.util.pass, private.record_remover(record), function(index) Aux.scan_util.find(record, private.status_bar, Aux.util.pass, private.record_remover(record), function(index)
if private.results_listing:ContainsRecord(record) then if private.results_listing:ContainsRecord(record) then
Aux.place_bid('list', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record)) Aux.place_bid('list', index, buyout_mode and record.buyout_price or record.bid_price, private.record_remover(record))
end end
@@ -893,9 +893,7 @@ do
end end
Aux.scan_util.find( Aux.scan_util.find(
private.test(record), record,
record.query,
record.page,
private.status_bar, private.status_bar,
function() function()
state = IDLE state = IDLE