Example #1
0
    def get_distance_to_goal(data_frame: pd.DataFrame, hit: Hit,
                             player_map: Dict[str, Player]):
        ball_data = BaseHit.get_ball_data(data_frame, hit)
        _goal_x = min(max(ball_data['pos_x'], GOAL_X / 2), -GOAL_X / 2)
        _goal_y = -MAP_Y / 2 if player_map[
            hit.player_id.id].is_orange else MAP_Y / 2

        displacement = ball_data[['pos_x', 'pos_y'
                                  ]].values - (_goal_x, _goal_y)
        distance = np.sqrt(np.square(displacement).sum())

        return distance
Example #2
0
    def next_hit_stats(data_frame: pd.DataFrame, saltie_hit: Hit,
                       next_saltie_hit: Hit, player_map: Dict[str, Player],
                       last_passing_hit: Hit):
        """
        finds stats that happen based off of the next hit.
        Passes, dribbles are found here, also candidates for assists.
        :param game:
        :param saltie_hit:
        :param next_saltie_hit:
        :param player_map:
        :param last_passing_hit:
        :return:
        """

        # distance the ball traveled
        displacement = (BaseHit.get_ball_data(data_frame, next_saltie_hit)[[
            'pos_x', 'pos_y', 'pos_z'
        ]].values - BaseHit.get_ball_data(
            data_frame, saltie_hit)[['pos_x', 'pos_y', 'pos_z']].values)
        saltie_hit.distance = np.sqrt(np.square(displacement).sum())

        # dribble detection
        if saltie_hit.player_id.id == next_saltie_hit.player_id.id:
            if not saltie_hit.dribble_continuation:
                saltie_hit.dribble = True
                next_saltie_hit.dribble_continuation = True
        else:
            last_passing_hit = None
            # passing detection
            if player_map[saltie_hit.player_id.id].is_orange == player_map[
                    next_saltie_hit.player_id.id].is_orange:
                saltie_hit.pass_ = True
                next_saltie_hit.passed = True
                last_passing_hit = saltie_hit

        return last_passing_hit
Example #3
0
    def create_hit_events(self, game: Game, proto_game: game_pb2.Game,
                          player_map: Dict[str,
                                           Player], data_frame: pd.DataFrame,
                          kickoff_frames: pd.DataFrame,
                          first_touch_frames: pd.Series):
        """
        Creates all of the events for hits
        """
        logger.info("Looking for hits.")
        hits = BaseHit.get_hits_from_game(game, proto_game, self.id_creator,
                                          data_frame, first_touch_frames)
        logger.info("Found %s hits." % len(hits))

        SaltieHit.get_saltie_hits_from_game(proto_game, hits, player_map,
                                            data_frame, kickoff_frames)
        logger.info("Analysed hits.")
Example #4
0
 def get_shot(data_frame: pd.DataFrame, saltie_hit: Hit,
              player_map: Dict[str, Player]):
     """
     Finds shots using ball prediction.
     :param game:
     :param saltie_hit:
     :param player_map:
     """
     # find shots
     # TODO: Support non-standard maps? Raise warning/don't predict for non-standard maps?
     player = player_map[saltie_hit.player_id.id]
     ball_sim = BallSimulator(BaseHit.get_ball_data(data_frame, saltie_hit),
                              player.is_orange)
     is_shot = ball_sim.get_is_shot()
     if is_shot:
         saltie_hit.shot = True
         # if saltie_hit.goal:
         #    logger.debug('Found shot for goal:')
     if saltie_hit.goal and not is_shot:
         logger.warning(
             f'Goal is not shot: frame {saltie_hit.frame_number} by {player.name}'
         )