Skip to content

Commit

Permalink
Add ballcam/handbrake times (#259)
Browse files Browse the repository at this point in the history
* Add ballcam/handbrake times

* Remove comments
  • Loading branch information
Sciguymjm authored Oct 14, 2020
1 parent 29a4c27 commit 3e66f17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CARBALL_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
2 changes: 2 additions & 0 deletions api/stats/player_stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ message Controller {
optional bool is_keyboard = 1;
optional float analogue_steering_input_percent = 2;
optional float analogue_throttle_input_percent = 3;
optional float time_ballcam = 4;
optional float time_handbrake = 5;
}

// Stats for carrying
Expand Down
17 changes: 17 additions & 0 deletions carball/analysis/stats/controls/controls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from logging import getLogger
from typing import Dict

import numpy as np
import pandas as pd

from ....analysis.stats.stats import BaseStat
from ....analysis.stats.utils.pandas_utils import sum_deltas_by_truthy_data
from ....generated.api import game_pb2
from ....generated.api.player_pb2 import Player
from ....generated.api.stats.player_stats_pb2 import PlayerStats
Expand All @@ -20,6 +22,7 @@ def calculate_player_stat(self, player_stat_map: Dict[str, PlayerStats], game: G
for player_key, stats in player_map.items():
try:
player_name = player_map[player_key].name
player_data_frame = data_frame[player_name].copy()

steering_percentage = self.get_analogue_percentage("steer", data_frame, player_name)
throttle_percentage = self.get_analogue_percentage("throttle", data_frame, player_name)
Expand All @@ -29,10 +32,24 @@ def calculate_player_stat(self, player_stat_map: Dict[str, PlayerStats], game: G
controller_stats.is_keyboard = is_keyboard
controller_stats.analogue_steering_input_percent = throttle_percentage
controller_stats.analogue_throttle_input_percent = steering_percentage
if 'ball_cam' in player_data_frame:
time_ballcam = self.get_ballcam_duration(data_frame, player_data_frame)
controller_stats.time_ballcam = time_ballcam
if 'handbrake' in player_data_frame:
time_handbrake = self.get_handbrake_duration(data_frame, player_data_frame)
controller_stats.time_handbrake = time_handbrake
except KeyError as e:
logger.warning('Player never pressed control %s', e)

def get_analogue_percentage(self, column: str, data_frame: pd.DataFrame, player_name: str):
total_frames = len(data_frame[player_name][column])
count = (data_frame[player_name][column] == 0).sum() + (data_frame[player_name][column] == 128).sum() + (data_frame[player_name][column] == 255).sum() + data_frame[player_name][column].isna().sum()
return 100 - ((count * 100) / total_frames)

@staticmethod
def get_ballcam_duration(data_frame: pd.DataFrame, player_dataframe: pd.DataFrame) -> np.float64:
return sum_deltas_by_truthy_data(data_frame, player_dataframe.ball_cam)

@staticmethod
def get_handbrake_duration(data_frame: pd.DataFrame, player_dataframe: pd.DataFrame) -> np.float64:
return sum_deltas_by_truthy_data(data_frame, player_dataframe.handbrake)

5 comments on commit 3e66f17

@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: 3e66f17 Previous: 29a4c27 Ratio
carball/tests/benchmarking/benchmarking.py::test_short_dropshot 0.6785955214615597 iter/sec (stddev: 0.02087314628455382) 0.6574284944937312 iter/sec (stddev: 0.03759415267222453) 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: 3e66f17 Previous: 29a4c27 Ratio
carball/tests/benchmarking/benchmarking.py::test_short_sample 0.7480469859504734 iter/sec (stddev: 0.010087323772397754) 0.9086366692845125 iter/sec (stddev: 0.046492523318716526) 1.21

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: 3e66f17 Previous: 29a4c27 Ratio
carball/tests/benchmarking/benchmarking.py::test_intensive_oce_rlcs 0.053363327923610496 iter/sec (stddev: 0.351571363744279) 0.056959625521488214 iter/sec (stddev: 0.16530996945515755) 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 oce_rlcs

Benchmark suite Current: 3e66f17 Previous: 29a4c27 Ratio
carball/tests/benchmarking/benchmarking.py::test_oce_rlcs 0.07479184586951351 iter/sec (stddev: 0.22444644295932295) 0.07494548572016133 iter/sec (stddev: 0.13970046603188085) 1.00

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: 3e66f17 Previous: 29a4c27 Ratio
carball/tests/benchmarking/benchmarking.py::test_full_rumble 0.07110837400985422 iter/sec (stddev: 0.11493127712456662) 0.09148565538353834 iter/sec (stddev: 0.062408556983764706) 1.29

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

Please sign in to comment.