better logs
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m20s
Run linting on the backend code / Build (pull_request) Failing after 26s
Run testing on the backend code / Build (pull_request) Failing after 2m40s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 17s

This commit is contained in:
2025-01-09 16:58:38 +01:00
parent a0a3d76b78
commit 11bbf34375
7 changed files with 60 additions and 68 deletions

View File

@@ -1,6 +1,7 @@
"""Main app for backend api"""
import logging
import time
from fastapi import FastAPI, HTTPException, Query
from contextlib import asynccontextmanager
@@ -81,6 +82,7 @@ def new_trip(preferences: Preferences,
must_do=True,
n_tags=0)
start_time = time.time()
# Generate the landmarks from the start location
landmarks, landmarks_short = manager.generate_landmarks_list(
center_coordinates = start,
@@ -91,6 +93,9 @@ def new_trip(preferences: Preferences,
landmarks_short.insert(0, start_landmark)
landmarks_short.append(end_landmark)
t_generate_landmarks = time.time() - start_time
start_time = time.time()
# First stage optimization
try:
base_tour = optimizer.solve_optimization(preferences.max_time_minute, landmarks_short)
@@ -99,11 +104,20 @@ def new_trip(preferences: Preferences,
except TimeoutError as exc:
raise HTTPException(status_code=500, detail="Optimzation took too long") from exc
t_first_stage = time.time() - start_time
start_time = time.time()
# Second stage optimization
refined_tour = refiner.refine_optimization(landmarks, base_tour,
preferences.max_time_minute,
preferences.detour_tolerance_minute)
t_second_stage = time.time() - start_time
logger.debug(f'Generating landmarks : {round(t_generate_landmarks,3)} seconds')
logger.debug(f'First stage optimization : {round(t_first_stage,3)} seconds')
logger.debug(f'Second stage optimization : {round(t_second_stage,3)} seconds')
logger.info(f'Total computation time : {round(t_generate_landmarks + t_first_stage + t_generate_landmarks,3)} seconds')
linked_tour = LinkedLandmarks(refined_tour)
# upon creation of the trip, persistence of both the trip and its landmarks is ensured.
trip = Trip.from_linked_landmarks(linked_tour, cache_client)
@@ -165,7 +179,7 @@ def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -
raise HTTPException(status_code=406, detail="Coordinates not provided or invalid")
if not (-90 <= location[0] <= 90 or -180 <= location[1] <= 180):
raise HTTPException(status_code=422, detail="Start coordinates not in range")
toilets_manager = ToiletsManager(location, radius)
try :