Spaces:
Sleeping
Sleeping
Sync DemoService c45f234d157b3df3205fe2579537a04a2bddf459
Browse files
api/ai-service/tests/test_gpx_shape_templates.py
CHANGED
|
@@ -9,6 +9,7 @@ ROOT = Path(__file__).resolve().parents[3]
|
|
| 9 |
TEMPLATES = ROOT / "router" / "ai" / "data" / "gpx_shape_templates.json"
|
| 10 |
APPROVED_TEMPLATES = ROOT / "router" / "ai" / "data" / "approved_road_shape_templates.json"
|
| 11 |
TSHIRT_TEMPLATES = ROOT / "router" / "ai" / "data" / "tshirt_shape_templates.json"
|
|
|
|
| 12 |
STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates.json"
|
| 13 |
ALL_STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates_all.json"
|
| 14 |
ALL_DOG_TEMPLATES = ROOT / "router" / "ai" / "data" / "dog_shape_templates_all.json"
|
|
@@ -53,6 +54,21 @@ def test_tshirt_gpx_examples_are_available_for_road_generation():
|
|
| 53 |
assert all(-0.51 <= value <= 0.51 for point in outline for value in point)
|
| 54 |
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def test_new_star_gpx_examples_are_available_for_road_generation():
|
| 57 |
outlines = json.loads(STAR_TEMPLATES.read_text(encoding="utf-8"))["symbol_star"]
|
| 58 |
assert len(outlines) == 64
|
|
|
|
| 9 |
TEMPLATES = ROOT / "router" / "ai" / "data" / "gpx_shape_templates.json"
|
| 10 |
APPROVED_TEMPLATES = ROOT / "router" / "ai" / "data" / "approved_road_shape_templates.json"
|
| 11 |
TSHIRT_TEMPLATES = ROOT / "router" / "ai" / "data" / "tshirt_shape_templates.json"
|
| 12 |
+
ALL_TSHIRT_TEMPLATES = ROOT / "router" / "ai" / "data" / "tshirt_shape_templates_all.json"
|
| 13 |
STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates.json"
|
| 14 |
ALL_STAR_TEMPLATES = ROOT / "router" / "ai" / "data" / "star_shape_templates_all.json"
|
| 15 |
ALL_DOG_TEMPLATES = ROOT / "router" / "ai" / "data" / "dog_shape_templates_all.json"
|
|
|
|
| 54 |
assert all(-0.51 <= value <= 0.51 for point in outline for value in point)
|
| 55 |
|
| 56 |
|
| 57 |
+
def test_all_tshirt_tracks_are_packaged_for_point_discovery():
|
| 58 |
+
outlines = json.loads(ALL_TSHIRT_TEMPLATES.read_text(encoding="utf-8"))["t_shirt"]
|
| 59 |
+
assert len(outlines) == 1014
|
| 60 |
+
assert len({tuple(map(tuple, outline)) for outline in outlines}) == 1014
|
| 61 |
+
assert all(5 <= len(outline) <= 25 and outline[0] == outline[-1] for outline in outlines)
|
| 62 |
+
script = ROOT / "router" / "ai" / "scripts" / "clip_osm_region_test.py"
|
| 63 |
+
tree = ast.parse(script.read_text(encoding="utf-8-sig"))
|
| 64 |
+
loader = next(node for node in tree.body if isinstance(node, ast.FunctionDef)
|
| 65 |
+
and node.name == "_load_gpx_shape_templates")
|
| 66 |
+
scope = {"__file__": str(script), "Path": Path, "json": json}
|
| 67 |
+
exec(compile(ast.Module(body=[loader], type_ignores=[]), str(script), "exec"), scope)
|
| 68 |
+
loaded = scope["_load_gpx_shape_templates"]()
|
| 69 |
+
assert len(loaded["t_shirt"]) == 1014
|
| 70 |
+
|
| 71 |
+
|
| 72 |
def test_new_star_gpx_examples_are_available_for_road_generation():
|
| 73 |
outlines = json.loads(STAR_TEMPLATES.read_text(encoding="utf-8"))["symbol_star"]
|
| 74 |
assert len(outlines) == 64
|
router/ai/data/tshirt_shape_templates_all.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
router/ai/scripts/build_tshirt_shape_templates.py
CHANGED
|
@@ -1,16 +1,37 @@
|
|
| 1 |
"""Package location-free T-shirt outlines from reviewed GPX tracks.
|
| 2 |
|
| 3 |
-
Usage: python build_tshirt_shape_templates.py
|
| 4 |
"""
|
| 5 |
|
| 6 |
import json
|
| 7 |
import sys
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
|
| 10 |
-
from build_gpx_shape_templates import normalized_outline
|
| 11 |
|
| 12 |
|
| 13 |
def build(source: Path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
paths = sorted(source.glob("tshirt_osm_*.gpx"))
|
| 15 |
if not paths:
|
| 16 |
raise ValueError("No tshirt_osm_*.gpx files found")
|
|
|
|
| 1 |
"""Package location-free T-shirt outlines from reviewed GPX tracks.
|
| 2 |
|
| 3 |
+
Usage: python build_tshirt_shape_templates.py GPX_DIRECTORY_OR_MULTITRACK_FILE OUTPUT_JSON
|
| 4 |
"""
|
| 5 |
|
| 6 |
import json
|
| 7 |
import sys
|
| 8 |
+
import xml.etree.ElementTree as ET
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
+
from build_gpx_shape_templates import normalized_outline, normalized_outline_from_track
|
| 12 |
|
| 13 |
|
| 14 |
def build(source: Path):
|
| 15 |
+
if source.is_file():
|
| 16 |
+
outlines = []
|
| 17 |
+
seen = set()
|
| 18 |
+
root = ET.parse(source).getroot()
|
| 19 |
+
for index, track in enumerate(node for node in root.iter()
|
| 20 |
+
if node.tag.rsplit("}", 1)[-1] == "trk"):
|
| 21 |
+
points = [(float(point.attrib["lat"]), float(point.attrib["lon"]))
|
| 22 |
+
for point in track.iter()
|
| 23 |
+
if point.tag.rsplit("}", 1)[-1] == "trkpt"]
|
| 24 |
+
try:
|
| 25 |
+
outline = normalized_outline_from_track(points, f"{source.name}:{index}")
|
| 26 |
+
except ValueError:
|
| 27 |
+
continue
|
| 28 |
+
signature = tuple(map(tuple, outline))
|
| 29 |
+
if signature not in seen:
|
| 30 |
+
seen.add(signature)
|
| 31 |
+
outlines.append(outline)
|
| 32 |
+
if not outlines:
|
| 33 |
+
raise ValueError("No valid T-shirt tracks found")
|
| 34 |
+
return {"t_shirt": outlines}
|
| 35 |
paths = sorted(source.glob("tshirt_osm_*.gpx"))
|
| 36 |
if not paths:
|
| 37 |
raise ValueError("No tshirt_osm_*.gpx files found")
|
router/ai/scripts/clip_osm_region_test.py
CHANGED
|
@@ -147,7 +147,7 @@ def _load_gpx_shape_templates() -> dict[str, list[list[tuple[float, float]]]]:
|
|
| 147 |
data_dir = Path(__file__).resolve().parents[1] / "data"
|
| 148 |
templates: dict[str, list[list[tuple[float, float]]]] = {"dog": [], "symbol_star": [], "t_shirt": []}
|
| 149 |
seen: dict[str, set[tuple[tuple[float, float], ...]]] = {label: set() for label in templates}
|
| 150 |
-
for filename in ("gpx_shape_templates.json", "approved_road_shape_templates.json", "tshirt_shape_templates.json", "star_shape_templates.json", "star_shape_templates_all.json", "dog_shape_templates_all.json"):
|
| 151 |
try:
|
| 152 |
payload = json.loads((data_dir / filename).read_text(encoding="utf-8"))
|
| 153 |
except (OSError, ValueError, TypeError):
|
|
|
|
| 147 |
data_dir = Path(__file__).resolve().parents[1] / "data"
|
| 148 |
templates: dict[str, list[list[tuple[float, float]]]] = {"dog": [], "symbol_star": [], "t_shirt": []}
|
| 149 |
seen: dict[str, set[tuple[tuple[float, float], ...]]] = {label: set() for label in templates}
|
| 150 |
+
for filename in ("gpx_shape_templates.json", "approved_road_shape_templates.json", "tshirt_shape_templates.json", "tshirt_shape_templates_all.json", "star_shape_templates.json", "star_shape_templates_all.json", "dog_shape_templates_all.json"):
|
| 151 |
try:
|
| 152 |
payload = json.loads((data_dir / filename).read_text(encoding="utf-8"))
|
| 153 |
except (OSError, ValueError, TypeError):
|