-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from PySport/metrica-tracking-serializer
Metrica tracking serializer
- Loading branch information
Showing
28 changed files
with
1,701 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
v0.1, 2020-04-23 -- Initial release. | ||
v0.1.0, 2020-04-23 -- Initial release. | ||
v0.2.0, 2020-05-05 -- Change interface of TrackingDataSerializer | ||
Add Metrica Tracking Serializer including automated tests | ||
Cleanup some import statements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .infra.serializers import TRACABSerializer | ||
from .infra.serializers import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .models import * | ||
from .services.transformers import * | ||
from .services import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
from .tracking import * | ||
from .common import * | ||
from .pitch import * | ||
from .tracking import * | ||
# NOT YET: from .event import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from abc import ABC | ||
from dataclasses import dataclass | ||
from enum import Enum, Flag | ||
from typing import Optional, List | ||
|
||
from .pitch import PitchDimensions | ||
|
||
|
||
class Team(Enum): | ||
HOME = "home" | ||
AWAY = "away" | ||
|
||
|
||
class BallState(Enum): | ||
ALIVE = "alive" | ||
DEAD = "dead" | ||
|
||
|
||
class AttackingDirection(Enum): | ||
HOME_AWAY = "home-away" # home L -> R, away R -> L | ||
AWAY_HOME = "away-home" # home R -> L, away L -> R | ||
NOT_SET = "not-set" # not set yet | ||
|
||
|
||
class Orientation(Enum): | ||
# change when possession changes | ||
BALL_OWNING_TEAM = "ball-owning-team" | ||
|
||
# changes during half-time | ||
HOME_TEAM = "home-team" | ||
AWAY_TEAM = "away-team" | ||
|
||
# won't change during match | ||
FIXED_HOME_AWAY = "fixed-home-away" | ||
FIXED_AWAY_HOME = "fixed-away-home" | ||
|
||
def get_orientation_factor(self, | ||
attacking_direction: AttackingDirection, | ||
ball_owning_team: Team): | ||
if self == Orientation.FIXED_HOME_AWAY: | ||
return -1 | ||
elif self == Orientation.FIXED_AWAY_HOME: | ||
return 1 | ||
elif self == Orientation.HOME_TEAM: | ||
if attacking_direction == AttackingDirection.HOME_AWAY: | ||
return -1 | ||
else: | ||
return 1 | ||
elif self == Orientation.AWAY_TEAM: | ||
if attacking_direction == AttackingDirection.AWAY_HOME: | ||
return -1 | ||
else: | ||
return 1 | ||
elif self == Orientation.BALL_OWNING_TEAM: | ||
if ((ball_owning_team == Team.HOME | ||
and attacking_direction == AttackingDirection.HOME_AWAY) | ||
or | ||
(ball_owning_team == Team.AWAY | ||
and attacking_direction == AttackingDirection.AWAY_HOME)): | ||
return -1 | ||
else: | ||
return 1 | ||
|
||
|
||
@dataclass | ||
class Period: | ||
id: int | ||
start_timestamp: float | ||
end_timestamp: float | ||
attacking_direction: Optional[AttackingDirection] = AttackingDirection.NOT_SET | ||
|
||
def contains(self, timestamp: float): | ||
return self.start_timestamp <= timestamp <= self.end_timestamp | ||
|
||
@property | ||
def attacking_direction_set(self): | ||
return self.attacking_direction != AttackingDirection.NOT_SET | ||
|
||
def set_attacking_direction(self, attacking_direction: AttackingDirection): | ||
self.attacking_direction = attacking_direction | ||
|
||
|
||
class DataSetFlag(Flag): | ||
BALL_OWNING_TEAM = 1 | ||
BALL_STATE = 2 | ||
|
||
|
||
@dataclass | ||
class DataRecord(ABC): | ||
timestamp: float | ||
ball_owning_team: Team | ||
ball_state: BallState | ||
|
||
period: Period | ||
|
||
|
||
@dataclass | ||
class DataSet(ABC): | ||
flags: DataSetFlag | ||
pitch_dimensions: PitchDimensions | ||
orientation: Orientation | ||
periods: List[Period] | ||
records: List[DataRecord] | ||
|
||
|
Oops, something went wrong.