Skip to content

Commit

Permalink
Syntax fixes + Type clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
DivvyCr committed Jul 22, 2020
1 parent d3b3216 commit 3a660aa
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions carball/analysis/stats/boost/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def calculate_player_stat(self, player_stat_map: Dict[str, PlayerStats], game: G
if 'boost_collect' not in player_data_frame:
logger.warning('%s did not collect any boost', player_key)
else:
self.calculate_and_set_player_wasted_collection(player_data_frame)
self.count_and_set_pad_collection(player_data_frame)
self.count_and_set_stolen_boosts(player_data_frame, player_map[player_key].is_orange)
self.calculate_and_set_player_wasted_collection(player_data_frame, proto_boost)
self.count_and_set_pad_collection(player_data_frame, proto_boost)
self.count_and_set_stolen_boosts(player_data_frame, player_map[player_key].is_orange, proto_boost)

@staticmethod
def get_player_boost_usage(player_dataframe: pd.DataFrame) -> np.float64:
Expand All @@ -54,7 +54,7 @@ def get_average_boost_level(player_dataframe: pd.DataFrame) -> np.float64:
return player_dataframe.boost.mean(skipna=True) / 255 * 100

@classmethod
def count_and_set_stolen_boosts(cls, player_dataframe: pd.DataFrame, is_orange):
def count_and_set_stolen_boosts(cls, player_dataframe: pd.DataFrame, is_orange, proto_boost):
big = cls.field_constants.get_big_pads()
# Get big pads below or above 0 depending on team
# The index of y position is 1. The index of the label is 2.
Expand Down Expand Up @@ -112,7 +112,7 @@ def get_player_boost_collection(player_dataframe: pd.DataFrame) -> Dict[str, int
# NEW (DivvyC)

@staticmethod
def get_wasted_big(gains_index, player_data_frame):
def get_wasted_big(gains_index: np.ndarray, player_data_frame: pd.DataFrame):
# Get all frames (by their index) where the player collected more than 34 boost.
collect_frames = player_data_frame.loc[player_data_frame.index[player_data_frame['boost_collect'] > 34]]

Expand All @@ -125,7 +125,7 @@ def get_wasted_big(gains_index, player_data_frame):
return wasted_big

@staticmethod
def get_wasted_small(gains_index, player_data_frame):
def get_wasted_small(gains_index: np.ndarray, player_data_frame: pd.DataFrame):
# Now, get all frames (by their index) where the player collected less than 34 boost.
collect_frames = player_data_frame.loc[player_data_frame.index[player_data_frame['boost_collect'] <= 34]]

Expand All @@ -140,32 +140,32 @@ def get_wasted_small(gains_index, player_data_frame):
return wasted_small

@staticmethod
def get_gains_index(player_data_frame):
def get_gains_index(player_data_frame: pd.DataFrame):
# Get differences in boost (on a frame-by-frame basis), and only keep entries that are >= 0.
gains_index = player_data_frame['boost'].diff().clip(0)
# Get all frame indexes with non-zero values (i.e. boost gain), as a numpy array.
gains_index = gains_index.loc[gains_index > 0].index.to_numpy()
return gains_index

@staticmethod
def calculate_and_set_player_wasted_collection(player_data_frame):
def calculate_and_set_player_wasted_collection(player_data_frame: pd.DataFrame, proto_boost):
# Get gains_index, which returns a numpy array of all indexes where the player gained (collected) boost.
gains_index = self.get_gains_index(player_data_frame)
gains_index = BoostStat.get_gains_index(player_data_frame)

# Get wasted_big, and set it to the appropriate API field.
wasted_big = self.get_wasted_big(gains_index, player_data_frame)
wasted_big = BoostStat.get_wasted_big(gains_index, player_data_frame)
proto_boost.wasted_big = wasted_big

# Get wasted_small, and set it to the appropriate API field.
wasted_small = self.get_wasted_small(gains_index, player_data_frame)
wasted_small = BoostStat.get_wasted_small(gains_index, player_data_frame)
proto_boost.wasted_small = wasted_small

# Add wasted_small/big to get wasted_collection, and set it to the appropriate API field.
proto_boost.wasted_collection = wasted_big + wasted_small

@staticmethod
def count_and_set_pad_collection(player_data_frame):
collection = self.get_player_boost_collection(player_data_frame)
def count_and_set_pad_collection(player_data_frame: pd.DataFrame, proto_boost):
collection = BoostStat.get_player_boost_collection(player_data_frame)
if 'small' in collection and collection['small'] is not None:
proto_boost.num_small_boosts = collection['small']
if 'big' in collection and collection['big'] is not None:
Expand Down

3 comments on commit 3a660aa

@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: 3a660aa Previous: 5d4385d Ratio
carball/tests/benchmarking/benchmarking.py::test_short_dropshot 0.6297952673983204 iter/sec (stddev: 0.011912304991155528) 0.6085909623600966 iter/sec (stddev: 0.025514623338161) 0.97

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: 3a660aa Previous: 5d4385d Ratio
carball/tests/benchmarking/benchmarking.py::test_short_sample 0.836152137855731 iter/sec (stddev: 0.010318945183143316) 0.899917375607017 iter/sec (stddev: 0.007431821317809326) 1.08

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: 3a660aa Previous: 5d4385d Ratio
carball/tests/benchmarking/benchmarking.py::test_intensive_oce_rlcs 0.04866476331107791 iter/sec (stddev: 0.5077674045101387) 0.06464355463319495 iter/sec (stddev: 0.09647825883678236) 1.33

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

Please sign in to comment.