| |
| """CLI for Brettapps/trifecta-bro-v1. |
| |
| Usage: |
| # Run on the bundled sample race |
| python -m trifecta_bro_v1.main |
| |
| # Run on a Trifecta-Bro predictions JSON file |
| python -m trifecta_bro_v1.main --data /path/to/predictions-2026-08-10.json |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import sys |
| from pathlib import Path |
|
|
| from .artifact import predict_race, race_from_payload |
| from .predictor import TrifectaPredictor |
|
|
| |
| SAMPLE = { |
| "date": "2026-08-10", |
| "track": "Dubbo", |
| "track_slug": "dubbo", |
| "race_number": "3", |
| "race_name": "Aqua West Country Boosted BM58 Handicap", |
| "distance": "1620m", |
| "condition": "Soft 5", |
| "weather": "Showers", |
| "race_class": "BM58", |
| "start_time": "2026-08-10T04:40:00Z", |
| "prize_money": "30000", |
| "number_of_runners": 3, |
| "form": { |
| "runners": [ |
| {"number": 1, "name": "Boncapo", "form": "X1241", "stats": {"overall": {"winPercent": 0.25, "placePercent": 0.5}}}, |
| {"number": 14, "name": "Bill Peyto", "form": "36412", "stats": {"overall": {"winPercent": 0.07, "placePercent": 0.35}}}, |
| {"number": 7, "name": "Casterly Rock", "form": "23939", "stats": {"overall": {"winPercent": 0.06, "placePercent": 0.48}}}, |
| ] |
| }, |
| } |
|
|
|
|
| def main(argv: list[str] | None = None) -> int: |
| p = argparse.ArgumentParser(description="Brettapps/trifecta-bro/v1 predictor") |
| p.add_argument("--data", help="Path to a Trifecta-Bro predictions JSON file") |
| p.add_argument("--race", type=int, default=0, help="1-based race index when --data is given") |
| args = p.parse_args(argv) |
|
|
| if args.data: |
| payload = json.loads(Path(args.data).read_text()) |
| races = payload.get("races", [payload]) |
| idx = max(0, args.race - 1) |
| if idx >= len(races): |
| print(f"Race index {args.race} out of range (have {len(races)})", file=sys.stderr) |
| return 2 |
| race = race_from_payload(races[idx]) |
| else: |
| race = race_from_payload(SAMPLE) |
|
|
| pred = TrifectaPredictor().predict(race) |
| print(json.dumps(pred, indent=2)) |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|