Skip to content

Commit

Permalink
Final touches. (Bumps -> Intensive, adapt testing, commenting unused …
Browse files Browse the repository at this point in the history
…code for codecov)
  • Loading branch information
DivvyCr committed Aug 8, 2020
1 parent 719b9e8 commit 7be3305
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
49 changes: 16 additions & 33 deletions carball/analysis/events/bump_detection/bump_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
# Needs to be relatively high to account for two cars colliding 'diagonally': /\
MAX_BUMP_ALIGN_ANGLE = 60

# Currently arbitrary:
MIN_BUMP_VELOCITY = 5000

# Approx. half of goal height.
# (could be used to discard all aerial contact as bumps, although rarely an aerial bump WAS, indeed, intended)
AERIAL_BUMP_HEIGHT = 300


# TODO Post-bump analysis // Bump impact analysis.
# Could also try to analyse bump severity (analyse velocities?)
class BumpAnalysis:
def __init__(self, game: Game, proto_game: game_pb2):
self.proto_game = proto_game
Expand Down Expand Up @@ -148,7 +146,7 @@ def filter_bumps(data_frame, player_pair, players_close_frame_idxs):
likely_bump = (frame_before_bump, attacker, victim)
likely_bumps.append(likely_bump)

# NOT YET IMPLEMENTED: Check if interval is quite long - players may be in rule 1 :) or might be a scramble.
# NOT YET IMPLEMENTED (see bottom of class):
# BumpAnalysis.analyse_prolonged_proximity(data_frame, interval, player_pair[0], player_pair[1])

