def preprocessing_tracking(tracking_df):
    """
    Preprocesses the tracking data frame, by changing the time values of the second have,
    splitting the DataFrame up in a home and away DataFrame. Changes the tracking data,
    so that each team plays in one direction the entire game and calculates the velocities of the players.

    Parameters
    -----------
        tracking_df: tracking DataFrame
    Returns
    -----------
        tracking_home: tracking DataFrame for the Home team
        tracking_away: tracking DataFrame for the Away team
    """
    # change time values and split the tracking data
    tracking_df = change_time_values_tracking(tracking_df)
    tracking_home, tracking_away = split_tracking_data(tracking_df)

    # reverse direction of play in the second half so that home team is always attacking from right->left
    tracking_home = change_to_single_playing_direction(tracking_home)
    tracking_away = change_to_single_playing_direction(tracking_away)

    # calculate the player velocities
    tracking_home = mvel.calc_player_velocities(tracking_home, smoothing=True)
    tracking_away = mvel.calc_player_velocities(tracking_away, smoothing=True)
    return tracking_home, tracking_away
Ejemplo n.º 2
0
def populate_tracking_dataframes():
    tracking_home = mio.tracking_data(DATA_DIR, MATCH_ID, 'Home')
    tracking_away = mio.tracking_data(DATA_DIR, MATCH_ID, 'Away')
    events = mio.read_event_data(DATA_DIR, MATCH_ID)

    tracking_home = mio.to_metric_coordinates(tracking_home)
    tracking_away = mio.to_metric_coordinates(tracking_away)
    events = mio.to_metric_coordinates(events)

    tracking_home = mvel.calc_player_velocities(tracking_home, smoothing=True)
    tracking_away = mvel.calc_player_velocities(tracking_away, smoothing=True)

    return mio.to_single_playing_direction(tracking_home, tracking_away, events)
Ejemplo n.º 3
0
events = mio.read_event_data(DATADIR, game_id)

# Using Metricas function to prep tracking_data that will allow us to find: single playing direction and passing probabilities towards the end.
tracking_home = mio.tracking_data(DATADIR, game_id, 'Home')
tracking_away = mio.tracking_data(DATADIR, game_id, 'Away')

tracking_home = mio.to_metric_coordinates(tracking_home)
tracking_away = mio.to_metric_coordinates(tracking_away)
events = mio.to_metric_coordinates(events)

tracking_home, tracking_away, events = mio.to_single_playing_direction(
    tracking_home, tracking_away, events)

tracking_home = mvel.calc_player_velocities(tracking_home,
                                            smoothing=True,
                                            filter_='moving average')
tracking_away = mvel.calc_player_velocities(tracking_away,
                                            smoothing=True,
                                            filter_='moving average')

shots_map = events[(events['Type'] == 'SHOT') & (events['Team'] == 'Home')]
mviz.plot_events(goals_map, color='k', indicators=['Marker'], annotate=True)

# Defenders in front of ball for Home team shots
defenders = []
for i in shots_map.index:
    ball = tracking_away.loc[i, 'ball_x']

    players_count = [
        player for player in tracking_away.columns
# region Laurie's code
game_id = 2  # let's look at sample match 2

# read in the event data
events = mio.read_event_data(DATADIR, game_id)

# read in tracking data
tracking_home = mio.tracking_data(DATADIR, game_id, "Home")
tracking_away = mio.tracking_data(DATADIR, game_id, "Away")

# Convert positions from metrica units to meters (note change in Metrica's coordinate system since the last lesson)
tracking_home = mio.to_metric_coordinates(tracking_home)
tracking_away = mio.to_metric_coordinates(tracking_away)
events = mio.to_metric_coordinates(events)

# reverse direction of play in the second half so that home team is always attacking from right->left
tracking_home, tracking_away, events = mio.to_single_playing_direction(
    tracking_home, tracking_away, events)

# Calculate player velocities
tracking_home = mvel.calc_player_velocities(tracking_home, smoothing=True)
tracking_away = mvel.calc_player_velocities(tracking_away, smoothing=True)
params = mpc.default_model_params(3)
# endregion

# Get GK numbers
GK_numbers = [
    mio.find_goalkeeper(tracking_home),
    mio.find_goalkeeper(tracking_away)
]