anyway/backend/src/main.py
Kilian Scheidecker adbb6466d9
All checks were successful
Build and push docker image / Build (pull_request) Successful in 2m17s
Build and release APK / Build APK (pull_request) Successful in 5m56s
Build web / Build Web (pull_request) Successful in 1m15s
fixed optimizer. works fine now
2024-06-10 14:24:37 +02:00

73 lines
2.3 KiB
Python

from optimizer import solve_optimization
from landmarks_manager import generate_landmarks
from structs.landmarks import LandmarkTest
from structs.landmarks import Landmark
from structs.landmarktype import LandmarkType
from structs.preferences import Preferences, Preference
from fastapi import FastAPI, Query, Body
from typing import List
app = FastAPI()
# Assuming frontend is calling like this :
#"http://127.0.0.1:8000/process?param1={param1}&param2={param2}"
@app.post("/optimizer_coords/{longitude}/{latitude}/{city_country}")
def main1(preferences: Preferences = Body(...), longitude: float = None, latitude: float = None, city_country: str = None) -> List[Landmark]:
# From frontend get longitude, latitude and prefence list
# Generate the landmark list
landmarks = generate_landmarks(preferences=preferences, city_country=city_country, coordinates=tuple((longitude, latitude)))
# Set the max distance
max_steps = 90
# Compute the visiting order
visiting_order = solve_optimization(landmarks, max_steps, True)
return visiting_order
@app.get("test")
def test():
# CONSTRAINT TO RESPECT MAX NUMBER OF STEPS
max_steps = 16
# Initialize all landmarks (+ start and goal). Order matters here
landmarks = []
landmarks.append(LandmarkTest("départ", -1, (0, 0)))
landmarks.append(LandmarkTest("tour eiffel", 99, (0,2))) # PUT IN JSON
landmarks.append(LandmarkTest("arc de triomphe", 99, (0,4)))
landmarks.append(LandmarkTest("louvre", 99, (0,6)))
landmarks.append(LandmarkTest("montmartre", 99, (0,10)))
landmarks.append(LandmarkTest("concorde", 99, (0,8)))
landmarks.append(LandmarkTest("arrivée", -1, (0, 0)))
visiting_order = solve_optimization(landmarks, max_steps, True)
return visiting_order
# should return landmarks = the list of Landmark (ordered list)
#return("max steps :", max_steps, "\n", visiting_order)
# input city, country in the form of 'Paris, France'
@app.post("/test2/{city_country}")
def test2(city_country: str, preferences: Preferences = Body(...)) -> List[Landmark]:
landmarks = generate_landmarks(city_country, preferences)
max_steps = 9000000
visiting_order = solve_optimization(landmarks, max_steps, True)