<jupyter_start><jupyter_text>ModulesGameDataset 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.<jupyter_code>import sys
sys.path.insert(1, '../../')

from codeball import GameDataset, PatternsSet<jupyter_output><empty_output><jupyter_text>Initialize GameDatasetDefine 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.<jupyter_code>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,
)<jupyter_output><empty_output><jupyter_text>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](https://github.com/metrica-sports/codeball/blob/master/codeball/patterns/patterns_config.json).<jupyter_code>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")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07023019898556379, 'fraction_numerical': 0.0003901677721420211, 'mean_word_length': 5.50761421319797, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '335947', 'license': 'MIT', 'n_tokens_mistral': 715, 'n_tokens_neox': 709, 'n_words': 277, 'path': 'docs/examples/run_patterns.ipynb', 'repo_name': 'metrica-sports/codeball', 'size': '2563'}