Spaces:
Running
Running
| from __future__ import annotations | |
| import argparse | |
| from pathlib import Path | |
| from racing_reports.artifacts import DEFAULT_REPORT_ARTIFACTS | |
| from racing_reports.datastore import DataStore | |
| from racing_reports.match_index import MatchIndex | |
| from racing_reports.runner import ReportRunner, request_from_yaml | |
| def _sync(args) -> None: | |
| store = DataStore() | |
| path = store.sync_preprocessed(args.league, args.season, force=args.force) | |
| print(path) | |
| artifacts = list(args.artifact or []) | |
| if args.with_artifacts: | |
| artifacts.extend(DEFAULT_REPORT_ARTIFACTS) | |
| for artifact in dict.fromkeys(artifacts): | |
| print(store.sync_artifact(artifact, force=args.force)) | |
| def _list_matches(args) -> None: | |
| idx = MatchIndex(DataStore()) | |
| df = idx.build(args.league, args.season) | |
| if args.query: | |
| q = args.query.lower() | |
| mask = ( | |
| df["home_team"].str.lower().str.contains(q, na=False) | |
| | df["away_team"].str.lower().str.contains(q, na=False) | |
| | df["match_id"].str.lower().str.contains(q, na=False) | |
| | df["date"].str.lower().str.contains(q, na=False) | |
| ) | |
| df = df[mask] | |
| print(df.to_string(index=False)) | |
| def _run(args) -> None: | |
| request = request_from_yaml(Path(args.config)) | |
| result = ReportRunner().run(request) | |
| print(f"Output dir: {result.output_dir}") | |
| for name, path in result.html_paths.items(): | |
| print(f"{name}: {path}") | |
| print(f"manifest: {result.manifest_path}") | |
| def build_parser() -> argparse.ArgumentParser: | |
| parser = argparse.ArgumentParser(prog="racing-reports") | |
| sub = parser.add_subparsers(required=True) | |
| sync = sub.add_parser("sync", help="Descarga preprocessed/artifacts desde Azure al cache local.") | |
| sync.add_argument("--league", required=True) | |
| sync.add_argument("--season", required=True) | |
| sync.add_argument("--force", action="store_true") | |
| sync.add_argument("--with-artifacts", action="store_true", help="Descarga artifacts estándar para reportes predictivos.") | |
| sync.add_argument("--artifact", action="append", help="Artifact relativo a AZURE_REPORT_ARTIFACTS_ROOT.") | |
| sync.set_defaults(func=_sync) | |
| lm = sub.add_parser("list-matches", help="Lista partidos disponibles en el preprocessed cacheado.") | |
| lm.add_argument("--league", required=True) | |
| lm.add_argument("--season", required=True) | |
| lm.add_argument("--query") | |
| lm.set_defaults(func=_list_matches) | |
| run = sub.add_parser("run", help="Genera reportes desde un YAML.") | |
| run.add_argument("--config", required=True) | |
| run.set_defaults(func=_run) | |
| return parser | |
| def main(argv: list[str] | None = None) -> None: | |
| parser = build_parser() | |
| args = parser.parse_args(argv) | |
| args.func(args) | |
| if __name__ == "__main__": | |
| main() | |