added more structure
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 3m29s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 12m29s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 34s

This commit is contained in:
2025-06-21 18:54:42 +02:00
parent f6d0cd5360
commit 6921ab57f8
8 changed files with 298 additions and 186 deletions

View File

@@ -1,12 +1,13 @@
"""Main app for backend api"""
import logging
import time
import random
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, BackgroundTasks
from .logging_config import configure_logging
from .structs.landmark import Landmark
from .structs.preferences import Preferences
from .structs.preferences import Preferences, Preference
from .structs.linked_landmarks import LinkedLandmarks
from .structs.trip import Trip
from .landmarks.landmarks_manager import LandmarkManager
@@ -140,7 +141,7 @@ def new_trip(preferences: Preferences,
# upon creation of the trip, persistence of both the trip and its landmarks is ensured.
trip = Trip.from_linked_landmarks(linked_tour, cache_client)
logger.info(f'Generated a trip of {trip.total_time} minutes with {len(refined_tour)} landmarks in {round(t_generate_landmarks + t_first_stage + t_second_stage,3)} seconds.')
logger.debug('Detailed trip :\n\t' + '\n\t'.join(f'{landmark}' for landmark in refined_tour))
logger.info('Detailed trip :\n\t' + '\n\t'.join(f'{landmark}' for landmark in refined_tour))
background_tasks.add_task(fill_cache)
@@ -224,3 +225,45 @@ def update_trip_time(trip_uuid: str, removed_landmark_uuid: str) -> Trip:
trip = Trip.from_linked_landmarks(linked_tour, cache_client)
return trip
# TODO: get stuff to do nearby. The idea is to have maybe thhe 3 best things to do within 500m and 2 hidden gems.
@app.post("/landmarks/get-nearby/{lat}/{lon}")
def get_landmarks_nearby(lat: float, lon: float) -> list[Landmark] :
# preferences = {"sightseeing": {"type": "sightseeing", "score": 0},
# "nature": {"type": "nature", "score": 0},
# "shopping": {"type": "shopping", "score": 5},
# "max_time_minute": 30,
# "detour_tolerance_minute": 0},
# Find the landmarks around the location
_, landmarks_around = manager.generate_landmarks_list(
center_coordinates = (lat, lon),
preferences = Preferences(
sightseeing = Preference(
type='sightseeing',
score=5
),
shopping = Preference(
type='shopping',
score=2
),
nature = Preference(
type='nature',
score=5
),
max_time_minute=30,
detour_tolerance_minute=0),
allow_clusters=False
)
if len(landmarks_around) == 0 :
raise HTTPException(status_code=500, detail="No landmarks were found.")
# select 5 landmarks from there
if len(landmarks_around) > 6 :
landmarks_around = landmarks_around[:2] + random.sample(landmarks_around[3:], 2)
logger.info('Suggested landmarks :\n\t' + '\n\t'.join(f'{landmark}' for landmark in landmarks_around))
return landmarks_around