def test_match_id(self): """ Tests if a match_id is not given is parsed properly """ self.parser = DemoParser( demofile="tests/natus-vincere-vs-astralis-m1-dust2.dem", log=True, ) assert self.parser.match_id == "natus-vincere-vs-astralis-m1-dust2"
def setup_class(self): """Setup class by instantiating parser""" self.parser = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=True, demo_id="test", parse_rate=128, )
def setup_class(self): """ Setup class by instantiating parser """ self.parser = DemoParser( demofile="tests/natus-vincere-vs-astralis-m1-dust2.dem", log=True, match_id="natus-vincere-vs-astralis-m1-dust2", )
def test_parsed_bomb_events_not_parsed(self): """Tests if bomb_events parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_bomb_events(return_type="list")
def openFileNameDialog(self): options = QtWidgets.QFileDialog.Options() options |= QtWidgets.QFileDialog.DontUseNativeDialog fileName, _ = QtWidgets.QFileDialog.getOpenFileName( self, "QFileDialog.getOpenFileName()", "", "Demo Files (*.dem)", options=options) if fileName: self.demofile = fileName self.guard_demoLoaded = True demo_parser = DemoParser(demofile=self.demofile, match_id="T") self.data = demo_parser.parse()
def create_demo_data(demoset_id, demo_file_name): demo_str = "".join(RAW_DEMO[demoset_id]) demo_str += "==" demo_byte = demo_str.encode('ascii') decoded_byte = base64.decodebytes(demo_byte) tmp_demo_path = "tmp_demos/" + demo_file_name tmp_path = open(tmp_demo_path, "wb") tmp_path.write(decoded_byte) tmp_path.close() demo_parser = DemoParser(demofile=tmp_demo_path, match_id=demo_file_name) demo_data = demo_parser.parse() base_dir_path = "parsed_demos_" + demoset_id if not os.path.exists(base_dir_path): os.makedirs(base_dir_path) metadata_path = base_dir_path + '/metadata.json' with open(metadata_path, 'w') as outfile: json.dump({'title': demoset_id}, outfile) demo_name_without_suffix = demo_file_name.replace(".dem", "") demo_dir_path = base_dir_path + "/" + demo_name_without_suffix if not os.path.exists(demo_dir_path): os.makedirs(demo_dir_path) demo_data["Rounds"].to_csv(demo_dir_path + "/" + demo_name_without_suffix + '-rounds.csv', index=False) demo_data["Kills"].to_csv(demo_dir_path + "/" + demo_name_without_suffix + '-kills.csv', index=False) demo_data["Damages"].to_csv(demo_dir_path + "/" + demo_name_without_suffix + '-damages.csv', index=False) demo_data["Grenades"].to_csv(demo_dir_path + "/" + demo_name_without_suffix + '-grenades.csv', index=False) demo_data["BombEvents"].to_csv( demo_dir_path + "/" + demo_name_without_suffix + '-bomb-events.csv', index=False) demo_data["Footsteps"].to_csv(demo_dir_path + "/" + demo_name_without_suffix + '-footsteps.csv', index=False) os.remove(tmp_demo_path)
def test_demo_id_inferred(self): """Tests if a demo_id is correctly inferred""" self.parser_inferred = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, ) assert self.parser_inferred.demo_id == "og-vs-natus-vincere-m1-dust2"
def test_parse_rate_inferred(self): """Tests if good parse rates are set""" self.parser_inferred_parse_rate = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) assert self.parser_inferred_parse_rate.parse_rate == 32
def parse(self, write_json=False): """ Parses the demofiles in self.match_dir Attributes: write_json (boolean) : Boolean indicating if JSON will write Returns: Dictionary of dictionaries, where the first level keys are maps, and the second level keys correspond to that map's set of data. """ for f in self.demofiles: map_name = f[3:-4] parser = DemoParser(demofile=self.match_dir + f, match_id=self.match_id) self.game_data[map_name] = parser.parse() if write_json: parser.write_json() return self.game_data
def test_parse_rate_bad(self): """Tests if bad parse rates fail""" self.parser_bad_parse_rate = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", parse_rate=129, ) assert self.parser_bad_parse_rate.parse_rate == 32
def test_wrong_demo_path(self): """Tests if failure on wrong demofile path""" with pytest.raises(ValueError): self.parser_wrong_demo_path = DemoParser( demofile="bad.dem", log=False, demo_id="test", parse_rate=128, )
def main(): demofile = sys.argv[1] # Create parser object # Set log=True above if you want to produce a logfile for the parser demo_parser = DemoParser(demofile=demofile, match_id="a") # Parse the demofile, output results to dictionary with df name as key data = demo_parser.parse() # create SQL databank conn = sqlite3.connect('TmpDB.db') for key in data.keys(): if key != "Map": df = pd.DataFrame.from_dict(data[key]) df.to_sql(key, con=conn) else: df = pd.DataFrame({"MapName": [data["Map"]]}) df.to_sql(key, con=conn)
class TestDemoParser: """Class to test the match parser Uses https://www.hltv.org/matches/2344822/og-vs-natus-vincere-blast-premier-fall-series-2020 """ def setup_class(self): """Setup class by instantiating parser""" self.parser = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=True, demo_id="test", parse_rate=128, ) self.data = self.parser.parse() def teardown_class(self): """Set parser to none""" self.parser = None self.data = None def test_graph_output_graph_dist(self): """Tests if the graph output is of correct dimension using graph distance""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][0], metric="graph", map_name=self.data["MapName"], full=True, ) assert X.shape[0] == 10 assert X.shape[1] == 10 assert A.shape[0] == 10 assert A.shape[1] == 10 def test_graph_output_graph_dist_nonfull(self): """Tests if the graph output is of correct dimension using graph distance and non-full parameters""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][40], metric="graph", map_name=self.data["MapName"], full=False, ) assert X.shape[0] == 5 assert X.shape[1] == 9 assert A.shape[0] == 5 assert A.shape[1] == 5 def test_graph_output_non_graph_dist(self): """Tests if the graph output is of correct dimension using non-graph distance""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][0], metric="euclidean", map_name=self.data["MapName"], full=True, ) assert X.shape[0] == 10 assert X.shape[1] == 10 assert A.shape[0] == 10 assert A.shape[1] == 10 def test_graph_output_non_graph_dist_not_full(self): """Tests if the graph output is of correct dimension using non-graph distance""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][40], metric="euclidean", map_name=self.data["MapName"], full=False, ) assert X.shape[0] == 5 assert X.shape[1] == 9 assert A.shape[0] == 5 assert A.shape[1] == 5 def test_frame_to_graph_bad_map(self): """Tests if frame to graph fails on bad map name""" with pytest.raises(ValueError): X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][0], metric="graph", map_name="not_a_correct_map_name", ) def test_frame_to_graph_no_players(self): """Tests if frame to graph fails on no players in T or CT""" with pytest.raises(ValueError): X, A = frame_to_graph( frame=self.data["GameRounds"][-1]["Frames"][-1], metric="graph", map_name=self.data["MapName"], ) def test_frame_to_graph_places(self): """Tests if frame to graph fails on places=True""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][40], metric="euclidean", map_name=self.data["MapName"], full=True, places=True, ) assert X.shape[0] == 10 assert X.shape[1] == 120 assert A.shape[0] == 10 assert A.shape[1] == 10 def test_frame_to_graph_coordinates(self): """Tests if frame to graph fails on places=True""" X, A = frame_to_graph( frame=self.data["GameRounds"][0]["Frames"][40], metric="euclidean", map_name=self.data["MapName"], full=True, places=False, coordinates=True ) assert X.shape[0] == 10 assert X.shape[1] == 13 assert A.shape[0] == 10 assert A.shape[1] == 10
class TestDemoParser: """Class to test the match parser Uses https://www.hltv.org/matches/2344822/og-vs-natus-vincere-blast-premier-fall-series-2020 """ def setup_class(self): """Setup class by instantiating parser""" self.parser = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=True, demo_id="test", parse_rate=128, ) def teardown_class(self): """Set parser to none""" self.parser = None def test_demo_id_inferred(self): """Tests if a demo_id is correctly inferred""" self.parser_inferred = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, ) assert self.parser_inferred.demo_id == "og-vs-natus-vincere-m1-dust2" def test_demo_id_given(self): """Tests if a demo_id is correctly inferred""" assert self.parser.demo_id == "test" def test_wrong_demo_path(self): """Tests if failure on wrong demofile path""" with pytest.raises(ValueError): self.parser_wrong_demo_path = DemoParser( demofile="bad.dem", log=False, demo_id="test", parse_rate=128, ) def test_parse_rate_bad(self): """Tests if bad parse rates fail""" self.parser_bad_parse_rate = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", parse_rate=129, ) assert self.parser_bad_parse_rate.parse_rate == 32 def test_parse_rate_good(self): """Tests if good parse rates are set""" self.parser_diff_parse_rate = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", parse_rate=16, ) assert self.parser_diff_parse_rate.parse_rate == 16 def test_parse_rate_inferred(self): """Tests if good parse rates are set""" self.parser_inferred_parse_rate = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) assert self.parser_inferred_parse_rate.parse_rate == 32 def test_logger_set(self): """Tests if log file is created""" assert self.parser.logger.name == "CSGODemoParser" assert os.path.exists("csgo_demoparser.log") def test_parse_demo(self): """Tests if parse actually outputs a file""" self.parser._parse_demo() assert os.path.exists("test.json") assert self.parser.output_file == "test.json" def test_read_json(self): """Tests if the JSON output from _parse_demo() can be read""" self.parser._parse_demo() output_json = self.parser._read_json() assert type(output_json) is dict def test_parse(self): """Tests if the JSON output from parse is a dict""" output_json = self.parser.parse() assert type(output_json) is dict def test_parsed_json(self): """Tests if the parsed JSON is correct""" data = self.parser.parse() assert data["MatchId"] == self.parser.demo_id assert data["ClientName"] == "GOTV Demo" assert data["MapName"] == "de_dust2" assert data["PlaybackTicks"] == 466670 assert data["ParseRate"] == 128 assert len(data["GameRounds"]) == 25 assert data["GameRounds"][0]["RoundNum"] == 1 assert data["GameRounds"][0]["StartTick"] == 9308 assert data["GameRounds"][0]["EndTick"] == 43177 assert data["GameRounds"][0]["TScore"] == 0 assert data["GameRounds"][0]["CTScore"] == 0 assert data["GameRounds"][0]["CTBuyType"] == "Pistol" assert data["GameRounds"][0]["TBuyType"] == "Pistol" assert data["GameRounds"][15]["CTBuyType"] == "Pistol" assert data["GameRounds"][15]["TBuyType"] == "Pistol" assert data["GameRounds"][0]["RoundEndReason"] == "CTWin" assert data["GameRounds"][0]["CTStartEqVal"] == 4400 assert data["GameRounds"][0]["TStartEqVal"] == 4250 assert data["GameRounds"][-1]["RoundEndReason"] == "TerroristsWin" assert data["GameRounds"][15]["RoundEndReason"] == "BombDefused" assert len(data["ServerVars"].keys()) == 17 def test_parsed_wrong_type(self): """Tests wrote parse type""" with pytest.raises(ValueError): self.parser.parse(return_type="bad") def test_parse_df(self): """Tests if df is parsed""" data = self.parser.parse(return_type="df") assert "Rounds" in data.keys() assert type(data["Rounds"]) == pd.DataFrame assert "Frames" in data.keys() assert type(data["Frames"]) == pd.DataFrame assert "PlayerFrames" in data.keys() assert type(data["PlayerFrames"]) == pd.DataFrame assert "Kills" in data.keys() assert type(data["Kills"]) == pd.DataFrame assert "Damages" in data.keys() assert type(data["Damages"]) == pd.DataFrame assert "Grenades" in data.keys() assert type(data["Grenades"]) == pd.DataFrame assert "Flashes" in data.keys() assert type(data["Flashes"]) == pd.DataFrame def test_parse_bad_return(self): """Tests if parse fails on bad return type""" with pytest.raises(ValueError): self.parser.parse(return_type="test") def test_parsed_frames(self): """Tests if frames parse correctly""" data = self.parser.parse() frames_list = self.parser._parse_frames(return_type="list") frames_df = self.parser._parse_frames(return_type="df") assert type(frames_list) == list assert len(frames_list) == 2521 assert type(frames_df) == pd.DataFrame assert frames_df.shape[0] == 2521 with pytest.raises(ValueError): self.parser._parse_frames(return_type="notalist") def test_parsed_frames_not_parsed(self): """Tests if frames parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_frames(return_type="list") def test_parsed_player_frames(self): """Tests if player_frames parse correctly""" data = self.parser.parse() player_frames_list = self.parser._parse_player_frames( return_type="list") player_frames_df = self.parser._parse_player_frames(return_type="df") assert type(player_frames_list) == list assert len(player_frames_list) == 24610 assert type(player_frames_df) == pd.DataFrame assert player_frames_df.shape[0] == 24610 with pytest.raises(ValueError): self.parser._parse_player_frames(return_type="notalist") def test_parsed_player_frames_not_parsed(self): """Tests if player_frames parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_player_frames(return_type="list") def test_parsed_rounds(self): """Tests if rounds parse correctly""" data = self.parser.parse() rounds_list = self.parser._parse_rounds(return_type="list") rounds_df = self.parser._parse_rounds(return_type="df") assert type(rounds_list) == list assert len(rounds_list) == 25 assert type(rounds_df) == pd.DataFrame assert rounds_df.shape[0] == 25 with pytest.raises(ValueError): self.parser._parse_rounds(return_type="notalist") def test_parsed_rounds_not_parsed(self): """Tests if rounds parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_rounds(return_type="list") def test_parsed_kills(self): """Tests if kills parse correctly""" data = self.parser.parse() kills_list = self.parser._parse_kills(return_type="list") kills_df = self.parser._parse_kills(return_type="df") assert type(kills_list) == list assert len(kills_list) == 163 assert type(kills_df) == pd.DataFrame assert kills_df.shape[0] == 163 with pytest.raises(ValueError): self.parser._parse_kills(return_type="notalist") def test_parsed_kills_not_parsed(self): """Tests if kills parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_kills(return_type="list") def test_parsed_damages(self): """Tests if damages parse correctly""" data = self.parser.parse() damages_list = self.parser._parse_damages(return_type="list") damages_df = self.parser._parse_damages(return_type="df") assert type(damages_list) == list assert len(damages_list) == 704 assert type(damages_df) == pd.DataFrame assert damages_df.shape[0] == 704 with pytest.raises(ValueError): self.parser._parse_damages(return_type="notalist") def test_parsed_damages_not_parsed(self): """Tests if damages parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_damages(return_type="list") def test_parsed_grenades(self): """Tests if grenades parse correctly""" data = self.parser.parse() grenades_list = self.parser._parse_grenades(return_type="list") grenades_df = self.parser._parse_grenades(return_type="df") assert type(grenades_list) == list assert len(grenades_list) == 705 assert type(grenades_df) == pd.DataFrame assert grenades_df.shape[0] == 705 with pytest.raises(ValueError): self.parser._parse_grenades(return_type="notalist") def test_parsed_grenades_not_parsed(self): """Tests if grenades parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_grenades(return_type="list") def test_parsed_flashes(self): """Tests if flashes parse correctly""" data = self.parser.parse() flashes_list = self.parser._parse_flashes(return_type="list") flashes_df = self.parser._parse_flashes(return_type="df") assert type(flashes_list) == list assert len(flashes_list) == 617 assert type(flashes_df) == pd.DataFrame assert flashes_df.shape[0] == 617 with pytest.raises(ValueError): self.parser._parse_flashes(return_type="notalist") def test_parsed_flashes_not_parsed(self): """Tests if flashes parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_flashes(return_type="list") def test_parsed_bomb_events(self): """Tests if bomb_events parse correctly""" data = self.parser.parse() bomb_events_list = self.parser._parse_bomb_events(return_type="list") bomb_events_df = self.parser._parse_bomb_events(return_type="df") assert type(bomb_events_list) == list assert len(bomb_events_list) == 16 assert type(bomb_events_df) == pd.DataFrame assert bomb_events_df.shape[0] == 16 with pytest.raises(ValueError): self.parser._parse_bomb_events(return_type="notalist") def test_parsed_bomb_events_not_parsed(self): """Tests if bomb_events parse correctly if not parsed""" self.parser_not_parsed = DemoParser( demofile="tests/og-vs-natus-vincere-m1-dust2.dem", log=False, demo_id="test", ) with pytest.raises(AttributeError): self.parser_not_parsed._parse_bomb_events(return_type="list")
class TestDemoParser: """ Class to test the match parser """ def setup_class(self): """ Setup class by instantiating parser """ self.parser = DemoParser( demofile="tests/natus-vincere-vs-astralis-m1-dust2.dem", log=True, match_id="natus-vincere-vs-astralis-m1-dust2", ) def teardown_class(self): """ Set parser to none """ self.parser = None def test_match_id(self): """ Tests if a match_id is not given is parsed properly """ self.parser = DemoParser( demofile="tests/natus-vincere-vs-astralis-m1-dust2.dem", log=True, ) assert self.parser.match_id == "natus-vincere-vs-astralis-m1-dust2" def test_demo_error(self): """ Tests if the parser encountered a corrupted demofile. If it did, the parser would set the `demo_error` attribute to True. Since this demofile is not corrupted, this test should have parser.demo_error as FALSE """ self.parser._parse_demofile() assert not self.parser.demo_error def test_logger(self): """ Tests if the parser logs correctly. """ assert self.parser.logger.name == "CSGODemoParser" assert os.path.exists("csgo_parser.log") def test_parse_match(self): """ Tests if the parser parses the match without issue. Our test demo had 21 total rounds. """ self.parser._parse_match() assert len(self.parser.rounds) == 21 def test_parse(self): """ Tests if parse wrapper method works """ output = self.parser.parse() assert not self.parser.demo_error assert len(self.parser.rounds) == 21 assert len(output.keys()) == 7 def test_clean_match(self): """ Tests if the clean_rounds works. Should still return 21. """ self.parser._clean_rounds() assert len(self.parser.rounds) == 21 def test_last_round_reason(self): """ Tests if the last round had the correct win reason. It should be "CTWin". """ assert self.parser.rounds[-1].reason == "CTWin" def test_round_cash_eq(self): """ Tests if cash and equipment values are parsing properly. """ assert self.parser.rounds[0].t_eq_val == 4050 assert self.parser.rounds[0].ct_eq_val == 4400 assert self.parser.rounds[0].t_cash_spent_total == 3550 assert self.parser.rounds[0].ct_cash_spent_total == 3650 assert self.parser.rounds[0].t_cash_spent_round == 3550 assert self.parser.rounds[0].ct_cash_spent_round == 3650 def test_round_type(self): """ Tests if round types are properly functioning. """ assert self.parser.rounds[0].ct_round_type == "Pistol" assert self.parser.rounds[0].t_round_type == "Pistol" assert self.parser.rounds[1].ct_round_type == "Half Buy" assert self.parser.rounds[2].ct_round_type == "Eco" def test_kills_total(self): """ Tests if the kill totals are correct. s1mple should have 25 kills. """ self.parser.write_kills() kills_df = self.parser.kills_df.groupby("AttackerName").size().reset_index() kills_df.columns = ["AttackerName", "Kills"] assert kills_df[kills_df["AttackerName"] == "s1mple"].Kills.values[0] == 25 def test_bomb_plant(self): """ Tests for bomb plant events. There should be a plant and a defuse event for this round. """ self.parser.write_bomb_events() bomb_df = self.parser.bomb_df assert ( bomb_df.loc[bomb_df["RoundNum"] == 16, ["Tick", "EventType"]].shape[0] == 2 ) def test_damage_total(self): """ Tests for correct damage per round. """ self.parser.write_damages() damage_df = self.parser.damages_df damage_df["Damage"] = damage_df["HpDamage"] + damage_df["ArmorDamage"] damage_df["KillDamage"] = damage_df["KillHpDamage"] + damage_df["ArmorDamage"] dmg = ( (damage_df.groupby(["AttackerName"]).Damage.sum() / 21) .reset_index() .iloc[0, 1] ) kill_dmg = ( (damage_df.groupby(["AttackerName"]).KillDamage.sum() / 21) .reset_index() .iloc[0, 1] ) assert (dmg == 94.9047619047619) and (kill_dmg == 88.23809523809524) def test_grenade_total(self): """ Tests for correct number of grenade events. """ self.parser.write_grenades() grenades_df = self.parser.grenades_df assert grenades_df.shape[0] == 550 def test_footsteps(self): """ Tests for correct trajectory parsing. """ self.parser.write_footsteps() footsteps_df = self.parser.footsteps_df assert footsteps_df.iloc[777, :].X == 583.253906 assert footsteps_df.iloc[777, :].Y == 592.542297 assert footsteps_df.iloc[777, :].Z == 2.59956 assert footsteps_df.iloc[777, :].XViz == 695.284979 assert footsteps_df.iloc[777, :].YViz == -601.46766 assert footsteps_df.iloc[777, :].AreaId == 1432 assert footsteps_df.iloc[777, :].AreaName == "LongDoors" def test_write_data(self): """ Tests write data method. """ df_dict = self.parser.write_data() assert len(df_dict.keys()) == 7 assert df_dict["Rounds"].shape[0] == 21 def test_parse_error(self): """ Tests if parser errors on bad file """ self.parser = DemoParser(demofile="tests/file-no-exist.dem", match_id="test",) self.parser._parse_demofile() assert self.parser.demo_error == True def test_json_write(self): """ Tests if parser can write to JSON """ self.parser.write_json() assert os.path.exists("natus-vincere-vs-astralis-m1-dust2_de_dust2.json") assert ( os.path.getsize("natus-vincere-vs-astralis-m1-dust2_de_dust2.json") < 10000000 ) def test_json_write_with_footsteps(self): """ Tests if parser can write to JSON, including footsteps """ self.parser.write_json(write_footsteps=True) assert os.path.exists("natus-vincere-vs-astralis-m1-dust2_de_dust2.json") assert ( os.path.getsize("natus-vincere-vs-astralis-m1-dust2_de_dust2.json") > 10000000 ) def test_write_map_name(self): """ Tests if the parser writes the map name to a dictionary """ df_dict = self.parser.write_data() assert df_dict["Map"] == "de_dust2"
def test_parse_error(self): """ Tests if parser errors on bad file """ self.parser = DemoParser(demofile="tests/file-no-exist.dem", match_id="test",) self.parser._parse_demofile() assert self.parser.demo_error == True
from csgo.parser import DemoParser # Create parser object # Set log=True above if you want to produce a logfile for the parser demo_parser = DemoParser( demofile="DemoManager/SKADE/Inferno/18-04-2021&Young Ninjas.dem", match_id="astralis-vs-liquid-m1-inferno.dem") # Parse the demofile, output results to dictionary with df name as key data = demo_parser.parse() # The following keys exist data["Rounds"] data["Kills"] data["Damages"] data["Grenades"] data["BombEvents"] data["Footsteps"] # You can also write the demofile data to JSON using demo_parser.write_json()