pysoccer.serializers.WyscoutSerializer package

Submodules

pysoccer.serializers.WyscoutSerializer.eventSerializer module

class pysoccer.serializers.WyscoutSerializer.eventSerializer.WyscoutEventSerializer

Bases: pysoccer.base.EventSerializer

Class that implements a serializer for Wyscout events.

get_challenged_player(index, events)

Function that computes the callenged player in a duel event. It search for a corresponding duel event. If there isn’t it search for the closest opponent team’s event and assume the player involved in that event as the callenged one. Separate if clause are needed to accurately separe the cases.

Parameters
  • index – index of the duel event

  • events – list containing the match’s events

Returns

the challenged player if there’s one, None otherwise

get_goal_position(event)

Function that calculate where a shot ended. The goal is divided in a 3x3 with the zones named . Then there is a zone over the bar and two on the sides of the posts.

Parameters

event – shot event that the function computes

Returns

the position where the shot ended

get_label(event, tags, outcome)str

Function that computes the event label. It append the event name to the sub event name separated by a minus. Then in the same way it appends the event’s tag names. Finally the event’s outcome is appended.

Parameters
  • event – the event we’re creating the label for

  • tags – the event’s tags

  • outcome – the event’s outcome

get_outcome(event, events, curr_phase, next_phase, tags)

Fuction that computes the outcome of an event.

Parameters
  • event – event whose outcome is beign computed

  • events – list containing the match’s events

  • phases – list containing the possession phases

  • tags – list containing the event’s tags

Returns

the outcome of the event

get_receiver(event, tags, events)

Fuction that calculates the receiver of a pass.

Parameters
  • event – pass event whose receiver is beign calculated

  • tags – list containing the event’s tags

  • events – list containing the match’s events

Returns

the receiver if the pass was accurate, None otherwise

get_team_possession_time(events: List, team: int)float

Function that computes the possession time of a single team

Parameters
  • events – the list of events

  • team – the team whose possession is computed

Returns

the minutes of possession

serialize(input: List)

Serializer that convert a list of Wyscout events in a list of standardized events.

Parameters

input – list containing the Wyscout events

Returns

list containing the standardized events

pysoccer.serializers.WyscoutSerializer.matchSerializer module

pysoccer.serializers.WyscoutSerializer.phaseDetection module

pysoccer.serializers.WyscoutSerializer.phaseDetection.get_period_offset(db)
pysoccer.serializers.WyscoutSerializer.phaseDetection.get_play_actions(db, verbose=False)

Given a list of events of a single match, it splits the events into possession phases using the following principle: - an action begins when a team gains ball possession - an action ends if one of two cases occurs: – there is interruption of the match, due to: 1) end of first half or match; 2) ball out of the field 3) offside 4) foul – ball is played by the opposite team w.r.t. to the team who is owning the ball

Returns

a list, where each item is a tuple including: - event outcome: ball lost | shot | interruption | penalty - phase events list

