diff --git a/backend/Pipfile b/backend/Pipfile index f02576b..7ffd4d8 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -8,5 +8,6 @@ numpy = "*" scipy = "*" fastapi = "*" osmpythontools = "*" +pydantic = "*" [dev-packages] diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock index f07cd8e..d41ed09 100644 --- a/backend/Pipfile.lock +++ b/backend/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "15cc819367b908ccf7d61e3f2b45574c248556600dfeaa795e19045d6781fe90" + "sha256": "4293390eadd968364de0b376810eb66c68a4876d24a87987dc61010ad92c5712" }, "pipfile-spec": 6, "requires": {}, @@ -890,6 +890,7 @@ "sha256:71b2945998f9c9b7919a45bde9a50397b289937d215ae141c1d0903ba7149fd7", "sha256:834ab954175f94e6e68258537dc49402c4a5e9d0409b9f1b86b7e934a8372de7" ], + "index": "pypi", "markers": "python_version >= '3.8'", "version": "==2.7.2" }, diff --git a/backend/app/__init__.py b/backend/app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/app/__pycache__/__init__.cpython-310.pyc b/backend/app/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 678d7d0..0000000 Binary files a/backend/app/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/backend/app/__pycache__/main.cpython-310.pyc b/backend/app/__pycache__/main.cpython-310.pyc deleted file mode 100644 index cd67059..0000000 Binary files a/backend/app/__pycache__/main.cpython-310.pyc and /dev/null differ diff --git a/backend/app/dependencies.py b/backend/app/dependencies.py deleted file mode 100644 index 2cb6801..0000000 --- a/backend/app/dependencies.py +++ /dev/null @@ -1 +0,0 @@ -import app.src \ No newline at end of file diff --git a/backend/app/main.py b/backend/app/main.py deleted file mode 100644 index 257d572..0000000 --- a/backend/app/main.py +++ /dev/null @@ -1,34 +0,0 @@ -from .src.optimizer import solve_optimization -from .src.landmarks_manager import Landmark -from fastapi import FastAPI - -app = FastAPI() - - -@app.get("/optimize/{max_steps}/{print_details}") -def main(max_steps: int, print_details: bool): - - # CONSTRAINT TO RESPECT MAX NUMBER OF STEPS - #max_steps = 16 - - - # Initialize all landmarks (+ start and goal). Order matters here - landmarks = [] - landmarks.append(Landmark("départ", -1, (0, 0))) - landmarks.append(Landmark("tour eiffel", 99, (0,2))) # PUT IN JSON - landmarks.append(Landmark("arc de triomphe", 99, (0,4))) - landmarks.append(Landmark("louvre", 99, (0,6))) - landmarks.append(Landmark("montmartre", 99, (0,10))) - landmarks.append(Landmark("concorde", 99, (0,8))) - landmarks.append(Landmark("arrivée", -1, (0, 0))) - - - visiting_order = solve_optimization(landmarks, max_steps, print_details) - - #return visiting_order - - return("max steps :", max_steps, "\n", visiting_order) - - -"""if __name__ == "__main__": - main()""" \ No newline at end of file diff --git a/backend/app/src/__init__.py b/backend/app/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/app/src/__pycache__/__init__.cpython-310.pyc b/backend/app/src/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 3c06a08..0000000 Binary files a/backend/app/src/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/backend/app/src/__pycache__/optimizer.cpython-310.pyc b/backend/app/src/__pycache__/optimizer.cpython-310.pyc deleted file mode 100644 index e60b82c..0000000 Binary files a/backend/app/src/__pycache__/optimizer.cpython-310.pyc and /dev/null differ diff --git a/backend/app/src/landmarks_manager.py b/backend/src/landmarks_manager.py similarity index 91% rename from backend/app/src/landmarks_manager.py rename to backend/src/landmarks_manager.py index 0c3a0e2..c8207b4 100644 --- a/backend/app/src/landmarks_manager.py +++ b/backend/src/landmarks_manager.py @@ -1,6 +1,7 @@ from OSMPythonTools.api import Api from OSMPythonTools.overpass import Overpass from dataclasses import dataclass +from pydantic import BaseModel # Defines the landmark class (aka some place there is to visit) @@ -10,8 +11,7 @@ class Landmarkkkk : attractiveness : int id : int -@dataclass -class Landmark : +class Landmark(BaseModel) : name : str attractiveness : int loc : tuple diff --git a/backend/src/main.py b/backend/src/main.py new file mode 100644 index 0000000..d267aa8 --- /dev/null +++ b/backend/src/main.py @@ -0,0 +1,42 @@ +from optimizer import solve_optimization +from .structs.landmarks import LandmarkTest +from .structs.preferences import Preferences +from fastapi import FastAPI + +app = FastAPI() + +# This should become main at some point +@app.post("optimizer/{longitude}/{latitude}") +def get_data(longitude: float, latitude: float, preferences: Preferences) : + # From frontend get longitude, latitude and prefence list + + return + +@app.get("optimizer/{max_steps}/{print_details}") +def main(max_steps: int, print_details: bool): + + # 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, print_details) + + #return visiting_order + + # should return landmarks = the list of Landmark (ordered list) + return("max steps :", max_steps, "\n", visiting_order) + + +"""if __name__ == "__main__": + main()""" \ No newline at end of file diff --git a/backend/app/src/main_example.py b/backend/src/main_example.py similarity index 100% rename from backend/app/src/main_example.py rename to backend/src/main_example.py diff --git a/backend/app/src/optimizer.py b/backend/src/optimizer.py similarity index 100% rename from backend/app/src/optimizer.py rename to backend/src/optimizer.py diff --git a/backend/src/structs/landmarks.py b/backend/src/structs/landmarks.py new file mode 100644 index 0000000..cb262d9 --- /dev/null +++ b/backend/src/structs/landmarks.py @@ -0,0 +1,24 @@ +from pydantic import BaseModel +from .landmarktype import LandmarkType +from .preferences import Preferences + +class LandmarkTest(BaseModel) : + name : str + attractiveness : int + loc : tuple + +# Output to frontend +class Landmark(BaseModel) : + name : str + type: LandmarkType # De facto mapping depending on how the query was executed with overpass. Should still EXACTLY correspond to the preferences + location : tuple + + + def score(preferences: Preferences): + # loop through the preferences and assign a score + + + return 29 + + + diff --git a/backend/src/structs/landmarktype.py b/backend/src/structs/landmarktype.py new file mode 100644 index 0000000..8a63a1b --- /dev/null +++ b/backend/src/structs/landmarktype.py @@ -0,0 +1,4 @@ +from pydantic import BaseModel + +class LandmarkType(BaseModel): + landmark_type: str \ No newline at end of file diff --git a/backend/src/structs/preferences.py b/backend/src/structs/preferences.py new file mode 100644 index 0000000..94e0836 --- /dev/null +++ b/backend/src/structs/preferences.py @@ -0,0 +1,28 @@ +from pydantic import BaseModel +from .landmarktype import LandmarkType + +class Preference(BaseModel) : + name: str + type: LandmarkType + score: int + +# Input for optimization +class Preferences(BaseModel) : + # Sightseeing / History & Culture (Musées, bâtiments historiques, opéras, églises) + sightseeing : Preference + + # Nature (parcs, jardins, rivières, plages) + nature: Preference + + # Shopping (diriger plutôt vers des zones / rues commerçantes) + shopping : Preference + + # Food (price low or high. Combien on veut dépenser pour manger à midi/soir) + food_budget : Preference + + # Tolérance au détour (ce qui détermine (+ ou -) le chemin emprunté) + detour_tol : Preference + + + +