Load every ``*.json`` trajectory under ``path``. ``path`` may be a directory or a single JSON file. If a trajectory has ``scenario_id`` set to null, the filename stem is used as a fallback. This supports layouts such as ``traces/trajectories/34.json`` where ``34`` is the scenario id
(path: Path)
| 13 | |
| 14 | |
| 15 | def load_trajectories(path: Path) -> list[PersistedTrajectory]: |
| 16 | """Load every ``*.json`` trajectory under ``path``. |
| 17 | |
| 18 | ``path`` may be a directory or a single JSON file. If a trajectory has |
| 19 | ``scenario_id`` set to null, the filename stem is used as a fallback. |
| 20 | This supports layouts such as ``traces/trajectories/34.json`` where |
| 21 | ``34`` is the scenario id. |
| 22 | """ |
| 23 | p = Path(path) |
| 24 | if p.is_file(): |
| 25 | return [_load_one_trajectory(p)] if p.suffix == ".json" else [] |
| 26 | |
| 27 | out: list[PersistedTrajectory] = [] |
| 28 | for child in sorted(p.glob("*.json")): |
| 29 | try: |
| 30 | out.append(_load_one_trajectory(child)) |
| 31 | except Exception: |
| 32 | _log.exception("loader: failed to parse %s", child) |
| 33 | return out |
| 34 | |
| 35 | |
| 36 | def _load_one_trajectory(path: Path) -> PersistedTrajectory: |