|
1 | 1 | import logging |
2 | 2 | from time import sleep |
3 | 3 | from typing import Callable |
| 4 | +import carball |
4 | 5 | import ballchasing |
5 | 6 | from requests import Response |
6 | 7 |
|
|
20 | 21 | BACKOFF_FACTOR = config["ballchasing"]["backoffFactor"] |
21 | 22 | DELAYS = [0, *(BACKOFF_FACTOR**(r + 1) for r in range(MAX_RETRIES))] |
22 | 23 |
|
23 | | -if PARSER != "ballchasing": |
24 | | - raise Exception(f"Unknown parser {PARSER}. Only 'ballchasing' is currently supported.") |
| 24 | +if PARSER != "carball" and PARSER != "ballchasing": |
| 25 | + raise Exception(f"Unknown parser {PARSER}. Please specify either 'carball' or 'ballchasing'.") |
25 | 26 |
|
26 | 27 |
|
27 | 28 | def parse(path: str, on_progress: Callable[[str], None] = None): |
| 29 | + if PARSER == "carball": |
| 30 | + return _parse_carball(path, on_progress) |
28 | 31 | if PARSER == "ballchasing": |
29 | 32 | return _parse_ballchasing(path, on_progress) |
30 | 33 | raise Exception(f"Parser {PARSER} not supported") |
31 | 34 |
|
32 | 35 |
|
33 | 36 |
|
| 37 | +############################### |
| 38 | +# |
| 39 | +# Carball |
| 40 | +# |
| 41 | +############################### |
| 42 | + |
| 43 | +def _parse_carball(path: str, on_progress: Callable[[str], None] = None) -> dict: |
| 44 | + """ |
| 45 | + Parses a Rocket League replay located at a given local path |
| 46 | +
|
| 47 | + Args: |
| 48 | + path (str): The local path of the replay file to parse |
| 49 | +
|
| 50 | + Returns: |
| 51 | + dict: A dictionary containing all of the stats returned by carball |
| 52 | + """ |
| 53 | + logging.info(f"Parsing {path} with carball") |
| 54 | + |
| 55 | + analysis_manager = carball.analyze_replay_file(path, logging_level=print) |
| 56 | + return analysis_manager.get_json_data() |
| 57 | + |
| 58 | + |
| 59 | + |
34 | 60 | ############################### |
35 | 61 | # |
36 | 62 | # Ballchasing |
|
0 commit comments