Spaces:
Sleeping
Sleeping
Sync DemoService 65a98143cc0c4d48a5221f2d90552f7d3a4bc364
Browse filesFiles changed (4)
46 unmodified lines474849505152349 unmodified lines40240340440540640717 unmodified lines42542642742842943043143243343443543621 unmodified lines45845946046146246346434 unmodified lines4995005015025035045055 unmodified lines511512513514515516517156 unmodified lines6746756766776786796806816826836848 unmodified lines69369469569669769823 unmodified lines72272372472572672746 unmodified linesgatv2Weight: float | None = Field(default=None, ge=0.0, le=1.0)routeCount: int = Field(default=8, ge=1, le=100)targetDistanceKm: float = Field(default=6.0, ge=0.5, le=30.0)labels: list[str] | None = NoneselectedLabel: str | None = NoneselectedTopK: int = Field(default=0, ge=0, le=20)349 unmodified linesroute_count: int,target_distance_km: float,selected_label: str | None,) -> dict[str, Any]:"""Create real walkable-road routes without per-route CLIP inference.17 unmodified lines# failed request before it can return any usable road loop.examples = getattr(module, "GPX_SHAPE_TEMPLATES", {}).get(selected_label, [])candidate_pool = min(16 if examples else 8, max(route_count, route_count + (11 if examples else 1)))candidates = build_candidates(graph=graph,route_count=candidate_pool,target_distance_m=target_distance_km * 1000.0,selected_label=selected_label,)# A selected shape is a preference, not a reason to leave the runner with# no route. Sparse neighbourhoods and long distances do not always have# enough roads to satisfy the strict shape-quality gate. In that case21 unmodified linesraise RuntimeError("No walkable road routes were generated near this location.")routes: list[dict[str, Any]] = []for route in candidates:# Simplified OSM edges can bend between intersections. Preserve those# bends rather than drawing straight lines across blocks or water.coords = _route_nodes_to_coords(graph, route["nodes"])34 unmodified linesif examples:routes.sort(key=lambda route: (-route["route_quality"]["gpx_similarity"],abs(route["length_km"] - target_distance_km),))routes = routes[:route_count]if not routes:5 unmodified lines"candidate_count": len(candidates),"requested_count": route_count,"generated_count": len(routes),"target_distance_km": target_distance_km,"radius_km": radius_km,"labels": [selected_label] if selected_label else [],"selected_label": selected_label,156 unmodified linesroute_count_cap = 20 if use_current else 100route_count = min(route_count_cap, max(1, payload.routeCount))target_distance_km = max(0.5, payload.targetDistanceKm)# A 1.5 km graph is enough for ordinary short courses, but it cannot make# a truthful 16~30 km route. Grow the road graph only as much as the# requested distance needs, up to the request model's safe 10 km limit.required_radius_km = target_distance_km / 5.5radius_km = min(10.0, max(1.5, min(10.0, payload.radiusKm), required_radius_km))if payload.fastRoads:module = None8 unmodified linesroute_count=route_count,target_distance_km=target_distance_km,selected_label=selected_label,)except Exception as primary_exc:logger.exception("fast walk-road route generation failed")23 unmodified linesroute_count=route_count,target_distance_km=target_distance_km,selected_label=selected_label,)except Exception:logger.exception("fallback-centre walk-road generation failed")46 unmodified lines47484950515253349 unmodified lines40340440540640740840917 unmodified lines42742842943043143243343443543643743843944044144244344444544644744844945021 unmodified lines47247347447547647747847948048148248334 unmodified lines5185195205215225235245 unmodified lines530531532533534535536156 unmodified lines6936946956966976986997007017027037048 unmodified lines71371471571671771871923 unmodified lines74374474574674774874946 unmodified linesgatv2Weight: float | None = Field(default=None, ge=0.0, le=1.0)routeCount: int = Field(default=8, ge=1, le=100)targetDistanceKm: float = Field(default=6.0, ge=0.5, le=30.0)shapePriority: bool = Falselabels: list[str] | None = NoneselectedLabel: str | None = NoneselectedTopK: int = Field(default=0, ge=0, le=20)349 unmodified linesroute_count: int,target_distance_km: float,selected_label: str | None,shape_priority: bool = False,) -> dict[str, Any]:"""Create real walkable-road routes without per-route CLIP inference.17 unmodified lines# failed request before it can return any usable road loop.examples = getattr(module, "GPX_SHAPE_TEMPLATES", {}).get(selected_label, [])candidate_pool = min(16 if examples else 8, max(route_count, route_count + (11 if examples else 1)))if shape_priority and examples:# Explore multiple physical sizes on the same road graph. The UI did# not request a distance; these are search scales, not length targets.candidates = []for search_distance_km in (6.0, 11.0, 18.0):candidates.extend(build_candidates(graph=graph,route_count=min(6, candidate_pool),target_distance_m=search_distance_km * 1000.0,selected_label=selected_label,))else:candidates = build_candidates(graph=graph,route_count=candidate_pool,target_distance_m=target_distance_km * 1000.0,selected_label=selected_label,)# A selected shape is a preference, not a reason to leave the runner with# no route. Sparse neighbourhoods and long distances do not always have# enough roads to satisfy the strict shape-quality gate. In that case21 unmodified linesraise RuntimeError("No walkable road routes were generated near this location.")routes: list[dict[str, Any]] = []seen_nodes: set[tuple[Any, ...]] = set()for route in candidates:node_signature = tuple(route["nodes"])if node_signature in seen_nodes:continueseen_nodes.add(node_signature)# Simplified OSM edges can bend between intersections. Preserve those# bends rather than drawing straight lines across blocks or water.coords = _route_nodes_to_coords(graph, route["nodes"])34 unmodified linesif examples:routes.sort(key=lambda route: (-route["route_quality"]["gpx_similarity"],abs(route["length_km"] - target_distance_km) if not shape_priority else 0,))routes = routes[:route_count]if not routes:5 unmodified lines"candidate_count": len(candidates),"requested_count": route_count,"generated_count": len(routes),"target_distance_km": 0.0 if shape_priority else target_distance_km,"radius_km": radius_km,"labels": [selected_label] if selected_label else [],"selected_label": selected_label,156 unmodified linesroute_count_cap = 20 if use_current else 100route_count = min(route_count_cap, max(1, payload.routeCount))target_distance_km = max(0.5, payload.targetDistanceKm)shape_priority = payload.shapePriority and selected_label in {"dog", "symbol_star"}# A 1.5 km graph is enough for ordinary short courses, but it cannot make# a truthful 16~30 km route. Grow the road graph only as much as the# requested distance needs, up to the request model's safe 10 km limit.required_radius_km = target_distance_km / 5.5radius_km = min(10.0, max(5.0 if shape_priority else 1.5, min(10.0, payload.radiusKm), required_radius_km))if payload.fastRoads:module = None8 unmodified linesroute_count=route_count,target_distance_km=target_distance_km,selected_label=selected_label,shape_priority=shape_priority,)except Exception as primary_exc:logger.exception("fast walk-road route generation failed")23 unmodified linesroute_count=route_count,target_distance_km=target_distance_km,selected_label=selected_label,shape_priority=shape_priority,)except Exception:logger.exception("fallback-centre walk-road generation failed")
132 unmodified lines133134135136137138132 unmodified linesassert result["best_route"] == result["routes"][0]def test_place_request_returns_all_100_routes(pipeline):pipeline.setattr(routes, "_run_fast_road_pipeline", Mock(side_effect=RuntimeError("All Overpass endpoints failed")))result = routes.generate_routes(routes.RouteGenerateRequest(place="์๊ทํฌ์", fallbackLatitude=33.25, fallbackLongitude=126.56, routeCount=100))132 unmodified lines133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162132 unmodified linesassert result["best_route"] == result["routes"][0]def test_shape_priority_searches_multiple_lengths_and_ranks_by_shape(monkeypatch):searched_distances = []def candidates_for_distance(**kwargs):distance = kwargs["target_distance_m"]searched_distances.append(distance)return [{"nodes": [distance, distance + 1], "length_m": distance,"shape_quality": 0.6, "is_loop": True}]module = SimpleNamespace(GPX_SHAPE_TEMPLATES={"dog": [[(0, 0), (1, 0), (0, 1)]]},_build_or_get_walk_graph=lambda *_: (object(), "test"),generate_candidate_routes=candidates_for_distance,route_points=lambda *_: [], simplify_coords=lambda points: points,)monkeypatch.setattr(routes, "_route_nodes_to_coords", lambda _graph, nodes: [[nodes[0], 0], [nodes[1], 1]])monkeypatch.setattr(routes, "best_gpx_shape_match", lambda coords, _examples: (coords[0][0] / 18000, 0))result = routes._run_fast_road_pipeline(module, place=None, center_lat=37, center_lon=127,radius_km=5, route_count=2, target_distance_km=6, selected_label="dog", shape_priority=True)assert searched_distances == [6000, 11000, 18000]assert [route["length_km"] for route in result["routes"]] == [18, 11]assert result["target_distance_km"] == 0def test_place_request_returns_all_100_routes(pipeline):pipeline.setattr(routes, "_run_fast_road_pipeline", Mock(side_effect=RuntimeError("All Overpass endpoints failed")))result = routes.generate_routes(routes.RouteGenerateRequest(place="์๊ทํฌ์", fallbackLatitude=33.25, fallbackLongitude=126.56, routeCount=100))
161 unmodified lines1621631641651661672 unmodified lines17017117217317417517628 unmodified lines20520620720820921021139 unmodified lines251252253254255256223 unmodified lines4804814824834844854862 unmodified lines48949049149249349449549649749818 unmodified lines517518519520521522523524161 unmodified linesconst longitude = Number.isFinite(initialLongitude) ? initialLongitude : null;const radiusKm = Number.isFinite(initialRadiusKm) ? initialRadiusKm : 5;const selectedTopK = Number.isFinite(initialSelectedTopK) ? initialSelectedTopK : 3;const routeFallbackLatitude = Number.isFinite(fallbackLatitude) ? fallbackLatitude : null;const routeFallbackLongitude = Number.isFinite(fallbackLongitude) ? fallbackLongitude : null;2 unmodified linesconst count = Number(routeCountInput);const distance = Number(targetDistanceInput);if (!requestPlace || !Number.isFinite(count) || count < 5 || count > 100 ||!Number.isFinite(distance) || distance < 1 || distance > 30) {void fetchRoutes(); // Keep the same field validation messages.return;}28 unmodified linessetError("๊ฒฝ๋ก ์๋ 5~100 ์ฌ์ด๋ก ์ ๋ ฅํด์ฃผ์ธ์.");return;}if (!Number.isFinite(targetDistanceKm) || targetDistanceKm < 1 || targetDistanceKm > 30) {setError("๋ชฉํ ๊ฑฐ๋ฆฌ๋ 1~30km ์ฌ์ด๋ก ์ ๋ ฅํด์ฃผ์ธ์.");return;}39 unmodified linesradiusKm,routeCount,targetDistanceKm,labels: AVAILABLE_LABELS,selectedLabel,selectedTopK,223 unmodified lines/><SectionCard><div className="grid gap-3 sm:grid-cols-[1fr_120px_120px] sm:items-end"><label className="grid gap-2"><span className="rts-label">์ง์ญ</span><input value={place} onChange={(event) => setPlace(event.target.value)} className="rts-input" />2 unmodified lines<span className="rts-label">๊ฒฝ๋ก ์</span><input type="number" min={5} max={100} value={routeCountInput} onChange={(event) => setRouteCountInput(event.target.value)} className="rts-input" /></label><label className="grid gap-2"><span className="rts-label">๋ชฉํ ๊ฑฐ๋ฆฌ</span><input type="number" min={1} max={30} step={0.5} value={targetDistanceInput} onChange={(event) => setTargetDistanceInput(event.target.value)} className="rts-input" /></label></div>{error ? <p className="mt-3 text-sm text-red-600">{error}</p> : null}18 unmodified lines<span>์ถ์ฒ ๊ฒฝ๋ก</span></div><div><strong>{formatDistance(result.target_distance_km)}</strong><span>๋ชฉํ ๊ฑฐ๋ฆฌ</span></div><div><strong>{formatGeneratedRouteLabel(selectedLabel)}</strong>161 unmodified lines1621631641651661671682 unmodified lines17117217317417517617728 unmodified lines20620720820921021121239 unmodified lines252253254255256257258223 unmodified lines4824834844854864874882 unmodified lines49149249349449549649749849950018 unmodified lines519520521522523524525526161 unmodified linesconst longitude = Number.isFinite(initialLongitude) ? initialLongitude : null;const radiusKm = Number.isFinite(initialRadiusKm) ? initialRadiusKm : 5;const selectedTopK = Number.isFinite(initialSelectedTopK) ? initialSelectedTopK : 3;const shapePriority = searchParams.get("shapePriority") === "true" && (selectedLabel === "dog" || selectedLabel === "symbol_star");const routeFallbackLatitude = Number.isFinite(fallbackLatitude) ? fallbackLatitude : null;const routeFallbackLongitude = Number.isFinite(fallbackLongitude) ? fallbackLongitude : null;2 unmodified linesconst count = Number(routeCountInput);const distance = Number(targetDistanceInput);if (!requestPlace || !Number.isFinite(count) || count < 5 || count > 100 ||(!shapePriority && (!Number.isFinite(distance) || distance < 1 || distance > 30))) {void fetchRoutes(); // Keep the same field validation messages.return;}28 unmodified linessetError("๊ฒฝ๋ก ์๋ 5~100 ์ฌ์ด๋ก ์ ๋ ฅํด์ฃผ์ธ์.");return;}if (!shapePriority && (!Number.isFinite(targetDistanceKm) || targetDistanceKm < 1 || targetDistanceKm > 30)) {setError("๋ชฉํ ๊ฑฐ๋ฆฌ๋ 1~30km ์ฌ์ด๋ก ์ ๋ ฅํด์ฃผ์ธ์.");return;}39 unmodified linesradiusKm,routeCount,targetDistanceKm,shapePriority,labels: AVAILABLE_LABELS,selectedLabel,selectedTopK,223 unmodified lines/><SectionCard><div className={`grid gap-3 sm:items-end ${shapePriority ? "sm:grid-cols-[1fr_120px]" : "sm:grid-cols-[1fr_120px_120px]"}`}><label className="grid gap-2"><span className="rts-label">์ง์ญ</span><input value={place} onChange={(event) => setPlace(event.target.value)} className="rts-input" />2 unmodified lines<span className="rts-label">๊ฒฝ๋ก ์</span><input type="number" min={5} max={100} value={routeCountInput} onChange={(event) => setRouteCountInput(event.target.value)} className="rts-input" /></label>{!shapePriority ? <label className="grid gap-2"><span className="rts-label">๋ชฉํ ๊ฑฐ๋ฆฌ</span><input type="number" min={1} max={30} step={0.5} value={targetDistanceInput} onChange={(event) => setTargetDistanceInput(event.target.value)} className="rts-input" /></label> : null}</div>{error ? <p className="mt-3 text-sm text-red-600">{error}</p> : null}18 unmodified lines<span>์ถ์ฒ ๊ฒฝ๋ก</span></div><div><strong>{shapePriority ? "๋ชจ์ ์ฐ์ " : formatDistance(result.target_distance_km)}</strong><span>{shapePriority ? "์ถ์ฒ ๊ธฐ์ค" : "๋ชฉํ ๊ฑฐ๋ฆฌ"}</span></div><div><strong>{formatGeneratedRouteLabel(selectedLabel)}</strong>
649 unmodified lines650651652653654655656657179 unmodified lines8378388398408418428438448458468474 unmodified lines852853854855856857422 unmodified lines128012811282128312841285128641 unmodified lines1328132913301331133213331334649 unmodified lines: [];const isWaitingForCurrentLocation = isLocating;const summaryPlace = source === "current" ? "ํ์ฌ ์์น" : selectedDistrictLabel;const selectedSummary = `${summaryPlace} ยท ${selectedShape.label} ยท ${targetDistanceInput || "-"}km`;const routePlanText = `${summaryPlace}์์ ${selectedShape.label} ๋ชจ์์ ๊ฐ๊น์ด ${targetDistanceInput || "-"}km ๊ฒฝ๋ก๋ฅผ ${routeCountInput || "-"}๊ฐ ์ถ์ฒํฉ๋๋ค.`;useEffect(() => {const isValid = isUiFlowPermitValid(FLOW_KEYS.routeSearch, flowToken);179 unmodified linessetFormError("์ถ์ฒ ๊ฒฝ๋ก ์๋ 5~100 ์ฌ์ด ์ซ์๋ก ์ ๋ ฅํด ์ฃผ์ธ์.");return;}if (!Number.isFinite(targetDistanceKm) ||targetDistanceKm < 1 ||targetDistanceKm > 30) {setFormError("๋ชฉํ ๊ฑฐ๋ฆฌ๋ 1~30km ์ฌ์ด ์ซ์๋ก ์ ๋ ฅํด ์ฃผ์ธ์.");return;}4 unmodified linesradiusKm: String(radiusKm),routeCount: String(routeCount),targetDistanceKm: String(targetDistanceKm),label: selectedLabel,selectedTopK: "3",// Supply the visible map centre for a server-side recovery attempt when422 unmodified lines</div></label><label className="grid gap-2"><span className="text-sm font-bold">๋ชฉํ ๊ฑฐ๋ฆฌ</span><div className="relative"><button41 unmodified lines})}</MotionPopover></div></label><details className="rounded-2xl bg-[#f7f7f7] p-4"><summary className="cursor-pointer text-sm font-bold">์ธ๋ถ ์ค์ </summary>649 unmodified lines650651652653654655656657658659660179 unmodified lines8408418428438448458468478488498504 unmodified lines855856857858859860861422 unmodified lines128412851286128712881289129041 unmodified lines1332133313341335133613371338649 unmodified lines: [];const isWaitingForCurrentLocation = isLocating;const summaryPlace = source === "current" ? "ํ์ฌ ์์น" : selectedDistrictLabel;const shapePriority = selectedLabel === "dog" || selectedLabel === "symbol_star";const selectedSummary = `${summaryPlace} ยท ${selectedShape.label}${shapePriority ? " ยท ๋ชจ์ ์ฐ์ " : ` ยท ${targetDistanceInput || "-"}km`}`;const routePlanText = shapePriority? `${summaryPlace}์ ๋๋ก์์ ${selectedShape.label} ๋ชจ์๊ณผ ๊ฐ์ฅ ๋ฎ์ ๊ฒฝ๋ก๋ฅผ ์ฐพ์ ${routeCountInput || "-"}๊ฐ ์ถ์ฒํฉ๋๋ค. ๊ฑฐ๋ฆฌ๋ ์์ฑ ๊ฒฐ๊ณผ์์ ํ์ธํ ์ ์์ด์.`: `${summaryPlace}์์ ${selectedShape.label} ๋ชจ์์ ๊ฐ๊น์ด ${targetDistanceInput || "-"}km ๊ฒฝ๋ก๋ฅผ ${routeCountInput || "-"}๊ฐ ์ถ์ฒํฉ๋๋ค.`;useEffect(() => {const isValid = isUiFlowPermitValid(FLOW_KEYS.routeSearch, flowToken);179 unmodified linessetFormError("์ถ์ฒ ๊ฒฝ๋ก ์๋ 5~100 ์ฌ์ด ์ซ์๋ก ์ ๋ ฅํด ์ฃผ์ธ์.");return;}if (!shapePriority && (!Number.isFinite(targetDistanceKm) ||targetDistanceKm < 1 ||targetDistanceKm > 30)) {setFormError("๋ชฉํ ๊ฑฐ๋ฆฌ๋ 1~30km ์ฌ์ด ์ซ์๋ก ์ ๋ ฅํด ์ฃผ์ธ์.");return;}4 unmodified linesradiusKm: String(radiusKm),routeCount: String(routeCount),targetDistanceKm: String(targetDistanceKm),shapePriority: String(shapePriority),label: selectedLabel,selectedTopK: "3",// Supply the visible map centre for a server-side recovery attempt when422 unmodified lines</div></label>{!shapePriority ? <label className="grid gap-2"><span className="text-sm font-bold">๋ชฉํ ๊ฑฐ๋ฆฌ</span><div className="relative"><button41 unmodified lines})}</MotionPopover></div></label> : null}<details className="rounded-2xl bg-[#f7f7f7] p-4"><summary className="cursor-pointer text-sm font-bold">์ธ๋ถ ์ค์ </summary>
api/ai-service/app/api/v1/endpoints/route_generation.py+31-9
api/ai-service/tests/test_route_generation_recovery.py+24
main/app/route-results/page.tsx+9-7
main/app/route-search/page.tsx+10-6