GameDataset is a class that will hold methods and data for one game. PatternsSet is a calss that willhold methods, patterns, and pattern_events data for this game.
import sys sys.path.insert(1, '../../') from codeball import GameDataset, PatternsSet
Define data files. Currently reading the files in the test folder of the package. Initialize game dataset. This loads the data for each data type using Kloppy, and then stores it on game_dataset as instances of TrackinDataFrame and EventsDataFrame. Both of them are subclasses of a pandas Dataframe. Other than holding the data in a dataframe, they also have methods to work with, filter etc the data they contain.
metadata_file = (r"../../codeball/tests/files/metadata.xml") tracking_file = (r"../../codeball/tests/files/tracking.txt") events_file = (r"../../codeball/tests/files/events.json") game_dataset = GameDataset( tracking_metadata_file=metadata_file, tracking_data_file=tracking_file, events_metadata_file=metadata_file, events_data_file=events_file, )
Instantiate PatternSet and run and export patterns for play.¶
The first step is to instantiate a PatternsSet instance. It takes as arugment a GameDataset instance so that all patterns can have access to the data of the game. Conceptually a pattern is an analysis that will return the moments in the game a certain thing happend, with that thing being defined in the pattern / analysis. For example, look for all passes into the box.
Next step is to initialize the patterns by reading the patterns config from ../codeball/patterns/patterns_config.json. However you can specify your own pattern config by providing it as an input to initialize_patterns. Then
run_patterns iterates over all the patterns in the PatternSet and runs them. Finally,
save_patterns_for_play method takes all the Patterns and PatternEvents in the PatternsSet and outputs them on a json fotmat that can be imported into Metrica Play via Metrica Cloud.
If you didn't clone the repo, you can get the config file here.
patterns_set = PatternsSet(game_dataset=game_dataset) patterns_set.initialize_patterns(config_file=r"../../codeball/patterns/patterns_config.json") patterns_set.run_patterns() patterns_set.save_patterns_for_play("output.patt")