reviewed code structure, cleaned comments, now pep8 conform
This commit is contained in:
@@ -12,49 +12,36 @@ app = FastAPI()
|
||||
|
||||
# Assuming frontend is calling like this :
|
||||
#"http://127.0.0.1:8000/process?param1={param1}¶m2={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]:
|
||||
@app.post("/optimizer_coords/{latitude}/{longitude}/{city_country}")
|
||||
def main1(preferences: Preferences = Body(...), latitude: float = None, longitude: float = None, city_country: str = None) -> List[Landmark]:
|
||||
|
||||
if preferences is None :
|
||||
raise ValueError("Please provide preferences in the form of a 'Preference' BaseModel class.")
|
||||
elif latitude is None and longitude is None and city_country is None :
|
||||
raise ValueError("Please provide GPS coordinates or a 'city_country' string.")
|
||||
elif latitude is not None and longitude is not None and city_country is not None :
|
||||
raise ValueError("Please provide EITHER GPS coordinates or a 'city_country' string.")
|
||||
|
||||
|
||||
# From frontend get longitude, latitude and prefence list
|
||||
if city_country is None :
|
||||
coordinates = tuple((latitude, longitude))
|
||||
|
||||
# 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
|
||||
[], landmarks_short = generate_landmarks(preferences=preferences, city_country=city_country, coordinates=coordinates)
|
||||
|
||||
start = Landmark(name='start', type=LandmarkType(landmark_type='start'), location=(48.8375946, 2.2949904), osm_type='start', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
finish = Landmark(name='finish', type=LandmarkType(landmark_type='finish'), location=(48.8375946, 2.2949904), osm_type='finish', osm_id=0, attractiveness=0, must_do=True, n_tags = 0)
|
||||
|
||||
# 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)))
|
||||
landmarks_short.insert(0, start)
|
||||
landmarks_short.append(finish)
|
||||
|
||||
max_walking_time = 4 # hours
|
||||
|
||||
visiting_order = solve_optimization(landmarks, max_steps, True)
|
||||
visiting_list = solve_optimization(landmarks_short, max_walking_time*60, True)
|
||||
|
||||
return visiting_order
|
||||
return visiting_list
|
||||
|
||||
# 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'
|
||||
|
||||
Reference in New Issue
Block a user