mirror of
https://github.com/Jylpah/blitz-tools.git
synced 2026-10-24 19:49:52 +02:00
filter_results() bug fix
This commit is contained in:
1 parent
dc8f9a233d
commit
9117963085
1 file changed
+26
-10
+26
-10
@@ -326,7 +326,6 @@ class BattleCategorizationList():
|
|||||||
self.urls = collections.OrderedDict()
|
self.urls = collections.OrderedDict()
|
||||||
self.url_title_max_len = 0
|
self.url_title_max_len = 0
|
||||||
|
|
||||||
|
|
||||||
cats = list(set(cats)) # remove duplicates
|
cats = list(set(cats)) # remove duplicates
|
||||||
# ordering
|
# ordering
|
||||||
self.categorizations_list = [ cat for cat in self._categorizations if cat in cats ]
|
self.categorizations_list = [ cat for cat in self._categorizations if cat in cats ]
|
||||||
@@ -355,6 +354,11 @@ class BattleCategorizationList():
|
|||||||
bu.error('BattleCategorizationList()', exception=err)
|
bu.error('BattleCategorizationList()', exception=err)
|
||||||
|
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
"""Returns the Iterator object"""
|
||||||
|
return BattleCategorizationListIterator(self)
|
||||||
|
|
||||||
|
|
||||||
def get_categorization(self, cat: str):
|
def get_categorization(self, cat: str):
|
||||||
"""Return a BattleCategorization for a category"""
|
"""Return a BattleCategorization for a category"""
|
||||||
try:
|
try:
|
||||||
@@ -458,6 +462,20 @@ class BattleCategorizationList():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class BattleCategorizationListIterator():
|
||||||
|
def __init__(self, btl_cats: BattleCategorizationList) -> None:
|
||||||
|
self._btl_cats = btl_cats
|
||||||
|
self._ndx = 0
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
if self._ndx < len(self._btl_cats.categorizations_list):
|
||||||
|
cat = self._btl_cats.categorizations_list[self._ndx]
|
||||||
|
res = self._btl_cats.categorizations[cat]
|
||||||
|
self._ndx += 1
|
||||||
|
return res
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
class BattleCategorization():
|
class BattleCategorization():
|
||||||
|
|
||||||
RESULT_CAT_HEADER_LEN = 15
|
RESULT_CAT_HEADER_LEN = 15
|
||||||
@@ -1783,7 +1801,7 @@ def process_battle_results(results: dict, args : argparse.Namespace):
|
|||||||
try:
|
try:
|
||||||
url = args.url
|
url = args.url
|
||||||
cats = BattleCategorizationList.get_categorizations(args)
|
cats = BattleCategorizationList.get_categorizations(args)
|
||||||
|
blt_cat_list= None
|
||||||
|
|
||||||
if args.filters != None:
|
if args.filters != None:
|
||||||
results = filter_results(results, args.filters)
|
results = filter_results(results, args.filters)
|
||||||
@@ -1811,19 +1829,18 @@ def filter_results(results: list, filter_json : str) -> bool:
|
|||||||
try:
|
try:
|
||||||
filters = json.loads(filter_json)
|
filters = json.loads(filter_json)
|
||||||
bu.debug(str(filters))
|
bu.debug(str(filters))
|
||||||
for filter in filters:
|
|
||||||
if type(filters[filter]) != list:
|
|
||||||
filters[filter] = [ filters[filter]]
|
|
||||||
|
|
||||||
if type(filters) != dict:
|
if type(filters) != dict:
|
||||||
bu.error('invalid --filter arguments: ' + str(filters))
|
bu.error('invalid --filter arguments: ' + str(filter))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
filter_cats = BattleCategorizationList(filters.keys())
|
filter_cats = BattleCategorizationList(filters.keys())
|
||||||
for cat in filters:
|
bu.verbose('Filters applied:')
|
||||||
|
for category in filter_cats:
|
||||||
|
cat = category.category_key
|
||||||
categorization = filter_cats.get_categorization(cat)
|
categorization = filter_cats.get_categorization(cat)
|
||||||
filters[cat] = categorization.get_filter_categories(filters[cat])
|
filters[cat] = categorization.get_filter_categories(filters[cat])
|
||||||
bu.verbose('Filter: ' + cat + ': ' + ','.join(filters[cat]))
|
bu.verbose(' ' + cat + ' = ' + ','.join(filters[cat]))
|
||||||
|
bu.verbose('')
|
||||||
|
|
||||||
res = list()
|
res = list()
|
||||||
for result in results:
|
for result in results:
|
||||||
@@ -2384,7 +2401,6 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto
|
|||||||
Nreplays += 1
|
Nreplays += 1
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
bu.error(exception=err)
|
bu.error(exception=err)
|
||||||
bu.verbose('Finished scanning replays: ' + str(Nreplays) + ' replays to process')
|
|
||||||
return Nreplays
|
return Nreplays
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user