return likely_bumps
Expand Down Expand Up @@ -233,7 +231,7 @@ def determine_attacker_victim(p1_name, p2_name, p1_alignment, p2_alignment):
the attacker/victim are ambiguous (T) or not (F).
"""

if abs(p1_alignment) < MAX_BUMP_ALIGN_ANGLE or abs(p2_alignment) < MAX_BUMP_ALIGN_ANGLE:
if BumpAnalysis.is_bump_alignment([p1_alignment, p2_alignment]):
# if abs(p1_alignment - p2_alignment) < 45:
# # TODO Rework? This would indicate that the bump is ambiguous (no definite attacker/victim).
# return p1_name, p2_name, True
Expand All @@ -245,21 +243,11 @@ def determine_attacker_victim(p1_name, p2_name, p1_alignment, p2_alignment):
# This is ambiguous - neither player had an attacking bump angle.
return None, None, True

@staticmethod
def analyse_prolonged_proximity(data_frame, interval, p1_name, p2_name):
# TODO Redo this to do some proper analysis.
if len(interval) > 10:
print(" > Scramble between " + p1_name + " and " + p2_name)
# NOTE: Could try analysing immediate post-bump effects.
# elif len(interval) >= 5:
# frame_after_bump = interval[len(interval) - 1]
# p1_alignment_after = BumpAnalysis.get_player_bump_alignment(data_frame, frame_after_bump,
# p1_name, p2_name)
# p2_alignment_after = BumpAnalysis.get_player_bump_alignment(data_frame, frame_after_bump,
# p2_name, p1_name)

@staticmethod
def is_aerial_bump(data_frame: pd.DataFrame, p1_name: str, p2_name: str, at_frame: int):
"""
Check if the contact was made mid-air.
"""
p1_pos_z = data_frame[p1_name].pos_z.loc[at_frame]
p2_pos_z = data_frame[p2_name].pos_z.loc[at_frame]
if all(x > AERIAL_BUMP_HEIGHT for x in [p1_pos_z, p2_pos_z]):
Expand All @@ -271,22 +259,17 @@ def is_aerial_bump(data_frame: pd.DataFrame, p1_name: str, p2_name: str, at_fram

@staticmethod
def is_bump_alignment(bump_angles):
# Check if all bump alignment angles in the first half of the interval are above MAX_BUMP_ALIGN_ANGLE.
if all(x > MAX_BUMP_ALIGN_ANGLE for x in bump_angles):
"""
Check if all bump alignment angles in the given list are above MAX_BUMP_ALIGN_ANGLE.
"""
if all(abs(x) > MAX_BUMP_ALIGN_ANGLE for x in bump_angles):
return False
else:
return True

@staticmethod
def is_bump_velocity(data_frame: pd.DataFrame, p1_name: str, p2_name: str, at_frame: int):
p1_vel_mag = np.sqrt(data_frame[p1_name].vel_x.loc[at_frame] ** 2 +
data_frame[p1_name].vel_y.loc[at_frame] ** 2 +
data_frame[p1_name].vel_z.loc[at_frame] ** 2)
p2_vel_mag = np.sqrt(data_frame[p2_name].vel_x.loc[at_frame] ** 2 +
data_frame[p2_name].vel_y.loc[at_frame] ** 2 +
data_frame[p2_name].vel_z.loc[at_frame] ** 2)
# Check if initial player velocities are below MIN_BUMP_VELOCITY.
if all(x < MIN_BUMP_VELOCITY for x in [p1_vel_mag, p2_vel_mag]):
return False
else:
return True
# TO SATISFY CODECOV, this is commented out for now.
# @staticmethod
# def analyse_prolonged_proximity(data_frame, interval, p1_name, p2_name):
# # TODO Redo this to do some proper analysis. Rule 1?
# if len(interval) > 60:
# print("Rule 1?")
3 changes: 1 addition & 2 deletions carball/analysis/events/event_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ def create_events(self, game: Game, proto_game: game_pb2.Game, player_map: Dict[
self.create_hit_events(game, proto_game, player_map, data_frame, kickoff_frames, first_touch_frames)
self.calculate_kickoff_stats(game, proto_game, player_map, data_frame, kickoff_frames, first_touch_frames)
self.calculate_ball_carries(game, proto_game, player_map, data_frame[goal_frames])
self.create_bumps(game, proto_game, player_map, data_frame[goal_frames])
self.create_dropshot_events(game, proto_game, player_map)

if calculate_intensive_events:
self.calculate_hit_pressure(game, proto_game, data_frame)
self.calculate_fifty_fifty(game, proto_game, data_frame)
# TODO (j-wass): calculate bumps
self.create_bumps(game, proto_game, player_map, data_frame)

def calculate_fifty_fifty(self, game: Game, proto_game: game_pb2.Game, data_frame: pd.DataFrame):
logger.info("Calculating 50/50s.")
Expand Down
4 changes: 3 additions & 1 deletion carball/tests/stats/bump_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ def test(analysis: AnalysisManager):
count_bumps += 1
assert count_bumps == 7

run_analysis_test_on_replay(test, get_raw_replays()["7_BUMPS"], cache=replay_cache)
# Skip test cache since this test is calculating intensive events.
run_analysis_test_on_replay(test, get_raw_replays()["7_BUMPS"],
calculate_intensive_events=True)

5 comments on commit 7be3305

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carball Benchmarks short_dropshot

Benchmark suite Current: 7be3305 Previous: 07297fe Ratio
carball/tests/benchmarking/benchmarking.py::test_short_dropshot 0.7174895723544785 iter/sec (stddev: 0.01852570684045899) 0.6623984673004569 iter/sec (stddev: 0.010878172765054418) 0.92

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carball Benchmarks intensive_oce_rlcs

Benchmark suite Current: 7be3305 Previous: 07297fe Ratio
carball/tests/benchmarking/benchmarking.py::test_intensive_oce_rlcs 0.0574253441906739 iter/sec (stddev: 0.10581458365411588) 0.06152116311170856 iter/sec (stddev: 0.20006056624924776) 1.07

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carball Benchmarks short_sample

Benchmark suite Current: 7be3305 Previous: 07297fe Ratio
carball/tests/benchmarking/benchmarking.py::test_short_sample 0.7620087923901416 iter/sec (stddev: 0.04724836440001424) 0.8667843933942438 iter/sec (stddev: 0.033132074823376975) 1.14

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carball Benchmarks oce_rlcs

Benchmark suite Current: 7be3305 Previous: 07297fe Ratio
carball/tests/benchmarking/benchmarking.py::test_oce_rlcs 0.08237222556728992 iter/sec (stddev: 0.13131601363191617) 0.07512800799461093 iter/sec (stddev: 0.15956780047878102) 0.91

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carball Benchmarks full_rumble

Benchmark suite Current: 7be3305 Previous: 07297fe Ratio
carball/tests/benchmarking/benchmarking.py::test_full_rumble 0.05941777016804892 iter/sec (stddev: 0.16297840184487644) 0.06434159662703988 iter/sec (stddev: 0.16290135322043248) 1.08

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.