def test_proto_export_invalid_type(self, replay_cache): def test(analysis: AnalysisManager): with NamedTemporaryFile(mode='w') as f: with pytest.raises(IOError): analysis.write_proto_out_to_file(f) run_analysis_test_on_replay(test, get_raw_replays()["DEFAULT_3_ON_3_AROUND_58_HITS"], cache=replay_cache)
def test_hit_pressure(self, replay_cache): def test(analysis: AnalysisManager, answer): proto_game = analysis.get_protobuf_data() hits = proto_game.game_stats.hits expected_pressures = [ 100, 100, 100, 100, 0, 93, 100, 100, 94, 0, 0, 95, 100, 100, 0, 0, 0, 0, 90, 0, 0, 94, 100, 100, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 99, 100, 0, 0, 0, 0, 100, 100, 100, 0, 100, 0, 0, 0, 0, 100, 100, 100, 100, 0, 100, 0, 94, 0, 96, 0, 100, 100, 100, 0, 0, 0, 0, 0, 98, 100, 0, 0, 100, 100, 0, 100, 0, 0, 0, 100, 100, 0, 0, 100, 0, 94, 100, 72, 100, 100, 0, 0, 0, 100, 100, 100, 100, 100, 100, 0, 0, 0, 0, 0, 0, 0, 94, 0, 100, 97, 100, 100, 0, 100, 0, 0, 0, 0, 0, 81, 100, 97, 100, 81, 100, 0, 100, 100, 0, 100, 100, 100, 100, 91, 0, 0, 0, 100, 0, 96, 100, 100, 99, 0, 0, 0, 100, 0, 0, 0, 0, 0, 100, 0, 99, 100, 98, 0, 94, 0, 100, 0, 100, 100, 0, 100, 100, 100, 0, 100, 0, 100, 67, 0, 91, 100, 100, 100, 0, 0, 0, 0, 88, 0, 100, 0, 100, 0, 0 ] for x in range(len(hits)): assert (hits[x].pressure == expected_pressures[x]) # Skip test cache since this test is calculating intensive events. run_analysis_test_on_replay( test, replay_list=get_raw_replays()["OCE_RLCS_7_CARS"], answers=get_specific_answers()["CLEARS"], calculate_intensive_events=True)
def test_unicode_names_invalid_type(self, replay_cache): def test(analysis: AnalysisManager): with NamedTemporaryFile(mode='w') as f: with pytest.raises(IOError): analysis.write_pandas_out_to_file(f) run_analysis_test_on_replay(test, get_raw_replays()["UNICODE_ERROR"], cache=replay_cache)
def test_all_kickoffs_2(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs assert (len(kickoffs) == 6) first_player = proto_game.players[0].stats kickoff_stats = first_player.kickoff_stats assert kickoff_stats.num_time_first_touch == 1 assert kickoff_stats.num_time_go_to_ball == 1 assert kickoff_stats.num_time_boost == 1 assert kickoff_stats.num_time_cheat == 0 assert kickoff_stats.num_time_defend == 1 assert kickoff_stats.num_time_afk == 1 assert kickoff_stats.total_kickoffs == 6 assert 2 == ( kickoff_stats.total_kickoffs - (kickoff_stats.num_time_go_to_ball + kickoff_stats.num_time_boost + kickoff_stats.num_time_cheat + kickoff_stats.num_time_defend + kickoff_stats.num_time_afk)) second_player_stats = proto_game.players[1].stats.kickoff_stats assert second_player_stats.num_time_first_touch == 5 assert second_player_stats.num_time_go_to_ball == 6 for i in range(len(kickoffs)): kickoff = proto_game.game_stats.kickoff_stats[i] player = kickoff.touch.players[0] start_left = player.start_position.pos_x < 0 assert player.start_left == start_left run_analysis_test_on_replay(test, get_raw_replays()["6_DIVERSE_KICKOFFS"])
def test_3_kickoffs(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs self.assertEqual(len(kickoffs), 3) run_analysis_test_on_replay(test, get_raw_replays()["3_KICKOFFS"])
def test_zero_dribbles(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() carries = proto_game.game_stats.ball_carries assert (len(carries) == 0) run_analysis_test_on_replay(test, get_raw_replays()["KICKOFF_NO_TOUCH"], cache=replay_cache)
def test_0_kickoffs(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs assert (len(kickoffs) == 0) run_analysis_test_on_replay(test, get_raw_replays()["KICKOFF_NO_TOUCH"])
def test_no_one_for_kickoffs(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs assert (len(kickoffs) == 1) run_analysis_test_on_replay(test, get_raw_replays()["NO_ONE_FOR_KICKOFF"])
def test_calculate_demos_correctly(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() bumps = proto_game.game_stats.bumps assert len(bumps) == 1 run_analysis_test_on_replay(test, get_raw_replays()["1_DEMO"], cache=replay_cache)
def test_json_export(self, replay_cache): def test(analysis: AnalysisManager): with NamedTemporaryFile(mode='w') as f: analysis.write_json_out_to_file(f) run_analysis_test_on_replay( test, get_raw_replays()["DEFAULT_3_ON_3_AROUND_58_HITS"], cache=replay_cache)
def test_fifties_empty_if_not_intensive(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() fifties = proto_game.game_stats.fifty_fifties assert (len(fifties) == 0) # Skip test cache since this test is calculating intensive events. run_analysis_test_on_replay(test, get_raw_replays()["OCE_RLCS_7_CARS"], calculate_intensive_events=False)
def test_gzip_export(self, replay_cache): def test(analysis: AnalysisManager): with NamedTemporaryFile(mode='wb') as f: gzip_file = gzip.GzipFile(mode='wb', fileobj=f) analysis.write_pandas_out_to_file(gzip_file) run_analysis_test_on_replay( test, get_raw_replays()["DEFAULT_3_ON_3_AROUND_58_HITS"], cache=replay_cache)
def test_boost_steals(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() player = proto_game.players[0] boost = player.stats.boost assert boost.num_stolen_boosts == 2 run_analysis_test_on_replay(test, get_raw_replays()["6_BIG_25_SMALL"], cache=replay_cache)
def test_lots_of_boost_collected(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() player = proto_game.players[0] boost = player.stats.boost assert [boost.num_small_boosts, boost.num_large_boosts] == [25, 6] run_analysis_test_on_replay(test, get_raw_replays()["6_BIG_25_SMALL"], cache=replay_cache)
def test_replay_attrs(self): def test(replay, file_path): json_object = decompile_replays.decompile_replay(replay, output_path=file_path) game = Game() game.initialize(loaded_json=json_object) assert game.game_info.server_name is not None assert game.map is not None assert game.game_info.match_guid is not None run_tests_on_list(test, get_raw_replays()["0_JUMPS"])
def test_item_kickoff(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() self.assert_rumble_item_counts( proto_game.players[0].stats.rumble_stats, [{ 'item': BALL_FREEZE, 'used': 0, 'unused': 0 }, { 'item': BALL_GRAPPLING_HOOK, 'used': 0, 'unused': 0 }, { 'item': BALL_LASSO, 'used': 0, 'unused': 0 }, { 'item': BALL_SPRING, 'used': 2, 'unused': 0 }, { 'item': BALL_VELCRO, 'used': 0, 'unused': 0 }, { 'item': BOOST_OVERRIDE, 'used': 0, 'unused': 0 }, { 'item': CAR_SPRING, 'used': 0, 'unused': 0 }, { 'item': GRAVITY_WELL, 'used': 0, 'unused': 0 }, { 'item': STRONG_HIT, 'used': 0, 'unused': 0 }, { 'item': SWAPPER, 'used': 0, 'unused': 0 }, { 'item': TORNADO, 'used': 0, 'unused': 0 }]) run_analysis_test_on_replay(test, get_raw_replays()["RUMBLE_ITEM_KICKOFF"], cache=replay_cache)
def test_1_large_pad_1_small_pad_collected(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() player = proto_game.players[0] boost = player.stats.boost assert (boost.num_large_boosts == 1) assert (boost.num_small_boosts == 1) run_analysis_test_on_replay( test, get_raw_replays()["12_AND_100_BOOST_PADS_0_USED"], cache=replay_cache)
def test_no_one_for_weird_kickoffs(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs assert (len(kickoffs) == 3) first_player = proto_game.players[0].stats kickoff_stats = first_player.kickoff_stats assert kickoff_stats.total_kickoffs == 3 run_analysis_test_on_replay(test, get_raw_replays()["WEIRD_KICKOFFS"])
def test_pre_item_goals(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() assert proto_game.game_metadata.goals[0].extra_mode_info.pre_items assert not proto_game.game_metadata.goals[ 1].extra_mode_info.pre_items assert proto_game.game_metadata.goals[2].extra_mode_info.pre_items run_analysis_test_on_replay(test, get_raw_replays()["RUMBLE_PRE_ITEM_GOALS"], cache=replay_cache)
def test_pre_item_goals(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() self.assertTrue( proto_game.game_metadata.goals[0].extra_mode_info.pre_items) self.assertFalse( proto_game.game_metadata.goals[1].extra_mode_info.pre_items) self.assertTrue( proto_game.game_metadata.goals[2].extra_mode_info.pre_items) run_analysis_test_on_replay(test, get_raw_replays()["RUMBLE_PRE_ITEM_GOALS"])
def test_total_dribble_time(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() player = proto_game.players[0] print(player) percent = 6 assert player.stats.ball_carries.total_carry_time == pytest.approx( 196, percent / 100) run_analysis_test_on_replay(test, get_raw_replays()["SKYBOT_DRIBBLE_INFO"], cache=replay_cache)
def test_num_kickoff_hits_detected(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() hits = proto_game.game_stats.hits kickoff_counter = 0 for hit in hits: if hit.is_kickoff: kickoff_counter += 1 print(analysis) self.assertEqual(kickoff_counter, 3) run_analysis_test_on_replay(test, get_raw_replays()["3_KICKOFFS"])
def test_0_kickoffs(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() kickoffs = proto_game.game_stats.kickoffs assert (len(kickoffs) == 0) first_player = proto_game.players[0].stats kickoff_stats = first_player.kickoff_stats assert kickoff_stats.total_kickoffs == 0 run_analysis_test_on_replay(test, get_raw_replays()["KICKOFF_NO_TOUCH"])
def test_goal(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() assert proto_game.game_metadata.goals[ 0].extra_mode_info.dropshot_tile.id == 89 assert proto_game.game_metadata.goals[ 0].extra_mode_info.phase_1_tiles == 0 assert proto_game.game_metadata.goals[ 0].extra_mode_info.phase_2_tiles == 1 run_analysis_test_on_replay(test, get_raw_replays()["DROPSHOT_GOAL"], cache=replay_cache)
def test_double_damage(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() assertions = unittest.TestCase('__init__') assert proto_game.players[0].stats.dropshot_stats.total_damage == 3 assert proto_game.players[ 0].stats.dropshot_stats.damage_efficiency == 1.0 assert proto_game.teams[1].stats.dropshot_stats.total_damage == 3 assert proto_game.teams[ 1].stats.dropshot_stats.damage_efficiency == 1.0 dropshot_ball_proto = proto_game.game_stats.ball_stats.extra_mode assert dropshot_ball_proto.dropshot_phase_stats[0].phase == 0 assertions.assertAlmostEqual( dropshot_ball_proto.dropshot_phase_stats[0].average, 10.189136, 5) assertions.assertAlmostEqual( dropshot_ball_proto.dropshot_phase_stats[0].max, 10.189136, 5) assertions.assertAlmostEqual( dropshot_ball_proto.dropshot_phase_stats[0].total, 10.189136, 5) assert dropshot_ball_proto.dropshot_phase_stats[1].phase == 1 assert dropshot_ball_proto.dropshot_phase_stats[1].average == 0 assert dropshot_ball_proto.dropshot_phase_stats[1].max == 0 assert dropshot_ball_proto.dropshot_phase_stats[1].total == 0 assert dropshot_ball_proto.dropshot_phase_stats[2].phase == 2 assert dropshot_ball_proto.dropshot_phase_stats[2].average == 0 assert dropshot_ball_proto.dropshot_phase_stats[2].max == 0 assert dropshot_ball_proto.dropshot_phase_stats[2].total == 0 game_dropshot_stats = proto_game.game_stats.dropshot_stats assert len(game_dropshot_stats.damage_events) == 3 assert game_dropshot_stats.damage_events[0].tiles[ 0].state == DAMAGED assert game_dropshot_stats.damage_events[1].tiles[ 0].state == DESTROYED assert len(game_dropshot_stats.tile_stats.damage_stats) == 2 assert game_dropshot_stats.tile_stats.damage_stats[ 0].total_damage == 2 run_analysis_test_on_replay( test, get_raw_replays()["DROPSHOT_DOUBLE_DAMAGE"], cache=replay_cache)
def test_freeze_vs_spike(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() self.assertNotEqual( proto_game.game_stats.rumble_items[1].frame_number_use, -1) freeze_stats = next( filter(lambda x: x.item == BALL_FREEZE, proto_game.players[0].stats.rumble_stats.rumble_items)) self.assertEqual(freeze_stats.used, 1) run_analysis_test_on_replay( test, get_raw_replays()["RUMBLE_FREEZE_VS_SPIKE"])
def test_num_kickoff_hits_detected(self, replay_cache): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() hits = proto_game.game_stats.hits kickoff_counter = 0 for hit in hits: if hit.is_kickoff: kickoff_counter += 1 print(analysis) assert (kickoff_counter == 3) run_analysis_test_on_replay( test, replay_list=get_raw_replays()["3_KICKOFFS"], cache=replay_cache)
def test_unicode_error(self, replay_cache): def test(analysis: AnalysisManager): assert (analysis.get_protobuf_data() is not None) assert (not analysis.get_protobuf_data().game_metadata.is_invalid_analysis) for player in analysis.get_protobuf_data().players: ratio = (player.stats.positional_tendencies.time_in_front_ball + player.stats.positional_tendencies.time_behind_ball) / player.time_in_game assert (ratio > 0.99) assert (player.stats.positional_tendencies.time_in_front_ball > 0) assert (player.stats.positional_tendencies.time_behind_ball > 0) assert (player.time_in_game > 0) assert (player.stats.speed.time_at_slow_speed > 0) assert (player.stats.boost.average_boost_level > 0) run_analysis_test_on_replay(test, get_raw_replays()['UNICODE_ERROR'], cache=replay_cache)
def test_hold_time(self): def test(analysis: AnalysisManager): proto_game = analysis.get_protobuf_data() spike_stats = next( filter(lambda x: x.item == BALL_VELCRO, proto_game.players[0].stats.rumble_stats.rumble_items)) self.assertAlmostEqual(spike_stats.average_hold, 11.87916, 5) spike_stats = next( filter(lambda x: x.item == BALL_VELCRO, proto_game.teams[0].stats.rumble_stats.rumble_items)) self.assertAlmostEqual(spike_stats.average_hold, 11.87916, 5) run_analysis_test_on_replay(test, get_raw_replays()["RUMBLE_HOLD_TIME"])
def test_0_play_station_only_party(self): def test(analysis: AnalysisManager): game = analysis.game ps_party_leader = "6083491126912347959" ps_team_member_01 = "4674819165248336722" ps_team_member_03 = "4911491436059516465" ps_team_member_02 = ps_party_leader self.assertIn(ps_party_leader, game.parties.keys()) self.assertIn(ps_team_member_01, game.parties[ps_party_leader]) self.assertIn(ps_team_member_02, game.parties[ps_party_leader]) self.assertIn(ps_team_member_03, game.parties[ps_party_leader]) run_analysis_test_on_replay( test, get_raw_replays()["PLAY_STATION_ONLY_PARTY"])