Spaces:
Running on T4
Running on T4
Download baseball_batting/history.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/baseball_batting/history.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/baseball_batting/history.py
-
curl -L -o history.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/baseball_batting/history.py
1.79 kB
| """Only explicit identity and matching context/processing support trial comparisons.""" | |
| from pathlib import Path | |
| from .storage import read_json, digest | |
| def comparison_key(result): | |
| capture=result["capture"];metadata=capture["metadata"] | |
| return digest({"engine_code_hash":result["engine_code_hash"],"models":result["model_hashes"], | |
| "geometry":metadata.get("calibration"),"task":metadata.get("swing_task"), | |
| "context":{k:v for k,v in metadata.get("event_context",{}).items() if k in | |
| {"intended_contact_location","pitch_location","pitch_type","lead_side","pitcher_direction_image"}}, | |
| "handedness":metadata.get("handedness"), | |
| "resolution":[capture["frames"][0]["width"],capture["frames"][0]["height"]], | |
| "timing":capture["timing_source"].get("kind"),"review":result["provenance"], | |
| "configuration":result["configuration"],"metric_versions":{m["metric_id"]:m["definition_version"] for m in result["metrics"]}}) | |
| def compatible_trials(root,result): | |
| root=Path(root);player=result["capture"]["metadata"].get("player_id") | |
| if not player or not result["capture"]["metadata"].get("swing_task"):return [] | |
| index=root.parent/"history.json" | |
| if not index.exists():return [] | |
| key=comparison_key(result);trials=[] | |
| for record in read_json(index): | |
| if record.get("player_id")!=player or record.get("input_sha256")==result["capture"]["input_sha256"]:continue | |
| target=(root.parent/record["result_path"]).resolve() | |
| if not target.is_relative_to(root.parent.resolve()) or not target.exists():continue | |
| previous=read_json(target) | |
| if comparison_key(previous)==key:trials.append(previous) | |
| return trials | |