Download grid_map/validator.py from build-small-hackathon/phantom-grid: direct link, hf CLI and curl.
- Browser
- Download file 639 Bytes
-
https://huggingface.co/spaces/build-small-hackathon/phantom-grid/resolve/4f670ea00a0db95a9e7dc6d80aa620e07d0e048f/grid_map/validator.py
- Command line
-
hf download hf://spaces/build-small-hackathon/phantom-grid@4f670ea00a0db95a9e7dc6d80aa620e07d0e048f/grid_map/validator.py
-
curl -L -o validator.py https://huggingface.co/spaces/build-small-hackathon/phantom-grid/resolve/4f670ea00a0db95a9e7dc6d80aa620e07d0e048f/grid_map/validator.py
639 Bytes
| from __future__ import annotations | |
| def validate_graph(graph: dict) -> list[str]: | |
| errors: list[str] = [] | |
| node_ids = {int(node["id"]) for node in graph.get("nodes", [])} | |
| for edge in graph.get("edges", []): | |
| source = int(edge["source"]) | |
| target = int(edge["target"]) | |
| if source not in node_ids: | |
| errors.append(f"Edge source {source} is missing from nodes") | |
| if target not in node_ids: | |
| errors.append(f"Edge target {target} is missing from nodes") | |
| if not edge.get("modes"): | |
| errors.append(f"Edge {source}-{target} has no transport modes") | |
| return errors | |