From fe7292a588b9ef9212396d3163893bb808a45f56 Mon Sep 17 00:00:00 2001 From: Jylpah Date: Thu, 26 Nov 2020 21:28:29 +0200 Subject: [PATCH 1/7] read_replay_id(): read _id from replay JSON --- blitzutils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/blitzutils.py b/blitzutils.py index 97157ab..119cb58 100755 --- a/blitzutils.py +++ b/blitzutils.py @@ -1747,6 +1747,16 @@ class WoTinspector: return url.rsplit('/', 1)[-1] + @classmethod + def read_replay_id(cls, json_replay): + """Read replay_id from replay JSON file""" + try: + url = json_replay['data']['view_url'] + return cls.get_replay_id(url) + except Exception as err: + error(exception=err) + return None + @classmethod def chk_JSON_replay(cls, json_resp): """"Check String for being a valid JSON file""" From c830955b6fe7b11f3d50bd2a0ce8eb0aefaa39c9 Mon Sep 17 00:00:00 2001 From: Jylpah Date: Thu, 26 Nov 2020 21:29:17 +0200 Subject: [PATCH 2/7] add _id to replays JSON read from the filesystem --- analyze_wotb_replays.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/analyze_wotb_replays.py b/analyze_wotb_replays.py index 1165345..e54925c 100755 --- a/analyze_wotb_replays.py +++ b/analyze_wotb_replays.py @@ -1960,7 +1960,7 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto if not line: break if (p_replayfile.match(line) != None): - replay_json = await bu.open_JSON(line, wi.chk_JSON_replay) + replay_json = await bu.open_JSON(line, wi.chk_JSON_replay) await queue.put(await mk_readerQ_item(replay_json, line)) except Exception as err: bu.error(exception=err) @@ -1993,7 +1993,13 @@ async def mk_replayQ(queue : asyncio.Queue, args : argparse.Namespace, db : moto async def mk_readerQ_item(replay_json, filename : str = None) -> list: """Make an item to replay queue""" global REPLAY_N - REPLAY_N +=1 + REPLAY_N +=1 + try: + if not '_id' in replay_json: + id = wi.read_replay_id(replay_json) + replay_json['_id'] = id + except Exception as err: + bu.error(exception=err) if filename == None: return [replay_json, REPLAY_N, '' ] elif RE_SRC_IS_DB.match(filename) != None: From 633a91cbab3ec76b37a91c6c361bea6a736ce959 Mon Sep 17 00:00:00 2001 From: Jylpah Date: Thu, 26 Nov 2020 23:59:48 +0200 Subject: [PATCH 3/7] renamed tank_str2name() --- upload_wotb_replays.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upload_wotb_replays.py b/upload_wotb_replays.py index 38b8db3..4f0619a 100755 --- a/upload_wotb_replays.py +++ b/upload_wotb_replays.py @@ -286,7 +286,7 @@ def getTitle(replayfile: str, title: str = None, i : int = 0) -> str: try: metadata_json = json.load(meta) #player = metadata_json['playerName'] - tank = wg.get_tank_name(metadata_json['playerVehicleName']) + tank = wg.tank_str2name(metadata_json['playerVehicleName']) map_name = wg.get_map(metadata_json['mapName']) bu.debug('Tank: ' + tank + ' Map: ' + map_name) except Exception as err: From 4f13fcbb96f1bd7fa99ba5e07c69023616c66e55 Mon Sep 17 00:00:00 2001 From: Jylpah Date: Fri, 27 Nov 2020 00:00:00 +0200 Subject: [PATCH 4/7] renamed WG.NATION --- extract_tankopedia.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extract_tankopedia.py b/extract_tankopedia.py index 4b7952d..ffe6de9 100755 --- a/extract_tankopedia.py +++ b/extract_tankopedia.py @@ -49,7 +49,7 @@ async def main(argv): wg = WG() tasks = [] - for nation in wg.NATIONS: + for nation in wg.NATION: tasks.append(asyncio.create_task(extract_tanks(args.blitz_app_base, nation))) tanklist = [] From dc4642304819da025db2239b38348e3ea5918cde Mon Sep 17 00:00:00 2001 From: Jylpah Date: Fri, 27 Nov 2020 00:00:30 +0200 Subject: [PATCH 5/7] WG.get_tank_xxx() funcs, renamed NATION --- blitzutils.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/blitzutils.py b/blitzutils.py index 119cb58..2590ca3 100755 --- a/blitzutils.py +++ b/blitzutils.py @@ -756,7 +756,8 @@ class WG: tanks = None tanks_by_tier = None - NATIONS = [ 'ussr', 'germany', 'usa', 'china', 'france', 'uk', 'japan', 'other', 'european'] + NATION = [ 'ussr', 'germany', 'usa', 'china', 'france', 'uk', 'japan', 'other', 'european'] + NATION_STR = [ 'Soviet', 'Germany', 'USA', 'China', 'France', 'UK', 'Japan', 'Other', 'European'] NATION_ID = { 'ussr' : 0, 'germany' : 1, @@ -769,7 +770,9 @@ class WG: 'european' : 8 } - TANK_TYPE = [ 'lightTank', 'mediumTank', 'heavyTank', 'AT-SPG' ] + TANK_TYPE = [ 'lightTank', 'mediumTank', 'heavyTank', 'AT-SPG' ] + TANK_TYPE_STR = [ 'Light Tank', 'Medium Tank', 'Heavy Tank', 'TD' ] + TANK_TYPE_ID = { 'lightTank' : 0, 'mediumTank' : 1, @@ -906,7 +909,7 @@ class WG: @classmethod - def get_tank_name(cls, tank_str: str) -> str: + def tank_str2name(cls, tank_str: str) -> str: """Return tank name from short tank string in replays""" try: return cls.tanks["userStr"][tank_str] @@ -1348,8 +1351,79 @@ class WG: return None - def get_tank_tier(self, tank_id: int): - return self.get_tank_data(tank_id, 'tier') + def get_tank_tier(self, tank_id: int) -> str: + try: + return self.get_tank_data(tank_id, 'tier') + except Exception as err: + error(exception=err) + return None + + + def get_tank_name(self, tank_id: int) -> str: + try: + return self.get_tank_data(tank_id, 'name') + except Exception as err: + error(exception=err) + return None + + + def get_tank_type(self, tank_id: int) -> str: + try: + return self.get_tank_data(tank_id, 'type') + except Exception as err: + error(exception=err) + return None + + + def get_tank_nation(self, tank_id: int) -> str: + try: + return self.get_tank_data(tank_id, 'nation') + except Exception as err: + error(exception=err) + return None + + + def get_tank_type_str(self, tank_id: int) -> str: + try: + tank_type = self.get_tank_data(tank_id, 'type') + return self.TANK_TYPE_STR[self.TANK_TYPE_ID[tank_type]] + except Exception as err: + error(exception=err) + return None + + + def get_tank_nation_str(self, tank_id: int) -> str: + try: + nation = self.get_tank_data(tank_id, 'nation') + return self.NATION_STR[self.NATION_ID[nation]] + except Exception as err: + error(exception=err) + return None + + + def get_tank_type_id(self, tank_id: int) -> str: + try: + tank_type = self.get_tank_data(tank_id, 'type') + return self.TANK_TYPE_ID[tank_type] + except Exception as err: + error(exception=err) + return None + + + def get_tank_nation_id(self, tank_id: int) -> str: + try: + nation = self.get_tank_data(tank_id, 'nation') + return self.NATION_ID[nation] + except Exception as err: + error(exception=err) + return None + + def is_premium(self, tank_id: int) -> bool: + try: + return self.get_tank_data(tank_id, 'is_premium') + except Exception as err: + error(exception=err) + return None async def put_2_statsQ(self, statsType: str, key: list, stats: list): From fd81866af84691cd8817a978d7726514be3c43ae Mon Sep 17 00:00:00 2001 From: Jylpah Date: Fri, 27 Nov 2020 00:00:58 +0200 Subject: [PATCH 6/7] New categorizations: is_premium, tank_type, tank_nation --- analyze_wotb_replays.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/analyze_wotb_replays.py b/analyze_wotb_replays.py index e54925c..2725feb 100755 --- a/analyze_wotb_replays.py +++ b/analyze_wotb_replays.py @@ -127,9 +127,12 @@ class BattleCategorizationList(): 'total' : [ 'TOTAL', 'total' ], 'battle_result' : [ 'Result', 'category', [ 'Loss', 'Win', 'Draw']], 'battle_type' : [ 'Battle Type', 'category', [ 'Encounter', 'Supremacy']], - 'tank_tier' : [ 'Tank Tier', 'number' ], - 'top_tier' : [ 'Tier', 'category', [ 'Bottom tier', 'Top tier']], 'room_type' : [ 'Battle Mode', 'category', _BATTLE_MODES ], + 'top_tier' : [ 'Tier', 'category', [ 'Bottom tier', 'Top tier']], + 'tank_tier' : [ 'Tank Tier', 'number' ], + 'is_premium' : [ 'Tank Type', 'category', [ 'Tech tree', 'Premium']], + 'tank_type' : [ 'Tank Class', 'category', WG.TANK_TYPE_STR], + 'tank_nation' : [ 'Nation', 'category', WG.NATION_STR], 'mastery_badge' : [ 'Battle Medal', 'category', ['-', '3rd Class', '2nd Class', '1st Class', 'Mastery' ]], 'team_result' : [ 'Team Result', 'string' ], 'player_wins' : [ 'Player WR', 'bucket', [ 0, .35, .45, .50, .55, .65], '%' ], @@ -140,11 +143,11 @@ class BattleCategorizationList(): 'enemies_spotted' : [ 'Player Spots', 'number'], 'hit_rate' : [ 'Player Hit Rate', 'bucket', [ 0, .25, .5, .6, .7, .8, .9, .95 ], '%' ], 'pen_rate' : [ 'Player Pen Rate', 'bucket', [ 0, .25, .5, .6, .7, .8, .9, .95 ], '%' ], - 'map_name' : [ 'Map', 'string' ], - 'tank_name' : [ 'Tank', 'string' ], - 'player_name' : [ 'Player', 'string' ], - 'protagonist' : [ 'account_id', 'number' ], - 'battle_i' : [ 'Battle #', 'number' ] + 'player_name' : [ 'Player', 'string' ], + 'protagonist' : [ 'account_id', 'number' ], + 'tank_name' : [ 'Tank', 'string' ], + 'map_name' : [ 'Map', 'string' ], + 'battle_i' : [ 'Battle #', 'number' ] } _categorizations_default = [ @@ -2123,7 +2126,10 @@ async def read_replay_JSON(replay_json: dict, args : argparse.Namespace) -> dict tmp['account_id'] = account_id tmp['tank_id'] = player['vehicle_descr'] tmp['tank_tier'] = player_tank_tier - tmp['tank_name'] = wg.get_tank_data(tmp['tank_id'], 'name') + tmp['tank_name'] = wg.get_tank_name(tmp['tank_id']) + tmp['tank_type'] = wg.get_tank_type_id(tmp['tank_id']) + tmp['tank_nation'] = wg.get_tank_nation_id(tmp['tank_id']) + tmp['is_premium'] = int(wg.is_premium(tmp['tank_id'])) tmp['squad_index'] = player['squad_index'] for key in replay_details_flds: tmp[key] = player[key] From e654b9ab36780b2754959b6f08d40b3ed7ba99df Mon Sep 17 00:00:00 2001 From: Jylpah Date: Fri, 27 Nov 2020 00:20:52 +0200 Subject: [PATCH 7/7] rename TD -> Tank Destroyer --- blitzutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blitzutils.py b/blitzutils.py index 2590ca3..fa572d4 100755 --- a/blitzutils.py +++ b/blitzutils.py @@ -771,7 +771,7 @@ class WG: } TANK_TYPE = [ 'lightTank', 'mediumTank', 'heavyTank', 'AT-SPG' ] - TANK_TYPE_STR = [ 'Light Tank', 'Medium Tank', 'Heavy Tank', 'TD' ] + TANK_TYPE_STR = [ 'Light Tank', 'Medium Tank', 'Heavy Tank', 'Tank Destroyer' ] TANK_TYPE_ID = { 'lightTank' : 0,