def test_can_get_the_default_score_from_a_single_match(self): # given a match report filename = "tests/logs/L0409001.log" match_report = LogParser.from_filename(filename).get_match_report() # when given to the stats extractor scorer = DefaultScorer() stats = MatchReportCollection([match_report]) # we can know the best player player = Player("Mcd.", 538382878) assert stats.get_best_player(scorer)[0] == player
def test_can_filter_players_with_less_than_n_rounds(self): # given a list of matches logs = "tests/logs" match_reports = LogDirectoryParser(logs).get_all_match_reports() # when given to the stats extractor with a filter scorer = WinRateScorer(filter_less_than=10) stats = MatchReportCollection(match_reports) # then the confidence in a player with less than the filter rounds played is zero score_table = stats.get_full_player_scores(scorer) print(score_table) player = Player("El Bromas", 538649250) assert score_table[player].confidence == 0
def test_can_get_glicko_ranking_per_player(self): # given a list of matches logs = "tests/logs" match_reports = LogDirectoryParser(logs).get_all_match_reports() # when given to the stats extractor scorer = GlickoScorer() stats = MatchReportCollection(match_reports) # we can know the player that has the best ranking score_table = stats.get_sorted_score_table(scorer) print(score_table) player = Player("Mcd.", 538382878) best_player = score_table[0][0] assert best_player == player
def test_can_get_time_spent_in_the_server_per_player(self): # given a list of matches logs = "tests/logs" match_reports = LogDirectoryParser(logs).get_all_match_reports() # when given to the stats extractor scorer = TimeSpentScorer() stats = MatchReportCollection(match_reports) # we can know the player that spent more time in the server score_table = stats.get_sorted_score_table(scorer) print(score_table) player = Player("Rocho", 86787335) best_player = score_table[0][0] assert best_player == player
def test_can_get_the_default_score_from_many_matches(self): # given a list of matches logs = "tests/logs" match_reports = LogDirectoryParser(logs).get_all_match_reports() # when given to the stats extractor scorer = DefaultScorer() stats = MatchReportCollection(match_reports) # we can know the best player score_table = stats.get_sorted_score_table(scorer) print(score_table) player = Player("Mcd.", 538382878) best_player = score_table[0][0] assert best_player == player
def test_can_know_a_player_match_stats(self): # given a log file filename = "tests/logs/L0409001.log" # when feeded to the log parser parser = LogParser.from_filename(filename) match_report = parser.get_match_report() # then the resulting match report knows the total match stats for the player player = Player("Mcd.", 538382878) player_stats = match_report.get_player_stats(player) awp = Weapon("awp") knife = Weapon("knife") assert player_stats.damage_inflicted == 5948 assert player_stats.damage_inflicted_by_weapon == {awp: 5496, knife: 452} assert player_stats.damage_received == 1928 assert player_stats.kills == 36 assert player_stats.deaths == 10
def test_can_get_the_default_score_from_many_matches(self): # given a list of matches and a list of scorers logs = "tests/logs" match_reports = LogDirectoryParser(logs).get_all_match_reports() scorers = [GlickoScorer(), DefaultScorer(), WinRateScorer(), TimeSpentScorer()] # when given to the stats table stats = StatsTable(match_reports, scorers) # we can know the full scoring table score_table = stats.get_full_table() print(score_table) self.assertEqual(score_table[Player('Laski', 53940642)]['Classic\u00A0score'].value, -12) self.assertEqual(score_table[Player('Laski', 53940642)]['Classic\u00A0score'].string, '-12') self.assertAlmostEqual(score_table[Player('Laski', 53940642)]['Classic\u00A0score'].confidence, 1) self.assertEqual(score_table[Player('Mcd.', 538382878)]['Classic\u00A0score'].value, 26) self.assertEqual(score_table[Player('Mcd.', 538382878)]['Classic\u00A0score'].string, '26') self.assertAlmostEqual(score_table[Player('Mcd.', 538382878)]['Classic\u00A0score'].confidence, 1)
def test_can_know_a_player_round_stats(self) -> None: # given a log where a player inflicted damage and killed an opponent logtext = """ L 04/09/2020 - 20:48:29: World triggered "Round_Start" L 04/09/2020 - 20:47:45: "Mcd.<4><STEAM_0:1:538382878><>" joined team "CT" L 04/09/2020 - 21:07:39: "Mcd.<4><STEAM_0:1:538382878><CT>" attacked "triple_de_miga<11><STEAM_0:0:479244024><TERRORIST>" with "awp" (damage "106") (damage_armor "2") (health "-6") (armor "98") L 04/09/2020 - 21:07:39: "Mcd.<4><STEAM_0:1:538382878><CT>" killed "triple_de_miga<11><STEAM_0:0:479244024><TERRORIST>" with "awp" L 04/09/2020 - 21:07:41: "Mcd.<4><STEAM_0:1:538382878><CT>" attacked "Laski<3><STEAM_0:0:53940642><TERRORIST>" with "awp" (damage "52") (damage_armor "1") (health "48") (armor "99") L 04/09/2020 - 20:49:23: "Laski<3><STEAM_0:0:53940642><TERRORIST>" attacked "Mcd.<4><STEAM_0:1:538382878><CT>" with "knife" (damage "12") (damage_armor "2") (health "88") (armor "98") L 04/09/2020 - 20:48:29: World triggered "Round_End" """ # when feeded to the log parser parser = LogParser.from_raw_text(logtext) round_reports = parser.get_round_reports() # then the resulting round report knows the round stats for the player first_round_report = round_reports[0] player = Player("Mcd.", 538382878) weapon = Weapon("awp") player_stats = first_round_report.get_player_stats(player) assert player_stats.damage_inflicted == 106 + 52 assert player_stats.damage_inflicted_by_weapon[weapon] == 106 + 52 assert player_stats.damage_received == 12 assert player_stats.kills == 1