Spaces:
Sleeping
Sleeping
Update utils/predict.py
Browse filesFix bugs in predict page
- utils/predict.py +11 -4
utils/predict.py
CHANGED
@@ -25,7 +25,7 @@ from utils.config import LOCATIONS, BRANDTHEMES, KENYA_LAT, KENYA_LON, HOURS, MI
|
|
25 |
from utils.config import HISTORY_FILE, ENV_PATH
|
26 |
from utils.url_to_coordinates import get_full_url, on_convert
|
27 |
|
28 |
-
|
29 |
|
30 |
|
31 |
class EtaFeatures(BaseModel):
|
@@ -285,7 +285,8 @@ def predict_page(input: Inputs, output: Outputs, session: Session):
|
|
285 |
return f"{eta_sec:,.0f} s", f"{eta_hms}"
|
286 |
else:
|
287 |
raise Exception
|
288 |
-
except Exception:
|
|
|
289 |
ui.notification_show(
|
290 |
"🚨 Could not predict Eta. Median eta is 1000 seconds", duration=3, type="error")
|
291 |
return None
|
@@ -352,7 +353,13 @@ def predict_page(input: Inputs, output: Outputs, session: Session):
|
|
352 |
) if valid else LOCATIONS["National Museum of Kenya"]['longitude'])
|
353 |
|
354 |
# Automate trip distance
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
|
357 |
# Manual
|
358 |
if input.manual_distance() and input.trip_distance() not in [0, None]:
|
@@ -361,7 +368,7 @@ def predict_page(input: Inputs, output: Outputs, session: Session):
|
|
361 |
@reactive.effect
|
362 |
@reactive.event(trip_distance)
|
363 |
def _():
|
364 |
-
if valid():
|
365 |
# Update the trip distance input with current calculated or manual trip distance
|
366 |
ui.update_numeric("trip_distance", value=trip_distance())
|
367 |
|
|
|
25 |
from utils.config import HISTORY_FILE, ENV_PATH
|
26 |
from utils.url_to_coordinates import get_full_url, on_convert
|
27 |
|
28 |
+
load_dotenv(ENV_PATH)
|
29 |
|
30 |
|
31 |
class EtaFeatures(BaseModel):
|
|
|
285 |
return f"{eta_sec:,.0f} s", f"{eta_hms}"
|
286 |
else:
|
287 |
raise Exception
|
288 |
+
except Exception as e:
|
289 |
+
logging.error({e})
|
290 |
ui.notification_show(
|
291 |
"🚨 Could not predict Eta. Median eta is 1000 seconds", duration=3, type="error")
|
292 |
return None
|
|
|
353 |
) if valid else LOCATIONS["National Museum of Kenya"]['longitude'])
|
354 |
|
355 |
# Automate trip distance
|
356 |
+
google_td = google_maps_trip_distance(loc1xy(), loc2xy())
|
357 |
+
if isinstance(google_td, float):
|
358 |
+
trip_distance.set(google_td)
|
359 |
+
else:
|
360 |
+
ui.notification_show(
|
361 |
+
"🚨 Could not estimate trip distance. Using Geosidic distance...", duration=3, type="warning")
|
362 |
+
trip_distance.set(geo_dist())
|
363 |
|
364 |
# Manual
|
365 |
if input.manual_distance() and input.trip_distance() not in [0, None]:
|
|
|
368 |
@reactive.effect
|
369 |
@reactive.event(trip_distance)
|
370 |
def _():
|
371 |
+
# if valid():
|
372 |
# Update the trip distance input with current calculated or manual trip distance
|
373 |
ui.update_numeric("trip_distance", value=trip_distance())
|
374 |
|