Update hour options to include seconds in time picker
Browse files- kitt.py +3 -2
- skills/common.py +2 -2
- skills/routing.py +10 -3
kitt.py
CHANGED
@@ -85,7 +85,7 @@ tools = [
|
|
85 |
|
86 |
|
87 |
# Generate options for hours (00-23)
|
88 |
-
hour_options = [f"{i:02d}:00" for i in range(24)]
|
89 |
|
90 |
|
91 |
def set_time(time_picker):
|
@@ -158,6 +158,7 @@ def update_vehicle_status(trip_progress):
|
|
158 |
new_coords = new_coords["latitude"], new_coords["longitude"]
|
159 |
print(f"Trip progress: {trip_progress}, len: {n_points}, new_coords: {new_coords}")
|
160 |
vehicle.location_coordinates = new_coords
|
|
|
161 |
return vehicle.model_dump_json()
|
162 |
|
163 |
|
@@ -214,7 +215,7 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
214 |
time_picker = gr.Dropdown(
|
215 |
choices=hour_options,
|
216 |
label="What time is it? (HH:MM)",
|
217 |
-
value="08:00",
|
218 |
interactive=True,
|
219 |
)
|
220 |
history = gr.Radio(
|
|
|
85 |
|
86 |
|
87 |
# Generate options for hours (00-23)
|
88 |
+
hour_options = [f"{i:02d}:00:00" for i in range(24)]
|
89 |
|
90 |
|
91 |
def set_time(time_picker):
|
|
|
158 |
new_coords = new_coords["latitude"], new_coords["longitude"]
|
159 |
print(f"Trip progress: {trip_progress}, len: {n_points}, new_coords: {new_coords}")
|
160 |
vehicle.location_coordinates = new_coords
|
161 |
+
vehicle.location = ""
|
162 |
return vehicle.model_dump_json()
|
163 |
|
164 |
|
|
|
215 |
time_picker = gr.Dropdown(
|
216 |
choices=hour_options,
|
217 |
label="What time is it? (HH:MM)",
|
218 |
+
value="08:00:00",
|
219 |
interactive=True,
|
220 |
)
|
221 |
history = gr.Radio(
|
skills/common.py
CHANGED
@@ -56,7 +56,7 @@ config = Settings() # type: ignore
|
|
56 |
vehicle = VehicleStatus(
|
57 |
location="Rue Alphonse Weicker, Luxembourg",
|
58 |
location_coordinates=(49.63324, 6.169),
|
59 |
-
date="2025-05-
|
60 |
-
time="08:00:
|
61 |
destination="Luxembourg Gare, Luxembourg"
|
62 |
)
|
|
|
56 |
vehicle = VehicleStatus(
|
57 |
location="Rue Alphonse Weicker, Luxembourg",
|
58 |
location_coordinates=(49.63324, 6.169),
|
59 |
+
date="2025-05-06",
|
60 |
+
time="08:00:00",
|
61 |
destination="Luxembourg Gare, Luxembourg"
|
62 |
)
|
skills/routing.py
CHANGED
@@ -85,15 +85,22 @@ def find_route_tomtom(
|
|
85 |
"""
|
86 |
# https://developer.tomtom.com/routing-api/documentation/routing/calculate-route
|
87 |
# https://developer.tomtom.com/routing-api/documentation/routing/guidance-instructions
|
|
|
|
|
|
|
88 |
r = requests.get(
|
89 |
-
|
90 |
timeout=5,
|
91 |
)
|
92 |
|
93 |
# Parse JSON from the response
|
94 |
response = r.json()
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
|
98 |
distance_m = result["lengthInMeters"]
|
99 |
duration_s = result["travelTimeInSeconds"]
|
@@ -154,4 +161,4 @@ def find_route(destination=""):
|
|
154 |
|
155 |
# return the distance and time
|
156 |
return f"The route to {destination} is {distance_km:.2f} km which takes {time_display}. Leaving now, the arrival time is estimated at {arrival_hour_display}."
|
157 |
-
|
|
|
85 |
"""
|
86 |
# https://developer.tomtom.com/routing-api/documentation/routing/calculate-route
|
87 |
# https://developer.tomtom.com/routing-api/documentation/routing/guidance-instructions
|
88 |
+
url = f"https://api.tomtom.com/routing/1/calculateRoute/{lat_depart},{lon_depart}:{lat_dest},{lon_dest}/json?key={config.TOMTOM_API_KEY}&departAt={depart_datetime}"
|
89 |
+
|
90 |
+
print(f"Calling TomTom API: {url}")
|
91 |
r = requests.get(
|
92 |
+
url,
|
93 |
timeout=5,
|
94 |
)
|
95 |
|
96 |
# Parse JSON from the response
|
97 |
response = r.json()
|
98 |
|
99 |
+
try:
|
100 |
+
result = response["routes"][0]["summary"]
|
101 |
+
except KeyError:
|
102 |
+
print(f"Failed to find a route: {response}")
|
103 |
+
return "Failed to find a route", response
|
104 |
|
105 |
distance_m = result["lengthInMeters"]
|
106 |
duration_s = result["travelTimeInSeconds"]
|
|
|
161 |
|
162 |
# return the distance and time
|
163 |
return f"The route to {destination} is {distance_km:.2f} km which takes {time_display}. Leaving now, the arrival time is estimated at {arrival_hour_display}."
|
164 |
+
# raw_response["routes"][0]["legs"][0]["points"]
|