implemented multi query search functionality

This commit is contained in:
Manuel Simon Hirsig
2016-01-27 22:24:17 +01:00
parent 5f66b96185
commit 912ae0125e
9 changed files with 159 additions and 118 deletions
+18 -16
View File
@@ -166,19 +166,26 @@ function public.update_auction_records()
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
local current_page
auction_records = {}
Aux.scan.start{
type = 'owner',
page = 0,
queries = {
{
type = 'owner',
start_page = 0,
next_page = function(page, total_pages)
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end,
}
},
on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages)
private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages))
current_page = page
end,
on_read_auction = function(auction_info)
tinsert(auction_records, private.create_auction_record(auction_info, current_page))
tinsert(auction_records, private.create_auction_record(auction_info))
end,
on_complete = function()
private.status_bar:update_status(100, 100)
@@ -189,12 +196,6 @@ function public.update_auction_records()
private.status_bar:update_status(100, 100)
private.status_bar:set_text('Done Scanning')
end,
next_page = function(page, total_pages)
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end,
}
end
@@ -209,7 +210,7 @@ function private.update_listing()
AuxFrame:SetWidth(AuxAuctionsFrameListing:GetWidth() + 15)
end
function private.create_auction_record(auction_info, page)
function private.create_auction_record(auction_info)
local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil
@@ -221,7 +222,8 @@ function private.create_auction_record(auction_info, page)
end
return {
page = page,
query = auction_info.query,
page = auction_info.page,
item_id = auction_info.item_id,
item_key = auction_info.item_key,
@@ -265,7 +267,7 @@ function private.process_request(entry, express_mode)
end
if express_mode then
Aux.scan_util.find('owner', test, {}, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.gone then
CancelAuction(index)
remove_entry()
@@ -274,7 +276,7 @@ function private.process_request(entry, express_mode)
else
private.select_auction(entry)
Aux.scan_util.find('owner', test, {}, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
private.cancel_button:SetScript('OnClick', function()
if test(index) and not entry.gone then
+18 -16
View File
@@ -181,19 +181,26 @@ function public.update_bid_records()
private.status_bar:update_status(0,0)
private.status_bar:set_text('Scanning auctions...')
local current_page
bid_records = {}
Aux.scan.start{
type = 'bidder',
page = 0,
queries = {
{
type = 'bidder',
start_page = 0,
next_page = function(page, total_pages)
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end,
}
},
on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages)
private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages))
current_page = page
end,
on_read_auction = function(auction_info)
tinsert(bid_records, private.create_auction_record(auction_info, current_page))
tinsert(bid_records, private.create_auction_record(auction_info))
end,
on_complete = function()
private.status_bar:update_status(100, 100)
@@ -204,12 +211,6 @@ function public.update_bid_records()
private.status_bar:update_status(100, 100)
private.status_bar:set_text('Done Scanning')
end,
next_page = function(page, total_pages)
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end,
}
end
@@ -224,7 +225,7 @@ function private.update_listing()
AuxFrame:SetWidth(AuxBidsFrameListing:GetWidth() + 15)
end
function private.create_auction_record(auction_info, page)
function private.create_auction_record(auction_info)
local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil
@@ -236,7 +237,8 @@ function private.create_auction_record(auction_info, page)
end
return {
page = page,
query = auction_info.query,
page = auction_info.page,
item_id = auction_info.item_id,
suffix_id = auction_info.suffix_id,
@@ -286,7 +288,7 @@ function private.process_request(entry, express_mode, buyout_mode)
end
if express_mode then
Aux.scan_util.find('bidder', test, {}, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.gone then
Aux.place_bid('bidder', index, buyout_mode and entry.buyout_price or entry.bid_price, remove_entry)
end
@@ -294,7 +296,7 @@ function private.process_request(entry, express_mode, buyout_mode)
else
private.select_auction(entry)
Aux.scan_util.find('bidder', test, {}, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.high_bidder then
private.bid_button:SetScript('OnClick', function()
+18 -19
View File
@@ -2,7 +2,6 @@ local private, public = {}, {}
Aux.filter_search_frame = public
local auctions
local search_query
local tooltip_patterns = {}
local refresh
local selected_auction
@@ -723,7 +722,17 @@ function public.start_search()
end
end
search_query = {
local query = {
type = 'list',
start_page = AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() and 0 or AuxFilterSearchFrameFiltersPageEditBox:GetNumber(),
next_page = function(page, total_pages)
if AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() then
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end
end,
name = AuxFilterSearchFrameFiltersNameInputBox:GetText(),
min_level = AuxFilterSearchFrameFiltersMinLevel:GetText(),
max_level = AuxFilterSearchFrameFiltersMaxLevel:GetText(),
@@ -734,10 +743,8 @@ function public.start_search()
usable = AuxFilterSearchFrameFiltersUsableCheckButton:GetChecked()
}
local current_page
Aux.scan.start{
query = search_query,
queries = { query },
page = AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() and 0 or AuxFilterSearchFrameFiltersPageEditBox:GetNumber(),
on_submit_query = function()
current_page = nil
@@ -745,12 +752,11 @@ function public.start_search()
on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) -- TODO
private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages))
current_page = page
end,
on_read_auction = function(auction_info)
if Aux.info.tooltip_match(tooltip_patterns, auction_info.tooltip) then
auctions = auctions or {}
tinsert(auctions, private.create_auction_record(auction_info, current_page))
tinsert(auctions, private.create_auction_record(auction_info))
end
end,
on_complete = function()
@@ -770,14 +776,6 @@ function public.start_search()
AuxFilterSearchFrameFiltersSearchButton:Show()
refresh = true
end,
next_page = function(page, total_pages)
if AuxFilterSearchFrameFiltersAllPagesCheckButton:GetChecked() then
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end
end,
}
end)
end
@@ -802,7 +800,7 @@ function private.process_request(entry, express_mode, buyout_mode)
end
if express_mode then
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.gone then
Aux.place_bid('list', index, buyout_mode and entry.buyout_price or entry.bid_price, remove_entry)
end
@@ -810,7 +808,7 @@ function private.process_request(entry, express_mode, buyout_mode)
else
private.select_auction(entry)
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.high_bidder then
private.bid_button:SetScript('OnClick', function()
@@ -857,7 +855,7 @@ function private.on_row_click(datum, grouped)
end
end
function private.create_auction_record(auction_info, page)
function private.create_auction_record(auction_info)
local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil
local unit_buyout_price = buyout_price and Aux.round(auction_info.buyout_price / auction_info.aux_quantity)
@@ -871,7 +869,8 @@ function private.create_auction_record(auction_info, page)
end
return {
page = page,
query = auction_info.query,
page = auction_info.page,
item_id = auction_info.item_id,
suffix_id = auction_info.suffix_id,
+3
View File
@@ -0,0 +1,3 @@
function load_group(datastring)
local item_keys = Aux.persistence.deserialize(datastring, ',')
end
-2
View File
@@ -85,8 +85,6 @@ function public.auction(index, type)
local aux_quantity = charges or count
return {
index = index,
item_id = item_id,
suffix_id = suffix_id,
unique_id = unique_id,
+18 -19
View File
@@ -553,7 +553,17 @@ function public.start_search()
-- local class_index = Aux.item_class_index(item_info.class)
-- local subclass_index = class_index and Aux.item_subclass_index(class_index, item_info.subclass) -- TODO test if needed
search_query = {
local query = {
type = 'list',
start_page = AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() and 0 or AuxItemSearchFrameItemPageEditBox:GetNumber(),
next_page = function(page, total_pages)
if AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() then
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end
end,
name = item_info.name,
min_level = item_info.level,
min_level = item_info.level,
@@ -564,20 +574,16 @@ function public.start_search()
usable = item_info.usable,
}
local current_page
Aux.scan.start{
query = search_query,
page = AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() and 0 or AuxItemSearchFrameItemPageEditBox:GetNumber(),
queries = { query },
on_page_loaded = function(page, total_pages)
private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) -- TODO
private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages))
current_page = page
end,
on_read_auction = function(auction_info)
if auction_info.item_id == item_id then
auctions = auctions or {}
tinsert(auctions, private.create_auction_record(auction_info, current_page))
tinsert(auctions, private.create_auction_record(auction_info))
end
end,
on_complete = function()
@@ -598,14 +604,6 @@ function public.start_search()
AuxItemSearchFrameItemRefreshButton:Show()
refresh = true
end,
next_page = function(page, total_pages)
if AuxItemSearchFrameItemAllPagesCheckButton:GetChecked() then
local last_page = max(total_pages - 1, 0)
if page < last_page then
return page + 1
end
end
end,
}
end)
end
@@ -630,7 +628,7 @@ function private.process_request(entry, express_mode, buyout_mode)
end
if express_mode then
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.gone then
Aux.place_bid('list', index, buyout_mode and entry.buyout_price or entry.bid_price, remove_entry)
end
@@ -638,7 +636,7 @@ function private.process_request(entry, express_mode, buyout_mode)
else
private.select_auction(entry)
Aux.scan_util.find('list', test, search_query, entry.page, private.status_bar, remove_entry, function(index)
Aux.scan_util.find(test, entry.query, entry.page, private.status_bar, remove_entry, function(index)
if not entry.high_bidder then
private.bid_button:SetScript('OnClick', function()
@@ -685,7 +683,7 @@ function private.on_row_click(datum, grouped)
end
end
function private.create_auction_record(auction_info, page)
function private.create_auction_record(auction_info)
local buyout_price = auction_info.buyout_price > 0 and auction_info.buyout_price or nil
local unit_buyout_price = buyout_price and Aux.round(auction_info.buyout_price / auction_info.aux_quantity)
@@ -699,7 +697,8 @@ function private.create_auction_record(auction_info, page)
end
return {
page = page,
query = auction_info.query,
page = auction_info.page,
item_id = auction_info.item_id,
suffix_id = auction_info.suffix_id,
+61 -42
View File
@@ -13,22 +13,25 @@ end)()
local state
local scan, scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, wait_for_owner_data, on_abort
local scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, wait_for_owner_data, on_abort, current_query
function Aux.scan.start(job)
function current_query()
return state.params.queries[state.query_index]
end
function public.start(params)
return controller().wait(function() return true end, function()
on_abort()
job.type = job.type or 'list'
state = {
job = job,
page = job.page
params = params,
}
scan()
private.scan()
end)
end
function Aux.scan.abort(k)
function public.abort(k)
return controller().wait(function() return true end, function()
on_abort()
@@ -41,19 +44,19 @@ function Aux.scan.abort(k)
end
function on_abort()
if state and state.job and state.job.on_abort then
state.job.on_abort()
if state and state.params and state.params.on_abort then
state.params.on_abort()
end
state = nil
end
function wait_for_results(k)
local ok
if state.job.type == 'bidder' then
if current_query().type == 'bidder' then
Aux.control.as_soon_as(function() return Aux.bids_loaded end, function()
ok = true
end)
elseif state.job.type == 'owner' then
elseif current_query().type == 'owner' then
if state.page == Aux.current_owner_page then
ok = true
else
@@ -76,9 +79,9 @@ function wait_for_owner_data(k)
if time() - t0 > 5 then -- we won't wait longer than 5 seconds
return true
end
local count, _ = GetNumAuctionItems(state.job.type)
local count, _ = GetNumAuctionItems(state.params.type)
for i=1,count do
local auction_info = Aux.info.auction(i, state.job.type)
local auction_info = Aux.info.auction(i, state.params.type)
if auction_info and not auction_info.owner then
return false
end
@@ -108,25 +111,36 @@ function wait_for_callback(args) -- the arguments must not be nil!
end
end
function scan()
submit_query(function()
local count, _ = GetNumAuctionItems(state.job.type)
function private.scan()
state.query_index = state.query_index and state.query_index + 1 or 1
if current_query() then
state.page = current_query().start_page
return private.process_query()
else
if state.params.on_complete then
return state.params.on_complete()
end
end
end
function private.process_query()
submit_query(function()
local count, _ = GetNumAuctionItems(current_query().type)
scan_auctions(count, function()
state.page = state.job.next_page and state.job.next_page(state.page, state.total_pages)
state.page = current_query().next_page and current_query().next_page(state.page, state.total_pages)
if state.page then
return scan()
return private.process_query()
else
if state.job.on_complete then
state.job.on_complete()
end
state = nil
return private.scan()
end
end)
end)
end
@@ -144,14 +158,19 @@ function scan_auctions_helper(i, n, k)
end
end
local auction_info = Aux.info.auction(i, state.job.type)
local auction_info = Aux.info.auction(i, current_query().type)
if auction_info then
auction_info.index = i
auction_info.page = state.page
auction_info.query = current_query()
local snapshot = Aux.persistence.load_snapshot()
if not snapshot.contains(auction_info.signature) then
snapshot.add(auction_info.signature, auction_info.duration)
Aux.history.process_auction(auction_info)
end
wait_for_callback{state.job.on_read_auction or Aux.util.pass, auction_info, recurse}
wait_for_callback{state.params.on_read_auction or Aux.util.pass, auction_info, recurse}
else
recurse()
end
@@ -159,17 +178,17 @@ end
function submit_query(k)
if state.page then
controller().wait(function() return state.job.type ~= 'list' or CanSendAuctionQuery() end, function()
controller().wait(function() return current_query().type ~= 'list' or CanSendAuctionQuery() end, function()
if state.job.on_submit_query then
state.job.on_submit_query()
if state.params.on_submit_query then
state.params.on_submit_query()
end
wait_for_results(function()
--wait_for_owner_data(function()
local _, total_count = GetNumAuctionItems(state.job.type)
local _, total_count = GetNumAuctionItems(current_query().type)
state.total_pages = math.ceil(total_count / PAGE_SIZE)
if state.total_pages >= state.page + 1 then
wait_for_callback{state.job.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function()
wait_for_callback{state.params.on_page_loaded or Aux.util.pass, state.page, state.total_pages, function()
return k()
end}
else
@@ -177,21 +196,21 @@ function submit_query(k)
end
-- end)
end)
if state.job.type == 'bidder' then
if current_query().type == 'bidder' then
GetBidderAuctionItems(state.page)
elseif state.job.type == 'owner' then
elseif current_query().type == 'owner' then
GetOwnerAuctionItems(state.page)
else
QueryAuctionItems(
state.job.query.name,
state.job.query.min_level,
state.job.query.max_level,
state.job.query.slot,
state.job.query.class,
state.job.query.subclass,
current_query().name,
current_query().min_level,
current_query().max_level,
current_query().slot,
current_query().class,
current_query().subclass,
state.page,
state.job.query.usable,
state.job.query.quality
current_query().usable,
current_query().quality
)
end
end)
+13 -3
View File
@@ -1,7 +1,7 @@
local m = {}
Aux.scan_util = m
function m.find(type, test, search_query, page, status_bar, on_failure, on_success)
function m.find(test, query, page, status_bar, on_failure, on_success)
Aux.scan.abort(function()
@@ -10,9 +10,19 @@ function m.find(type, test, search_query, page, status_bar, on_failure, on_succe
local pages = page > 0 and { page, page - 1 } or { page }
query = Aux.util.copy_table(query)
query.page = page
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
Aux.scan.start{
type = type,
query = search_query,
queries = { query },
on_read_auction = function(auction_info, ctrl)
if test(auction_info.index) then
ctrl.suspend()
+10 -1
View File
@@ -1,4 +1,5 @@
Aux.util = {}
local private, public = {}, {}
Aux.util = public
Aux.util.LT = {}
Aux.util.EQ = {}
@@ -9,6 +10,14 @@ local merge, copy_array
function Aux.util.pass()
end
function public.copy_table(table)
local copy = {}
for k, v in pairs(table) do
copy[k] = v
end
return copy
end
function Aux.util.inventory_iterator()
local inventory = {}
for bag = 0, 4 do