pysoccer.serializers.WyscoutSerializer.phaseDetection.get_tag_list(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_accurate_pass(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_ball_lost(event, previous_event)

note: not considering touch and cleareance as possession event

pysoccer.serializers.WyscoutSerializer.phaseDetection.is_duel(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_goal(event)

Check if it is a goal or own goal. To detect sudden goal form not usual event types (touches acceleration whatever)

pysoccer.serializers.WyscoutSerializer.phaseDetection.is_interruption(event, current_half)

Verify whether or not an event is a game interruption. A game interruption can be due to a ball our of the field, a whistle by the referee, a fouls, an offside, a goal, the end of the first half or the end of the game.

Parameters
  • event – dict a dictionary describing the event

  • current_half – str the current half of the match (1H = first half, 2H == second half)

Returns

True is the event is an interruption, False otherwise

pysoccer.serializers.WyscoutSerializer.phaseDetection.is_other(event)

Check for cleareance and touches

pysoccer.serializers.WyscoutSerializer.phaseDetection.is_pass(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_penalty(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_reflexes(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_save_attempt(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.is_shot(event)

Verify whether or not the event is a shot. Sometimes, a play action can continue after a shot if the team gains again the ball. We account for this case by looking at the next events of the game.

Parameters

event – dict a dictionary describing the event

Returns

True is the event is a shot, False otherwise

pysoccer.serializers.WyscoutSerializer.phaseDetection.is_touch(event)
pysoccer.serializers.WyscoutSerializer.phaseDetection.pre_process(events)

Duels appear in pairs in the streamflow: one event is by a team and the other by the opposing team. This can create

pysoccer.serializers.WyscoutSerializer.phaseFeatures module

pysoccer.serializers.WyscoutSerializer.phaseFeatures.cleareances(phase)

cleareances: n. of clearances

pysoccer.serializers.WyscoutSerializer.phaseFeatures.compute_shot_features(phase)

it computes the features of a shot / free kick event, for xg computation

pysoccer.serializers.WyscoutSerializer.phaseFeatures.create_xg_model(events_list, matches, tree_fname='xg_model.joblib', encoder_fname='label_encoder.joblib')

creation of a sklearn model

pysoccer.serializers.WyscoutSerializer.phaseFeatures.d(start, stop)

angular distance difference between start ant stop events we consider first position as event position

Parameters
  • start – event positions

  • stop – event positions

pysoccer.serializers.WyscoutSerializer.phaseFeatures.duels(phase)

duels on 1st third: n. of passess conceded with origin x in [66,100] duels on 2nd third: n. of passess conceded with origin x in [33,66] duels on 3d third: n. of passess conceded with origin x in [0,33]

pysoccer.serializers.WyscoutSerializer.phaseFeatures.duels_count(phase)
pysoccer.serializers.WyscoutSerializer.phaseFeatures.duration(phase)

duration of possessing events

pysoccer.serializers.WyscoutSerializer.phaseFeatures.expected_goals(phase, model, label_encoder)

computing expected goals for a phase according to input model

Parameters
  • phase – phase object, tuple

  • model – sklearn model

pysoccer.serializers.WyscoutSerializer.phaseFeatures.fouls(phase)

fouls: n. of fouls

pysoccer.serializers.WyscoutSerializer.phaseFeatures.goal_count(phase)

it counts the number of goals in a phase, excluding save attempts events (eventId = 9)

pysoccer.serializers.WyscoutSerializer.phaseFeatures.invasion(phase, verbose=False)

it computes the invasion of each possesion phase invasion index is the maximum closeness, across a possession phase, between the ball and opponents goal. it is the closest point, w.r.t. opponents goal, where the possessing team manages to bring the ball

pysoccer.serializers.WyscoutSerializer.phaseFeatures.last_ball_location(shot, prev_events, time_window=3)

it computes the average distance from shots location to previous <time_window> events. it could be useful to distinguish among high and low pressure situation

Parameters
  • shot – a shot event

  • prev_Events – a list of previous events

  • time_window – previous time window to consider (in seconds)

pysoccer.serializers.WyscoutSerializer.phaseFeatures.pass_length(phase)

average lenght of all the passes within the phase

pysoccer.serializers.WyscoutSerializer.phaseFeatures.passes_direction(phase)

counting forward, lateral and back passes

pysoccer.serializers.WyscoutSerializer.phaseFeatures.phase_wideness(phase)

average and std y of each ball position to asses pitch usage on y dimension

pysoccer.serializers.WyscoutSerializer.phaseFeatures.players_involved(phase)

returns the players involved in each phase

pysoccer.serializers.WyscoutSerializer.phaseFeatures.possessing_team(phase)

returns the possessing team of the phase

pysoccer.serializers.WyscoutSerializer.phaseFeatures.shots(phase)

shots: n. of shots conceded

pysoccer.serializers.WyscoutSerializer.phaseFeatures.shots_distance(phase)
pysoccer.serializers.WyscoutSerializer.phaseFeatures.space_gain(phase)

it computes space gained between start and stop of the phase. It returns the gain and the final position of the phase

pysoccer.serializers.WyscoutSerializer.phaseFeatures.space_gain_speed(phase)

it computes space gained between start and tertile_i of the phase. It returns the speed in this segment of the phase. Segments are computed according to the duration

pysoccer.serializers.WyscoutSerializer.phaseFeatures.speed_step(phase)

it computes the space gain speed for each step of the phase. For each step (pass etc) it computes relative space gain / elapsed time

pysoccer.serializers.WyscoutSerializer.phaseFeatures.start_x(phase)

return starting x position of the possesion phase

pysoccer.serializers.WyscoutSerializer.phaseFeatures.timestamp(phase, offset)

return the absolute timestamp of the first event of the phase

Parameters
  • phase – a list of events corresponding to a possesion phase

  • offest – dictionary with offset for each period of the match

pysoccer.serializers.WyscoutSerializer.wyscoutAttributes module

Module contents