From c15e257dea263de9ab563270813be3c0dd16bffa Mon Sep 17 00:00:00 2001 From: Helldragon67 Date: Tue, 11 Feb 2025 15:42:14 +0100 Subject: [PATCH 1/2] add trip time update --- backend/src/main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/src/main.py b/backend/src/main.py index 0c8c85f..9500f85 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -179,6 +179,45 @@ def get_landmark(landmark_uuid: str) -> Landmark: raise HTTPException(status_code=404, detail="Landmark not found") from exc +@app.post("/trip/recompute-time/{trip_uuid}/{removed_landmark_uuid}") +def update_trip_time(trip_uuid: str, removed_landmark_uuid: str) -> Trip: + """ + Updates the reaching times of a given trip when removing a landmark. + + Args: + landmark_uuid (str) : unique identifier for a Landmark. + + Returns: + (Landmark) : the corresponding Landmark. + """ + # First, fetch the trip in the cache. + try: + trip = cache_client.get(f'trip_{trip_uuid}') + except KeyError as exc: + raise HTTPException(status_code=404, detail='Trip not found') from exc + + landmarks = [] + next_uuid = trip.first_landmark_uuid + + # Extract landmarks + try : + while next_uuid is not None: + landmark = cache_client.get(f'landmark_{next_uuid}') + # Filter out the removed landmark. + if next_uuid != removed_landmark_uuid : + landmarks.append(landmark) + next_uuid = landmark.next_uuid # Prepare for the next iteration + except KeyError as exc: + raise HTTPException(status_code=404, detail=f'landmark {next_uuid} not found') from exc + + # Re-link every thing and compute times again + linked_tour = LinkedLandmarks(landmarks) + trip = Trip.from_linked_landmarks(linked_tour, cache_client) + + return trip + + + @app.post("/toilets/new") def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -> list[Toilets] : """ From da6ab207d927b9b67ddd212e38689e462a1d7529 Mon Sep 17 00:00:00 2001 From: kscheidecker Date: Mon, 17 Feb 2025 05:39:20 +0000 Subject: [PATCH 2/2] Update backend/src/logging_config.py --- backend/src/logging_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/logging_config.py b/backend/src/logging_config.py index a00302c..2412787 100644 --- a/backend/src/logging_config.py +++ b/backend/src/logging_config.py @@ -29,7 +29,7 @@ def configure_logging(): logger.info(f"Logging to Loki at {loki_url} with {loki_handler.labels} and {is_debug=}") logging_handlers = [loki_handler, logging.StreamHandler()] - logging_level = logging.DEBUG if is_debug else logging.INFO + logging_level = logging.DEBUG # silence the chatty logs loki generates itself logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING) # no need for time since it's added by loki or can be shown in kube logs @@ -39,7 +39,7 @@ def configure_logging(): # if we are in a debug (local) session, set verbose and rich logging from rich.logging import RichHandler logging_handlers = [RichHandler()] - logging_level = logging.DEBUG if is_debug else logging.INFO + logging_level = logging.DEBUG logging_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'