File size: 2,256 Bytes
1dc52fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Test: Chandigarh Airport → PEC (same test as Google Maps comparison).
Google Maps shows: 36 min, 18.3 km, 3 different routes.
"""
import httpx
import time
import json

# Same coordinates user tested with
SRC_LAT, SRC_LON = 30.6741923, 76.7909851
DEST_LAT, DEST_LON = 30.7664869, 76.7850788

print("=" * 60)
print("Google Luma V3 Route Test")
print(f"Origin: ({SRC_LAT}, {SRC_LON})")
print(f"Destination: ({DEST_LAT}, {DEST_LON})")
print("=" * 60)

start = time.time()
r = httpx.get(
    "http://localhost:8000/api/v1/routing/routes/compare",
    params={
        "src_lat": SRC_LAT,
        "src_lon": SRC_LON,
        "dest_lat": DEST_LAT,
        "dest_lon": DEST_LON,
    },
    timeout=30,
)
elapsed = time.time() - start

if r.status_code != 200:
    print(f"\nERROR {r.status_code}: {r.text}")
else:
    data = r.json()
    print(f"\nResponse time: {elapsed:.2f}s\n")

    print(f"{'Mode':<12} {'Safety':>8} {'Time':>10} {'Distance':>10} {'Points':>8}")
    print("-" * 52)

    for route in data["routes"]:
        mode = route["mode"]
        safety = route["average_safety_score"]
        time_s = route["estimated_time_seconds"]
        # Approximate distance from geometry points
        pts = len(route["route_geometry"])
        time_min = time_s / 60

        # Calculate actual distance from geometry
        total_dist = 0
        geom = route["route_geometry"]
        for i in range(1, len(geom)):
            import math
            R = 6371
            dlat = math.radians(geom[i]["lat"] - geom[i-1]["lat"])
            dlon = math.radians(geom[i]["lon"] - geom[i-1]["lon"])
            a = math.sin(dlat/2)**2 + math.cos(math.radians(geom[i-1]["lat"])) * math.cos(math.radians(geom[i]["lat"])) * math.sin(dlon/2)**2
            total_dist += R * 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))

        print(
            f"{mode:<12} {safety:>7.3f} "
            f"{time_min:>8.1f}min "
            f"{total_dist:>8.1f}km "
            f"{pts:>7}"
        )

    print(f"\nRankings: {json.dumps(data['rankings'])}")
    print(f"\nTradeoffs:")
    for mode, metrics in data["tradeoff_metrics"].items():
        print(f"  {mode}: time_diff={metrics['time_penalty_seconds']:.0f}s, safety_diff={metrics['safety_gain_absolute']:+.4f}")