Fix handling of zero replays found

This commit is contained in:
Jylpah committed 2020-05-16 02:46:09 +03:00
1 parent 01e01f3077
commit d9d56670fd
1 file changed
+16 -7
+16 -7
View File
@@ -575,7 +575,7 @@ async def main(argv):
bu.debug('Waiting for the replay scanner to finish') bu.debug('Waiting for the replay scanner to finish')
await asyncio.wait([scanner_task]) await asyncio.wait([scanner_task])
bu.debug('Scanner finished. Waiting for replay readers to finish the queue') # bu.debug('Scanner finished. Waiting for replay readers to finish the queue')
await replayQ.join() await replayQ.join()
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
bu.debug('Replays read. Cancelling Readers and analyzing results') bu.debug('Replays read. Cancelling Readers and analyzing results')
@@ -587,6 +587,8 @@ async def main(argv):
for res in await asyncio.gather(*reader_tasks): for res in await asyncio.gather(*reader_tasks):
results.extend(res[0]) results.extend(res[0])
players.update(res[1]) players.update(res[1])
if len(players) == 0:
raise Exception("No players found to fetch stats for. No replays found?")
(player_stats, stat_id_map) = await process_player_stats(players, OPT_WORKERS_N, args, db) (player_stats, stat_id_map) = await process_player_stats(players, OPT_WORKERS_N, args, db)
bu.verbose('') bu.verbose('')
@@ -1024,7 +1026,7 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto
"""Create queue of replays to post""" """Create queue of replays to post"""
p_replayfile = re.compile('.*\\.wotbreplay\\.json$') p_replayfile = re.compile('.*\\.wotbreplay\\.json$')
files = args.files files = args.files
Nreplays = 0
if files[0] == 'db:': if files[0] == 'db:':
if db == None: if db == None:
bu.error('No database connection opened') bu.error('No database connection opened')
@@ -1044,6 +1046,7 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto
async for replay_json in cursor: async for replay_json in cursor:
#bu.debug(json.dumps(replay_json, indent=2)) #bu.debug(json.dumps(replay_json, indent=2))
await queue.put(await mk_readerQ_item(replay_json)) await queue.put(await mk_readerQ_item(replay_json))
Nreplays += 1
bu.debug('All the matching replays have been read from the DB') bu.debug('All the matching replays have been read from the DB')
except Exception as err: except Exception as err:
bu.error(exception=err) bu.error(exception=err)
@@ -1069,8 +1072,9 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto
fn = fn[:-1] fn = fn[:-1]
if os.path.isfile(fn) and (p_replayfile.match(fn) != None): if os.path.isfile(fn) and (p_replayfile.match(fn) != None):
replay_json = await bu.open_JSON(fn, wi.chk_JSON_replay) replay_json = await bu.open_JSON(fn, wi.chk_JSON_replay)
await queue.put(await mk_readerQ_item(fn)) await queue.put(await mk_readerQ_item(replay_json))
bu.debug('File added to queue: ' + fn) bu.debug('File added to queue: ' + fn)
Nreplays += 1
elif os.path.isdir(fn): elif os.path.isdir(fn):
with os.scandir(fn) as dirEntry: with os.scandir(fn) as dirEntry:
for entry in dirEntry: for entry in dirEntry:
@@ -1079,10 +1083,11 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto
replay_json = await bu.open_JSON(entry.path, wi.chk_JSON_replay) replay_json = await bu.open_JSON(entry.path, wi.chk_JSON_replay)
await queue.put(await mk_readerQ_item(replay_json)) await queue.put(await mk_readerQ_item(replay_json))
bu.debug('File added to queue: ' + entry.path) bu.debug('File added to queue: ' + entry.path)
Nreplays += 1
except Exception as err: except Exception as err:
bu.error(exception=err) bu.error(exception=err)
bu.debug('Finished: ' + str(queue.qsize()) + ' replays to process') bu.verbose('Finished scanning replays: ' + str(Nreplays) + ' replays to process')
return None return Nreplays
async def mk_readerQ_item(replay_json) -> list: async def mk_readerQ_item(replay_json) -> list:
@@ -1175,8 +1180,12 @@ async def read_replay_JSON(replay_json: dict, args : argparse.Namespace) -> dict
for key in replay_summary_flds: for key in replay_summary_flds:
result[key] = replay_json['data']['summary'][key] result[key] = replay_json['data']['summary'][key]
except Exception as err:
bu.error(exception=err)
return None
try:
bu.debug('Part 2')
result['allies'] = set() result['allies'] = set()
result['enemies'] = set() result['enemies'] = set()
btl_duration = 0 btl_duration = 0