45 Commits

Author SHA1 Message Date
132aa5a19b changed to no dev when building the docker image
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m24s
Run linting on the backend code / Build (pull_request) Failing after 21s
Run testing on the backend code / Build (pull_request) Failing after 22m41s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 36s
2025-07-26 12:44:41 +02:00
19b0c37a97 fixed the missing dependency in the refiner and changed the test run to using uv 2025-07-26 12:44:12 +02:00
ecdef605a7 cleanup and removed pipenv files 2025-07-26 12:41:58 +02:00
e2a918112b changed to uv fo managing dependencies 2025-07-26 12:41:15 +02:00
96b0718081 removed unused landmark attributes
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m39s
Run linting on the backend code / Build (pull_request) Successful in 31s
Run testing on the backend code / Build (pull_request) Failing after 49s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 38s
2025-07-13 17:47:12 +02:00
d9e5d9dac6 fixed dependcu
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m8s
Run linting on the backend code / Build (pull_request) Successful in 29s
Run testing on the backend code / Build (pull_request) Failing after 46s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 28s
2025-07-13 17:45:13 +02:00
b0f9d31ee2 Implement backend API for landmarks, trip optimization, and toilet locations
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m49s
Run linting on the backend code / Build (pull_request) Successful in 30s
Run testing on the backend code / Build (pull_request) Failing after 45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 32s
- Added landmarks_router.py to handle landmark retrieval based on user preferences and location.
- Implemented optimization_router.py for trip optimization, including handling preferences and landmarks.
- Created toilets_router.py to fetch toilet locations within a specified radius from a given location.
- Enhanced error handling and logging across all new endpoints.
- Generated a comprehensive report.html for test results and environment details.
2025-07-13 17:43:24 +02:00
54bc9028ad simplified test pipeline
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m38s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 17m36s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 35s
2025-07-02 21:59:07 +02:00
37926e68ec fixed typo in invalid inputs
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m24s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 20m39s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 32s
2025-07-02 21:58:47 +02:00
e2d3d29956 working split
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m46s
Run linting on the backend code / Build (pull_request) Successful in 2m31s
Run testing on the backend code / Build (pull_request) Failing after 12m37s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 29s
2025-06-22 14:24:00 +02:00
6921ab57f8 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
2025-06-21 18:54:42 +02:00
f6d0cd5360 Merge pull request 'backend/feature/add-description' (#63) from backend/feature/add-description into main
Some checks failed
Build and deploy the backend to production / Build and push image (push) Successful in 1m36s
/ push-to-remote (push) Failing after 33s
Build and deploy the backend to production / Deploy to production (push) Successful in 25s
Reviewed-on: #63
2025-02-21 07:38:15 +00:00
7a18830e99 removed debug from prod
Some checks failed
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m51s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
2025-02-20 20:07:20 +01:00
ba14a0279e better logs again
Some checks failed
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m41s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
2025-02-20 19:49:18 +01:00
5a2c61d343 better logs
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m40s
Run linting on the backend code / Build (pull_request) Successful in 55s
Run testing on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
2025-02-20 19:11:23 +01:00
5e27dd9d79 corrected import
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m11s
Run linting on the backend code / Build (pull_request) Has been cancelled
Run testing on the backend code / Build (pull_request) Failing after 35m5s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 26s
2025-02-19 16:09:52 +01:00
d92001faaf forgot to add main
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m39s
Run linting on the backend code / Build (pull_request) Successful in 29s
Run testing on the backend code / Build (pull_request) Failing after 47s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 26s
2025-02-19 16:04:31 +01:00
73f0dc8361 linting
Some checks failed
Run linting on the backend code / Build (pull_request) Has been cancelled
Run testing on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
2025-02-19 16:04:18 +01:00
05092e55f1 better structure
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m45s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s
2025-02-19 15:53:41 +01:00
83be4b7616 linting
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Successful in 28s
2025-02-19 14:51:38 +01:00
8a9ec6b4d8 fixed double description
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m39s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 26m40s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 26s
2025-02-19 11:16:01 +01:00
8c3145dfc9 increased max_iter and park support 2025-02-19 11:11:23 +01:00
2bf38119d6 added descriptions 2025-02-19 11:04:18 +01:00
ca711c614f test 2025-02-18 18:50:09 +01:00
357edf3000 added branch 2025-02-18 18:24:04 +01:00
444c47e3a4 Merge pull request 'backend/feature/recompute-trip-time' (#62) from backend/feature/recompute-trip-time into main
Some checks failed
/ push-to-remote (push) Has been cancelled
Build and deploy the backend to production / Build and push image (push) Successful in 1m40s
Build and deploy the backend to production / Deploy to production (push) Successful in 25s
Reviewed-on: #62
2025-02-17 05:40:22 +00:00
da6ab207d9 Update backend/src/logging_config.py
Some checks failed
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
2025-02-17 05:39:20 +00:00
c15e257dea add trip time update
Some checks failed
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
Run testing on the backend code / Build (pull_request) Has been cancelled
Run linting on the backend code / Build (pull_request) Successful in 27s
2025-02-11 15:42:14 +01:00
5a698dd02c Merge pull request 'Adding licenses' (#58) from licenses into main
Reviewed-on: #58
2025-02-11 08:36:16 +00:00
7e4a4b3dc7 added general license 2025-02-11 08:25:02 +00:00
84e5902436 Merge pull request 'fixed cluster names' (#57) from backend/fix/missing-cluster-names into main
Some checks failed
Build and deploy the backend to production / Build and push image (push) Successful in 2m9s
/ push-to-remote (push) Failing after 41s
Build and deploy the backend to production / Deploy to production (push) Successful in 23s
Reviewed-on: #57
2025-02-11 06:50:11 +00:00
81330e5eb3 fixed cluster names
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m54s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 4m19s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 24s
2025-02-11 07:34:50 +01:00
9002483036 Merge pull request 'Removes the rounding from the trip details' (#56) from frontend/no-more-rounding into main
Reviewed-on: #56
2025-02-07 18:09:31 +00:00
0271c3d7a7 removed rounding but app won't compile
Some checks failed
Build and release debug APK / Build APK (pull_request) Failing after 3m37s
2025-02-07 15:14:21 +01:00
4fd1272ea4 test
Some checks failed
Build and release debug APK / Build APK (pull_request) Failing after 3m7s
2025-02-07 15:08:00 +01:00
6bedd04a57 removed rounding
Some checks failed
Build and release debug APK / Build APK (pull_request) Failing after 4m10s
2025-02-07 14:44:18 +01:00
d31ca9f81f Merge pull request 'Frontend UX improvements' (#37) from feature/frontend/image-loading into main
Reviewed-on: #37
2025-02-05 12:55:24 +00:00
f6e396e54b undo add test.py
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Has been cancelled
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been cancelled
Build and release debug APK / Build APK (pull_request) Has been cancelled
2025-02-05 13:53:10 +01:00
d4de945df8 cleaner trip loading indicator
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m57s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 26s
Build and release debug APK / Build APK (pull_request) Has been cancelled
2025-02-05 13:50:38 +01:00
d992b62533 tentatively shrink trip overview, nicer onboarding 2024-12-17 11:17:59 +01:00
e78bee4597 some more images 2024-12-17 10:28:33 +01:00
d186a51a87 WIP: ladnmark card adjustments 2024-12-15 16:30:17 +01:00
4baf045c8c better onboarding
All checks were successful
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m1s
Build and release debug APK / Build APK (pull_request) Successful in 10m54s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 14s
2024-12-02 10:43:42 +01:00
3f1fe463bf better help and onboarding
All checks were successful
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m40s
Build and release debug APK / Build APK (pull_request) Successful in 7m23s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 14s
2024-11-18 17:42:52 +01:00
d58ef2562d image querying from within the frontend
All checks were successful
Build and release debug APK / Build APK (pull_request) Successful in 7m40s
2024-11-06 14:45:43 +01:00
72 changed files with 4798 additions and 2479 deletions

View File

@@ -18,17 +18,17 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
apt-get update && apt-get install -y python3 python3-pip apt-get update && apt-get install -y python3 python3-pip
pip install pipenv pip install uv
- name: Install packages - name: Install packages
run: | run: |
ls -la ls -la
# install all packages, including dev-packages # install all packages, including dev-packages
pipenv install --dev uv sync
working-directory: backend working-directory: backend
- name: Run Tests - name: Run Tests
run: pipenv run pytest src --html=report.html --self-contained-html --log-cli-level=DEBUG run: uv run pytest src --html=report.html --self-contained-html --log-cli-level=DEBUG
working-directory: backend working-directory: backend
- name: Upload HTML report - name: Upload HTML report

30
LICENSE.md Normal file
View File

@@ -0,0 +1,30 @@
# License
## Proprietary License
All code and resources in this repository are the property of AnyDev. The software and related documentation are provided solely for use with services provided by AnyDev. Redistribution, modification, or use of this software outside of its intended service is strictly prohibited without explicit permission.
### Copyright © 2024 AnyDev
All rights reserved.
### Restrictions
- You may not modify, distribute, copy, or reverse engineer any part of this codebase.
- This software is licensed for use solely in conjunction with services provided by AnyDev.
- Any commercial use of this software is strictly prohibited without explicit written consent from AnyDev.
## Third-Party Dependencies
This project uses third-party dependencies, which are subject to their respective licenses.
- Python backend dependencies: fastapi, pydantic, numpy, shapely, etc. Licensed under their respective licenses.
- Flutter frontend dependencies: Cupertino Icons, sliding_up_panel, http, etc. Licensed under their respective licenses.
Please refer to each project's documentation for the specific terms and conditions.
## OpenStreetMap Data Usage
This project uses data derived from **OpenStreetMap**. OpenStreetMap data is available under the [Open Database License (ODbL)](https://www.openstreetmap.org/copyright). We comply with the ODbL license, and some of the data displayed in the service may be derived from OpenStreetMap sources. We do not redistribute raw OpenStreetMap data; instead, it is processed and transformed before being used in our services.
More information about OpenStreetMap data usage can be found [here](https://www.openstreetmap.org/copyright).

6
backend/.gitignore vendored
View File

@@ -1,6 +1,9 @@
# osm-cache # osm-cache
cache_XML/ cache_XML/
# secrets
*secrets.yaml
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
@@ -9,6 +12,9 @@ __pycache__/
# C extensions # C extensions
*.so *.so
# Pytest reports
report.html
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/

1
backend/.python-version Normal file
View File

@@ -0,0 +1 @@
3.12.9

View File

@@ -1,11 +1,29 @@
FROM python:3.11-slim FROM python:3.12-slim-bookworm
# The installer requires curl (and certificates) to download the release archive
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates
# Download the latest installer
ADD https://astral.sh/uv/install.sh /uv-installer.sh
# Run the installer then remove it
RUN sh /uv-installer.sh && rm /uv-installer.sh
# Ensure the installed binary is on the `PATH`
ENV PATH="/root/.local/bin/:$PATH"
# Set the working directory
WORKDIR /app WORKDIR /app
COPY Pipfile Pipfile.lock .
RUN pip install pipenv # Copy uv files
RUN pipenv install --deploy --system COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock
COPY .python-version .python-version
# Sync the venv
RUN uv sync --frozen --no-cache --no-dev
# Copy application files
COPY src src COPY src src
EXPOSE 8000 EXPOSE 8000
@@ -17,4 +35,4 @@ ENV MEMCACHED_HOST_PATH=none
ENV LOKI_URL=none ENV LOKI_URL=none
# explicitly use a string instead of an argument list to force a shell and variable expansion # explicitly use a string instead of an argument list to force a shell and variable expansion
CMD fastapi run src/main.py --port 8000 --workers $NUM_WORKERS CMD uv run fastapi run src/main.py --port 8000 --workers $NUM_WORKERS

View File

@@ -1,27 +0,0 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
pylint = "*"
pytest = "*"
tomli = "*"
httpx = "*"
exceptiongroup = "*"
pytest-html = "*"
typing-extensions = "*"
dill = "*"
[packages]
numpy = "*"
fastapi = "*"
pydantic = "*"
shapely = "*"
pymemcache = "*"
fastapi-cli = "*"
scikit-learn = "*"
loki-logger-handler = "*"
pulp = "*"
scipy = "*"
requests = "*"

1246
backend/Pipfile.lock generated

File diff suppressed because it is too large Load Diff

6
backend/main.py Normal file
View File

@@ -0,0 +1,6 @@
def main():
print("Hello from backend!")
if __name__ == "__main__":
main()

55
backend/pyproject.toml Normal file
View File

@@ -0,0 +1,55 @@
[project]
name = "backend"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"annotated-types==0.7.0 ; python_full_version >= '3.8'",
"anyio==4.8.0 ; python_full_version >= '3.9'",
"certifi==2024.12.14 ; python_full_version >= '3.6'",
"charset-normalizer==3.4.1 ; python_full_version >= '3.7'",
"click==8.1.8 ; python_full_version >= '3.7'",
"fastapi==0.115.7 ; python_full_version >= '3.8'",
"fastapi-cli==0.0.7 ; python_full_version >= '3.8'",
"h11==0.14.0 ; python_full_version >= '3.7'",
"httptools==0.6.4",
"idna==3.10 ; python_full_version >= '3.6'",
"joblib==1.4.2 ; python_full_version >= '3.8'",
"loki-logger-handler==1.1.0 ; python_full_version >= '2.7'",
"markdown-it-py==3.0.0 ; python_full_version >= '3.8'",
"mdurl==0.1.2 ; python_full_version >= '3.7'",
"numpy==2.2.2 ; python_full_version >= '3.10'",
"pulp==2.9.0 ; python_full_version >= '3.7'",
"pydantic==2.10.6 ; python_full_version >= '3.8'",
"pydantic-core==2.27.2 ; python_full_version >= '3.8'",
"pygments==2.19.1 ; python_full_version >= '3.8'",
"pymemcache==4.0.0 ; python_full_version >= '3.7'",
"python-dotenv==1.0.1",
"pyyaml==6.0.2",
"requests==2.32.3 ; python_full_version >= '3.8'",
"rich==13.9.4 ; python_full_version >= '3.8'",
"rich-toolkit==0.13.2 ; python_full_version >= '3.8'",
"scikit-learn==1.6.1 ; python_full_version >= '3.9'",
"scipy==1.15.1 ; python_full_version >= '3.10'",
"shapely==2.0.6 ; python_full_version >= '3.7'",
"shellingham==1.5.4 ; python_full_version >= '3.7'",
"sniffio==1.3.1 ; python_full_version >= '3.7'",
"starlette==0.45.3 ; python_full_version >= '3.9'",
"threadpoolctl==3.5.0 ; python_full_version >= '3.8'",
"typer==0.15.1 ; python_full_version >= '3.7'",
"typing-extensions==4.12.2 ; python_full_version >= '3.8'",
"urllib3==2.3.0 ; python_full_version >= '3.9'",
"uvicorn[standard]==0.34.0 ; python_full_version >= '3.9'",
"uvloop==0.21.0",
"watchfiles==1.0.4",
"websockets==14.2",
]
[dependency-groups]
dev = [
"httpx>=0.28.1",
"ipykernel>=6.30.0",
"pytest>=8.4.1",
"pytest-html>=4.1.1",
]

File diff suppressed because one or more lines are too long

View File

View File

@@ -1,6 +1,6 @@
"""Find clusters of interest to add more general areas of visit to the tour.""" """Find clusters of interest to add more general areas of visit to the tour."""
import logging import logging
from typing import Literal from typing import Literal, Tuple
import numpy as np import numpy as np
from sklearn.cluster import DBSCAN from sklearn.cluster import DBSCAN
@@ -8,8 +8,8 @@ from pydantic import BaseModel
from ..overpass.overpass import Overpass, get_base_info from ..overpass.overpass import Overpass, get_base_info
from ..structs.landmark import Landmark from ..structs.landmark import Landmark
from .get_time_distance import get_distance from ..utils.get_time_distance import get_distance
from .utils import create_bbox from ..utils.bbox import create_bbox
@@ -33,7 +33,7 @@ class Cluster(BaseModel):
""" """
type: Literal['street', 'area'] type: Literal['street', 'area']
importance: int importance: int
centroid: tuple centroid: Tuple[float, float]
# start: Optional[list] = None # for later use if we want to have streets as well # start: Optional[list] = None # for later use if we want to have streets as well
# end: Optional[list] = None # end: Optional[list] = None
@@ -103,7 +103,7 @@ class ClusterManager:
out = out out = out
) )
except Exception as e: except Exception as e:
self.logger.error(f"Error fetching clusters: {e}") self.logger.warning(f"Error fetching clusters: {e}")
if result is None : if result is None :
self.logger.debug(f"Found no {cluster_type} clusters, overpass query returned no datapoints.") self.logger.debug(f"Found no {cluster_type} clusters, overpass query returned no datapoints.")
@@ -113,7 +113,7 @@ class ClusterManager:
points = [] points = []
for elem in result: for elem in result:
osm_type = elem.get('type') osm_type = elem.get('type')
# Get coordinates and append them to the points list # Get coordinates and append them to the points list
_, coords = get_base_info(elem, osm_type) _, coords = get_base_info(elem, osm_type)
if coords is not None : if coords is not None :
@@ -146,7 +146,7 @@ class ClusterManager:
self.valid = False self.valid = False
else : else :
self.logger.debug(f"Detected 0 {cluster_type} clusters.") self.logger.debug(f"Found 0 {cluster_type} clusters.")
self.valid = False self.valid = False
@@ -178,11 +178,12 @@ class ClusterManager:
# Calculate the centroid as the mean of the points # Calculate the centroid as the mean of the points
centroid = np.mean(current_cluster, axis=0) centroid = np.mean(current_cluster, axis=0)
centroid = tuple((round(centroid[0], 7), round(centroid[1], 7)))
if self.cluster_type == 'shopping' : if self.cluster_type == 'shopping' :
score = len(current_cluster)*2 score = len(current_cluster)*3
else : else :
score = len(current_cluster)*8 score = len(current_cluster)*15
locations.append(Cluster( locations.append(Cluster(
type='area', type='area',
centroid=centroid, centroid=centroid,
@@ -215,18 +216,18 @@ class ClusterManager:
""" """
# Define the bounding box for a given radius around the coordinates # Define the bounding box for a given radius around the coordinates
bbox = create_bbox(cluster.centroid, 1000) bbox = create_bbox(cluster.centroid, 300)
# Query neighborhoods and shopping malls # Query neighborhoods and shopping malls
selectors = ['"place"~"^(suburb|neighborhood|neighbourhood|quarter|city_block)$"'] selectors = ['"place"~"^(suburb|neighborhood|neighbourhood|quarter|city_block)$"']
if self.cluster_type == 'shopping' : if self.cluster_type == 'shopping' :
selectors.append('"shop"="mall"') selectors.append('"shop"="mall"')
new_name = 'Shopping Area' new_name = 'Shopping Area'
t = 40 t = 30
else : else :
new_name = 'Neighborhood' new_name = 'Neighborhood'
t = 15 t = 20
min_dist = float('inf') min_dist = float('inf')
osm_id = 0 osm_id = 0
@@ -238,30 +239,28 @@ class ClusterManager:
result = self.overpass.send_query(bbox = bbox, result = self.overpass.send_query(bbox = bbox,
osm_types = osm_types, osm_types = osm_types,
selector = sel, selector = sel,
out = 'ids center' out = 'ids center tags'
) )
except Exception as e: except Exception as e:
self.logger.error(f"Error fetching clusters: {e}") self.logger.warning(f"Error fetching clusters: {e}")
continue continue
if result is None : if result is None :
self.logger.error(f"Error fetching clusters: {e}") self.logger.warning(f"Error fetching clusters: query result is None")
continue continue
for elem in result: for elem in result:
osm_type = elem.get('type') # Get basic info
id, coords, name = get_base_info(elem, elem.get('type'), with_name=True)
id, coords, name = get_base_info(elem, osm_type, with_name=True)
if name is None or coords is None : if name is None or coords is None :
continue continue
d = get_distance(cluster.centroid, coords) d = get_distance(cluster.centroid, coords)
if d < min_dist : if d < min_dist :
min_dist = d min_dist = d
new_name = name new_name = name # add name
osm_type = osm_type # Add type: 'way' or 'relation' osm_type = elem.get('type') # add type: 'way' or 'relation'
osm_id = id # Add OSM id osm_id = id # add OSM id
return Landmark( return Landmark(
name=new_name, name=new_name,

View File

@@ -4,10 +4,9 @@ import yaml
from ..structs.preferences import Preferences from ..structs.preferences import Preferences
from ..structs.landmark import Landmark from ..structs.landmark import Landmark
from .take_most_important import take_most_important
from .cluster_manager import ClusterManager from .cluster_manager import ClusterManager
from ..overpass.overpass import Overpass, get_base_info from ..overpass.overpass import Overpass, get_base_info
from .utils import create_bbox from ..utils.bbox import create_bbox
from ..constants import AMENITY_SELECTORS_PATH, LANDMARK_PARAMETERS_PATH, OPTIMIZER_PARAMETERS_PATH from ..constants import AMENITY_SELECTORS_PATH, LANDMARK_PARAMETERS_PATH, OPTIMIZER_PARAMETERS_PATH
@@ -23,7 +22,7 @@ class LandmarkManager:
church_coeff: float # coeff to adjsut score of churches church_coeff: float # coeff to adjsut score of churches
nature_coeff: float # coeff to adjust score of parks nature_coeff: float # coeff to adjust score of parks
overall_coeff: float # coeff to adjust weight of tags overall_coeff: float # coeff to adjust weight of tags
n_important: int # number of important landmarks to consider # n_important: int # number of important landmarks to consider
def __init__(self) -> None: def __init__(self) -> None:
@@ -39,11 +38,10 @@ class LandmarkManager:
self.overall_coeff = parameters['overall_coeff'] self.overall_coeff = parameters['overall_coeff']
self.tag_exponent = parameters['tag_exponent'] self.tag_exponent = parameters['tag_exponent']
self.image_bonus = parameters['image_bonus'] self.image_bonus = parameters['image_bonus']
self.name_bonus = parameters['name_bonus']
self.wikipedia_bonus = parameters['wikipedia_bonus'] self.wikipedia_bonus = parameters['wikipedia_bonus']
self.viewpoint_bonus = parameters['viewpoint_bonus'] self.viewpoint_bonus = parameters['viewpoint_bonus']
self.pay_bonus = parameters['pay_bonus'] self.pay_bonus = parameters['pay_bonus']
self.n_important = parameters['N_important'] # self.n_important = parameters['N_important']
with OPTIMIZER_PARAMETERS_PATH.open('r') as f: with OPTIMIZER_PARAMETERS_PATH.open('r') as f:
parameters = yaml.safe_load(f) parameters = yaml.safe_load(f)
@@ -56,7 +54,12 @@ class LandmarkManager:
self.logger.info('LandmakManager successfully initialized.') self.logger.info('LandmakManager successfully initialized.')
def generate_landmarks_list(self, center_coordinates: tuple[float, float], preferences: Preferences) -> tuple[list[Landmark], list[Landmark]]: def generate_landmarks_list(
self,
center_coordinates: tuple[float, float],
preferences: Preferences,
allow_clusters: bool = True
) -> list[Landmark] :
""" """
Generate and prioritize a list of landmarks based on user preferences. Generate and prioritize a list of landmarks based on user preferences.
@@ -64,16 +67,17 @@ class LandmarkManager:
and current location. It scores and corrects these landmarks, removes duplicates, and then selects the most important and current location. It scores and corrects these landmarks, removes duplicates, and then selects the most important
landmarks based on a predefined criterion. landmarks based on a predefined criterion.
Args: Parameters :
center_coordinates (tuple[float, float]): The latitude and longitude of the center location around which to search. center_coordinates (tuple[float, float]): The latitude and longitude of the center location around which to search.
preferences (Preferences): The user's preference settings that influence the landmark selection. preferences (Preferences): The user's preference settings that influence the landmark selection.
allow_clusters (bool, optional) : If set to False, no clusters will be fetched. Mainly used for the option to fetch landmarks nearby.
Returns: Returns:
tuple[list[Landmark], list[Landmark]]: tuple[list[Landmark], list[Landmark]]:
- A list of all existing landmarks. - A list of all existing landmarks.
- A list of the most important landmarks based on the user's preferences. - A list of the most important landmarks based on the user's preferences.
""" """
self.logger.debug('Starting to fetch landmarks...') self.logger.info(f'Starting to fetch landmarks around {center_coordinates}...')
max_walk_dist = int((preferences.max_time_minute/2)/60*self.walking_speed*1000/self.detour_factor) max_walk_dist = int((preferences.max_time_minute/2)/60*self.walking_speed*1000/self.detour_factor)
radius = min(max_walk_dist, int(self.max_bbox_side/2)) radius = min(max_walk_dist, int(self.max_bbox_side/2))
@@ -90,10 +94,11 @@ class LandmarkManager:
all_landmarks.update(current_landmarks) all_landmarks.update(current_landmarks)
self.logger.info(f'Found {len(current_landmarks)} sightseeing landmarks') self.logger.info(f'Found {len(current_landmarks)} sightseeing landmarks')
if allow_clusters :
# special pipeline for historic neighborhoods # special pipeline for historic neighborhoods
neighborhood_manager = ClusterManager(bbox, 'sightseeing') neighborhood_manager = ClusterManager(bbox, 'sightseeing')
historic_clusters = neighborhood_manager.generate_clusters() historic_clusters = neighborhood_manager.generate_clusters()
all_landmarks.update(historic_clusters) all_landmarks.update(historic_clusters)
# list for nature # list for nature
if preferences.nature.score != 0: if preferences.nature.score != 0:
@@ -114,16 +119,19 @@ class LandmarkManager:
landmark.duration = 30 landmark.duration = 30
all_landmarks.update(current_landmarks) all_landmarks.update(current_landmarks)
# special pipeline for shopping malls if allow_clusters :
shopping_manager = ClusterManager(bbox, 'shopping') # special pipeline for shopping malls
shopping_clusters = shopping_manager.generate_clusters() shopping_manager = ClusterManager(bbox, 'shopping')
all_landmarks.update(shopping_clusters) shopping_clusters = shopping_manager.generate_clusters()
all_landmarks.update(shopping_clusters)
landmarks_constrained = take_most_important(all_landmarks, self.n_important) # DETAILS HERE
# self.logger.info(f'All landmarks generated : {len(all_landmarks)} landmarks around {center_coordinates}, and constrained to {len(landmarks_constrained)} most important ones.') # self.logger.info(f'All landmarks generated : {len(all_landmarks)} landmarks around {center_coordinates}, and constrained to {len(landmarks_constrained)} most important ones.')
self.logger.info(f'Found {len(all_landmarks)} landmarks in total.')
return all_landmarks, landmarks_constrained return sorted(all_landmarks, key=lambda x: x.attractiveness, reverse=True)
def set_landmark_score(self, landmark: Landmark, landmarktype: str, preference_level: int) : def set_landmark_score(self, landmark: Landmark, landmarktype: str, preference_level: int) :
""" """
@@ -147,6 +155,8 @@ class LandmarkManager:
score *= self.wikipedia_bonus score *= self.wikipedia_bonus
if landmark.is_place_of_worship : if landmark.is_place_of_worship :
score *= self.church_coeff score *= self.church_coeff
if landmark.is_viewpoint :
score *= self.viewpoint_bonus
if landmarktype == 'nature' : if landmarktype == 'nature' :
score *= self.nature_coeff score *= self.nature_coeff
@@ -196,12 +206,12 @@ class LandmarkManager:
out = 'ids center tags' out = 'ids center tags'
) )
except Exception as e: except Exception as e:
self.logger.error(f"Error fetching landmarks: {e}") self.logger.debug(f"Failed to fetch landmarks, proceeding without: {str(e)}")
continue continue
return_list += self._to_landmarks(result, landmarktype, preference_level) return_list += self._to_landmarks(result, landmarktype, preference_level)
self.logger.debug(f"Fetched {len(return_list)} landmarks of type {landmarktype} in {bbox}") # self.logger.debug(f"Fetched {len(return_list)} landmarks of type {landmarktype} in {bbox}")
return return_list return return_list
@@ -235,6 +245,17 @@ class LandmarkManager:
continue continue
tags = elem.get('tags') tags = elem.get('tags')
n_tags=len(tags)
# Skip this landmark if not suitable
if tags.get('building:part') is not None :
continue
if tags.get('disused') is not None :
continue
if tags.get('boundary') is not None :
continue
if tags.get('shop') is not None and landmarktype != 'shopping' :
continue
# Convert this to Landmark object # Convert this to Landmark object
landmark = Landmark(name=name, landmark = Landmark(name=name,
@@ -243,57 +264,36 @@ class LandmarkManager:
osm_id=id, osm_id=id,
osm_type=osm_type, osm_type=osm_type,
attractiveness=0, attractiveness=0,
n_tags=len(tags)) n_tags=n_tags)
# self.logger.debug('added landmark.') # Extract useful information for score calculation later down the road.
landmark.image_url = tags.get('image')
landmark.website_url = tags.get('website')
landmark.wiki_url = tags.get('wikipedia')
landmark.name_en = tags.get('name:en')
# Browse through tags to add information to landmark. # Check for place of worship
for key, value in tags.items(): if tags.get('place_of_worship') is not None :
# Skip this landmark if not suitable.
if key == 'building:part' and value == 'yes' :
break
if 'disused:' in key :
break
if 'boundary:' in key :
break
if 'shop' in key and landmarktype != 'shopping' :
break
# if value == 'apartments' :
# break
# Fill in the other attributes.
if key == 'image' :
landmark.image_url = value
if key == 'website' :
landmark.website_url = value
if key == 'place_of_worship' :
landmark.is_place_of_worship = True landmark.is_place_of_worship = True
if key == 'wikipedia' : landmark.name_en = tags.get('place_of_worship')
landmark.wiki_url = value
if key == 'name:en' :
landmark.name_en = value
if 'building:' in key or 'pay' in key :
landmark.n_tags -= 1
# Set the duration. # Set the duration. Needed for the optimization.
if value in ['museum', 'aquarium', 'planetarium'] : if tags.get('amenity') in ['aquarium', 'planetarium'] or tags.get('tourism') in ['aquarium', 'museum', 'zoo']:
landmark.duration = 60 landmark.duration = 60
elif value == 'viewpoint' : elif tags.get('tourism') == 'viewpoint' :
landmark.is_viewpoint = True landmark.is_viewpoint = True
landmark.duration = 10 landmark.duration = 10
elif value == 'cathedral' : elif tags.get('building') == 'cathedral' :
landmark.is_place_of_worship = False landmark.is_place_of_worship = False
landmark.duration = 10 landmark.duration = 10
else: # Compute the score and add landmark to the list.
self.set_landmark_score(landmark, landmarktype, preference_level) self.set_landmark_score(landmark, landmarktype, preference_level)
landmarks.append(landmark) landmarks.append(landmark)
continue
return landmarks return landmarks
def dict_to_selector_list(d: dict) -> list: def dict_to_selector_list(d: dict) -> list:
""" """
Convert a dictionary of key-value pairs to a list of Overpass query strings. Convert a dictionary of key-value pairs to a list of Overpass query strings.

View File

@@ -0,0 +1,123 @@
"""Main app for backend api"""
import logging
import time
import random
from fastapi import HTTPException, APIRouter
from ..structs.landmark import Landmark
from ..structs.preferences import Preferences, Preference
from .landmarks_manager import LandmarkManager
# Setup the logger and the Landmarks Manager
logger = logging.getLogger(__name__)
manager = LandmarkManager()
# Initialize the API router
router = APIRouter()
@router.post("/get/landmarks")
def get_landmarks(
preferences: Preferences,
start: tuple[float, float],
) -> list[Landmark]:
"""
Function that returns all available landmarks given some preferences and a start position.
Args:
preferences : the preferences specified by the user as the post body
start : the coordinates of the starting point
Returns:
list[Landmark] : The full list of fetched landmarks
"""
if preferences is None:
raise HTTPException(status_code=406, detail="Preferences not provided or incomplete.")
if (preferences.shopping.score == 0 and
preferences.sightseeing.score == 0 and
preferences.nature.score == 0) :
raise HTTPException(status_code=406, detail="All preferences are 0.")
if start is None:
raise HTTPException(status_code=406, detail="Start coordinates not provided")
if not (-90 <= start[0] <= 90 or -180 <= start[1] <= 180):
raise HTTPException(status_code=422, detail="Start coordinates not in range")
logger.info(f"Requested new trip generation. Details:\n\tCoordinates: {start}\n\tTime: {preferences.max_time_minute}\n\tSightseeing: {preferences.sightseeing.score}\n\tNature: {preferences.nature.score}\n\tShopping: {preferences.shopping.score}")
start_time = time.time()
# Generate the landmarks from the start location
landmarks = manager.generate_landmarks_list(
center_coordinates = start,
preferences = preferences
)
if len(landmarks) == 0 :
raise HTTPException(status_code=500, detail="No landmarks were found.")
t_generate_landmarks = time.time() - start_time
logger.info(f'Fetched {len(landmarks)} landmarks in \t: {round(t_generate_landmarks,3)} seconds')
return landmarks
@router.post("/get-nearby/landmarks/{lat}/{lon}")
def get_landmarks_nearby(
lat: float,
lon: float
) -> list[Landmark] :
"""
Suggests nearby landmarks based on a given latitude and longitude.
This endpoint returns a curated list of up to 5 landmarks around the given geographical coordinates. It uses fixed preferences for
sightseeing, shopping, and nature, with a maximum time constraint of 30 minutes to limit the number of landmarks returned.
Args:
lat (float): Latitude of the user's current location.
lon (float): Longitude of the user's current location.
Returns:
list[Landmark]: A list of selected nearby landmarks.
"""
logger.info(f'Fetching landmarks nearby ({lat}, {lon}).')
# Define fixed preferences:
prefs = 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,
)
# Find the landmarks around the location
landmarks_around = manager.generate_landmarks_list(
center_coordinates = (lat, lon),
preferences = prefs,
allow_clusters=False,
)
if len(landmarks_around) == 0 :
raise HTTPException(status_code=500, detail="No landmarks were found.")
# select 8 - 12 landmarks from there
if len(landmarks_around) > 8 :
n_imp = random.randint(2,5)
rest = random.randint(8 - n_imp, min(12, len(landmarks_around))-n_imp)
print(f'len = {len(landmarks_around)}\nn_imp = {n_imp}\nrest = {rest}')
landmarks_around = landmarks_around[:n_imp] + random.sample(landmarks_around[n_imp:], rest)
logger.info(f'Found {len(landmarks_around)} landmarks to suggest nearby ({lat}, {lon}).')
# logger.debug('Suggested landmarks :\n\t' + '\n\t'.join(f'{landmark}' for landmark in landmarks_around))
return landmarks_around

View File

@@ -33,14 +33,14 @@ def configure_logging():
# silence the chatty logs loki generates itself # silence the chatty logs loki generates itself
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING) logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)
# no need for time since it's added by loki or can be shown in kube logs # no need for time since it's added by loki or can be shown in kube logs
logging_format = '%(name)s - %(levelname)s - %(message)s' logging_format = '%(name)-55s - %(levelname)-7s - %(message)s'
else: else:
# if we are in a debug (local) session, set verbose and rich logging # if we are in a debug (local) session, set verbose and rich logging
from rich.logging import RichHandler from rich.logging import RichHandler
logging_handlers = [RichHandler()] logging_handlers = [RichHandler()]
logging_level = logging.DEBUG if is_debug else logging.INFO logging_level = logging.DEBUG if is_debug else logging.INFO
logging_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' logging_format = '%(asctime)s - %(name)-55s - %(levelname)-7s - %(message)s'

View File

@@ -1,20 +1,18 @@
"""Main app for backend api""" """Main app for backend api"""
import logging import logging
import time
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, BackgroundTasks, Query from fastapi import FastAPI, HTTPException
from .logging_config import configure_logging from .logging_config import configure_logging
from .structs.landmark import Landmark, Toilets from .structs.landmark import Landmark
from .structs.preferences import Preferences
from .structs.linked_landmarks import LinkedLandmarks from .structs.linked_landmarks import LinkedLandmarks
from .structs.trip import Trip from .structs.trip import Trip
from .utils.landmarks_manager import LandmarkManager from .landmarks.landmarks_manager import LandmarkManager
from .utils.toilets_manager import ToiletsManager from .toilets.toilets_router import router as toilets_router
from .optimization.optimization_router import router as optimization_router
from .landmarks.landmarks_router import router as landmarks_router, get_landmarks_nearby
from .optimization.optimizer import Optimizer from .optimization.optimizer import Optimizer
from .optimization.refiner import Refiner from .optimization.refiner import Refiner
from .overpass.overpass import fill_cache
from .cache import client as cache_client from .cache import client as cache_client
@@ -37,108 +35,22 @@ async def lifespan(app: FastAPI):
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
@app.post("/trip/new")
def new_trip(preferences: Preferences,
start: tuple[float, float],
end: tuple[float, float] | None = None,
background_tasks: BackgroundTasks = None) -> Trip:
"""
Main function to call the optimizer.
Args: # Fetches the global list of landmarks given preferences and start/end coordinates. Two routes
preferences : the preferences specified by the user as the post body # Call with "/get/landmarks/" for main entry point of the trip generation pipeline.
start : the coordinates of the starting point # Call with "/get-nearby/landmarks/" for the NEARBY feature.
end : the coordinates of the finishing point app.include_router(landmarks_router)
Returns:
(uuid) : The uuid of the first landmark in the optimized route
"""
if preferences is None:
raise HTTPException(status_code=406, detail="Preferences not provided or incomplete.")
if (preferences.shopping.score == 0 and
preferences.sightseeing.score == 0 and
preferences.nature.score == 0) :
raise HTTPException(status_code=406, detail="All preferences are 0.")
if start is None:
raise HTTPException(status_code=406, detail="Start coordinates not provided")
if not (-90 <= start[0] <= 90 or -180 <= start[1] <= 180):
raise HTTPException(status_code=422, detail="Start coordinates not in range")
if end is None:
end = start
logger.info("No end coordinates provided. Using start=end.")
start_landmark = Landmark(name='start',
type='start',
location=(start[0], start[1]),
osm_type='start',
osm_id=0,
attractiveness=0,
duration=0,
must_do=True,
n_tags = 0)
end_landmark = Landmark(name='finish', # Optimizes the trip given preferences. Second step in the main trip generation pipeline
type='finish', # Call with "/optimize/trip"
location=(end[0], end[1]), app.include_router(optimization_router)
osm_type='end',
osm_id=0,
attractiveness=0,
duration=0,
must_do=True,
n_tags=0)
start_time = time.time()
# Generate the landmarks from the start location
landmarks, landmarks_short = manager.generate_landmarks_list(
center_coordinates = start,
preferences = preferences
)
if len(landmarks) == 0 : # Fetches toilets near given coordinates.
raise HTTPException(status_code=500, detail="No landmarks were found.") # Call with "/get/toilets" for fetching toilets around coordinates
app.include_router(toilets_router)
# insert start and finish to the landmarks list
landmarks_short.insert(0, start_landmark)
landmarks_short.append(end_landmark)
t_generate_landmarks = time.time() - start_time
logger.info(f'Fetched {len(landmarks)} landmarks in \t: {round(t_generate_landmarks,3)} seconds')
start_time = time.time()
# First stage optimization
try:
base_tour = optimizer.solve_optimization(preferences.max_time_minute, landmarks_short)
except Exception as exc:
raise HTTPException(status_code=500, detail=f"Optimization failed: {str(exc)}") from exc
t_first_stage = time.time() - start_time
start_time = time.time()
# Second stage optimization
# TODO : only if necessary (not enough landmarks for ex.)
try :
refined_tour = refiner.refine_optimization(landmarks, base_tour,
preferences.max_time_minute,
preferences.detour_tolerance_minute)
except TimeoutError as te :
logger.error(f'Refiner failed : {str(te)} Using base tour.')
refined_tour = base_tour
except Exception as exc :
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(exc)}") from exc
t_second_stage = time.time() - start_time
logger.debug(f'First stage optimization\t: {round(t_first_stage,3)} seconds')
logger.debug(f'Second stage optimization\t: {round(t_second_stage,3)} seconds')
logger.info(f'Total computation time\t: {round(t_first_stage + t_second_stage,3)} seconds')
linked_tour = LinkedLandmarks(refined_tour)
# 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.')
background_tasks.add_task(fill_cache)
return trip
#### For already existing trips/landmarks #### For already existing trips/landmarks
@@ -157,6 +69,7 @@ def get_trip(trip_uuid: str) -> Trip:
trip = cache_client.get(f"trip_{trip_uuid}") trip = cache_client.get(f"trip_{trip_uuid}")
return trip return trip
except KeyError as exc: except KeyError as exc:
logger.error(f"Failed to fetch trip with UUID {trip_uuid}: {str(exc)}")
raise HTTPException(status_code=404, detail="Trip not found") from exc raise HTTPException(status_code=404, detail="Trip not found") from exc
@@ -175,32 +88,46 @@ def get_landmark(landmark_uuid: str) -> Landmark:
landmark = cache_client.get(f"landmark_{landmark_uuid}") landmark = cache_client.get(f"landmark_{landmark_uuid}")
return landmark return landmark
except KeyError as exc: except KeyError as exc:
logger.error(f"Failed to fetch landmark with UUID {landmark_uuid}: {str(exc)}")
raise HTTPException(status_code=404, detail="Landmark not found") from exc raise HTTPException(status_code=404, detail="Landmark not found") from exc
@app.post("/toilets/new") @app.post("/trip/recompute-time/{trip_uuid}/{removed_landmark_uuid}")
def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -> list[Toilets] : def update_trip_time(trip_uuid: str, removed_landmark_uuid: str) -> Trip:
""" """
Endpoint to find toilets within a specified radius from a given location. Updates the reaching times of a given trip when removing a landmark.
This endpoint expects the `location` and `radius` as **query parameters**, not in the request body.
Args: Args:
location (tuple[float, float]): The latitude and longitude of the location to search from. landmark_uuid (str) : unique identifier for a Landmark.
radius (int, optional): The radius (in meters) within which to search for toilets. Defaults to 500 meters.
Returns: Returns:
list[Toilets]: A list of Toilets objects that meet the criteria. (Landmark) : the corresponding Landmark.
""" """
if location is None: # First, fetch the trip in the cache.
raise HTTPException(status_code=406, detail="Coordinates not provided or invalid") try:
if not (-90 <= location[0] <= 90 or -180 <= location[1] <= 180): trip = cache_client.get(f'trip_{trip_uuid}')
raise HTTPException(status_code=422, detail="Start coordinates not in range")
toilets_manager = ToiletsManager(location, radius)
try :
toilets_list = toilets_manager.generate_toilet_list()
return toilets_list
except KeyError as exc: except KeyError as exc:
raise HTTPException(status_code=404, detail="No toilets found") from exc logger.error(f"Failed to update trip with UUID {trip_uuid} (trip not found): {str(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:
logger.error(f"Failed to update trip with UUID {trip_uuid} : {str(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

View File

@@ -0,0 +1,141 @@
"""API entry point for the trip optimization."""
import logging
import time
import yaml
from fastapi import HTTPException, APIRouter, BackgroundTasks
from .optimizer import Optimizer
from .refiner import Refiner
from ..structs.landmark import Landmark
from ..structs.preferences import Preferences
from ..structs.linked_landmarks import LinkedLandmarks
from ..structs.trip import Trip
from ..overpass.overpass import fill_cache
from ..cache import client as cache_client
from ..constants import OPTIMIZER_PARAMETERS_PATH
# Setup the Logger, Optimizer and Refiner
logger = logging.getLogger(__name__)
optimizer = Optimizer()
refiner = Refiner(optimizer=optimizer)
# Initialize the API router
router = APIRouter()
@router.post("/optimize/trip")
def optimize_trip(
preferences: Preferences,
landmarks: list[Landmark],
start: tuple[float, float],
end: tuple[float, float] | None = None,
background_tasks: BackgroundTasks = None
) -> Trip:
"""
Main function to call the optimizer.
Args:
preferences (Preferences) : the preferences specified by the user as the post body.
start (tuple[float, float]) : the coordinates of the starting point.
end tuple[float, float] : the coordinates of the finishing point.
backgroud_tasks (BackgroundTasks) : necessary to fill the cache after the trip has been returned.
Returns:
(uuid) : The uuid of the first landmark in the optimized route
"""
if preferences is None:
raise HTTPException(status_code=406, detail="Preferences not provided or incomplete.")
if len(landmarks) == 0 :
raise HTTPException(status_code=406, detail="No landmarks provided for computing the trip.")
if (preferences.shopping.score == 0 and
preferences.sightseeing.score == 0 and
preferences.nature.score == 0) :
raise HTTPException(status_code=406, detail="All preferences are 0.")
if start is None:
raise HTTPException(status_code=406, detail="Start coordinates not provided")
if not (-90 <= start[0] <= 90 or -180 <= start[1] <= 180):
raise HTTPException(status_code=422, detail="Start coordinates not in range")
if end is None:
end = start
logger.info("No end coordinates provided. Using start=end.")
# Start the timer
start_time = time.time()
logger.info(f"Requested new trip generation. Details:\n\tCoordinates: {start}\n\tTime: {preferences.max_time_minute}\n\tSightseeing: {preferences.sightseeing.score}\n\tNature: {preferences.nature.score}\n\tShopping: {preferences.shopping.score}")
start_landmark = Landmark(
name='start',
type='start',
location=(start[0], start[1]),
osm_type='start',
osm_id=0,
attractiveness=0,
duration=0,
must_do=True,
n_tags = 0
)
end_landmark = Landmark(
name='finish',
type='finish',
location=(end[0], end[1]),
osm_type='end',
osm_id=0,
attractiveness=0,
duration=0,
must_do=True,
n_tags=0
)
# From the parameters load the length at which to truncate the landmarks list.
with OPTIMIZER_PARAMETERS_PATH.open('r') as f:
parameters = yaml.safe_load(f)
n_important = parameters['N_important']
# Truncate to the most important landmarks for a shorter list
landmarks_short = landmarks[:n_important]
# insert start and finish to the shorter landmarks list
landmarks_short.insert(0, start_landmark)
landmarks_short.append(end_landmark)
# First stage optimization
try:
base_tour = optimizer.solve_optimization(preferences.max_time_minute, landmarks_short)
except Exception as exc:
logger.error(f"Trip generation failed: {str(exc)}")
raise HTTPException(status_code=500, detail=f"Optimization failed: {str(exc)}") from exc
t_first_stage = time.time() - start_time
start_time = time.time()
# Second stage optimization
try :
refined_tour = refiner.refine_optimization(
landmarks, base_tour,
preferences.max_time_minute,
preferences.detour_tolerance_minute
)
except Exception as exc :
logger.warning(f"Refiner failed. Proceeding with base trip {str(exc)}")
refined_tour = base_tour
t_second_stage = time.time() - start_time
logger.debug(f'First stage optimization\t: {round(t_first_stage,3)} seconds')
logger.debug(f'Second stage optimization\t: {round(t_second_stage,3)} seconds')
logger.info(f'Total computation time\t: {round(t_first_stage + t_second_stage,3)} seconds')
linked_tour = LinkedLandmarks(refined_tour)
# 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'Optimized a trip of {trip.total_time} minutes with {len(refined_tour)} landmarks in {round(t_first_stage + t_second_stage,3)} seconds.')
logger.info('Detailed trip :\n\t' + '\n\t'.join(f'{landmark}' for landmark in refined_tour))
background_tasks.add_task(fill_cache)
return trip

View File

@@ -257,7 +257,6 @@ class Optimizer:
Returns: Returns:
None: This function modifies the `prob` object by adding L-2 equality constraints in-place. None: This function modifies the `prob` object by adding L-2 equality constraints in-place.
""" """
# FIXME: weird 0 artifact in the coefficients popping up
# Loop through rows 1 to L-2 to prevent stacked ones # Loop through rows 1 to L-2 to prevent stacked ones
for i in range(1, L-1): for i in range(1, L-1):
# Add the constraint that sums across each "row" or "block" in the decision variables # Add the constraint that sums across each "row" or "block" in the decision variables
@@ -590,15 +589,15 @@ class Optimizer:
try : try :
prob.solve(pl.PULP_CBC_CMD(msg=False, timeLimit=self.time_limit+1, gapRel=self.gap_rel)) prob.solve(pl.PULP_CBC_CMD(msg=False, timeLimit=self.time_limit+1, gapRel=self.gap_rel))
except Exception as exc : except Exception as exc :
raise Exception(f"No solution found: {exc}") from exc raise Exception(f"No solution found: {str(exc)}") from exc
status = pl.LpStatus[prob.status] status = pl.LpStatus[prob.status]
solution = [pl.value(var) for var in x] # The values of the decision variables (will be 0 or 1) solution = [pl.value(var) for var in x] # The values of the decision variables (will be 0 or 1)
self.logger.debug("First results are out. Looking out for circles and correcting.") self.logger.debug("First results are out. Looking out for circles and correcting...")
# Raise error if no solution is found. FIXME: for now this throws the internal server error # Raise error if no solution is found. FIXME: for now this throws the internal server error
if status != 'Optimal' : if status != 'Optimal' :
self.logger.error("The problem is overconstrained, no solution on first try.") self.logger.warning("The problem is overconstrained, no solution on first try.")
raise ArithmeticError("No solution could be found. Please try again with more time or different preferences.") raise ArithmeticError("No solution could be found. Please try again with more time or different preferences.")
# If there is a solution, we're good to go, just check for connectiveness # If there is a solution, we're good to go, just check for connectiveness
@@ -608,7 +607,7 @@ class Optimizer:
while circles is not None : while circles is not None :
i += 1 i += 1
if i == self.max_iter : if i == self.max_iter :
self.logger.error(f'Timeout: No solution found after {self.max_iter} iterations.') self.logger.warning(f'Timeout: No solution found after {self.max_iter} iterations.')
raise TimeoutError(f"Optimization took too long. No solution found after {self.max_iter} iterations.") raise TimeoutError(f"Optimization took too long. No solution found after {self.max_iter} iterations.")
for circle in circles : for circle in circles :
@@ -618,12 +617,13 @@ class Optimizer:
try : try :
prob.solve(pl.PULP_CBC_CMD(msg=False, timeLimit=self.time_limit, gapRel=self.gap_rel)) prob.solve(pl.PULP_CBC_CMD(msg=False, timeLimit=self.time_limit, gapRel=self.gap_rel))
except Exception as exc : except Exception as exc :
raise Exception(f"No solution found: {exc}") from exc self.logger.warning("No solution found: {str(exc)")
raise Exception(f"No solution found: {str(exc)}") from exc
solution = [pl.value(var) for var in x] solution = [pl.value(var) for var in x]
if pl.LpStatus[prob.status] != 'Optimal' : if pl.LpStatus[prob.status] != 'Optimal' :
self.logger.error("The problem is overconstrained, no solution after {i} cycles.") self.logger.warning("The problem is overconstrained, no solution after {i} cycles.")
raise ArithmeticError("No solution could be found. Please try again with more time or different preferences.") raise ArithmeticError("No solution could be found. Please try again with more time or different preferences.")
circles = self.is_connected(solution) circles = self.is_connected(solution)

View File

@@ -6,7 +6,6 @@ from shapely import buffer, LineString, Point, Polygon, MultiPoint, concave_hull
from ..structs.landmark import Landmark from ..structs.landmark import Landmark
from ..utils.get_time_distance import get_time from ..utils.get_time_distance import get_time
from ..utils.take_most_important import take_most_important
from .optimizer import Optimizer from .optimizer import Optimizer
from ..constants import OPTIMIZER_PARAMETERS_PATH from ..constants import OPTIMIZER_PARAMETERS_PATH
@@ -238,7 +237,7 @@ class Refiner :
if self.is_in_area(area, landmark.location) and landmark.name not in visited_names: if self.is_in_area(area, landmark.location) and landmark.name not in visited_names:
second_order_landmarks.append(landmark) second_order_landmarks.append(landmark)
return take_most_important(second_order_landmarks, int(self.max_landmarks_refiner*0.75)) return sorted(second_order_landmarks, key=lambda x: x.attractiveness, reverse=True)[:int(self.max_landmarks_refiner*0.75)]
# Try fix the shortest path using shapely # Try fix the shortest path using shapely
@@ -278,7 +277,7 @@ class Refiner :
better_tour_poly = concave_hull(MultiPoint(coords)) # Create concave hull with "core" of tour leaving out start and finish better_tour_poly = concave_hull(MultiPoint(coords)) # Create concave hull with "core" of tour leaving out start and finish
xs, ys = better_tour_poly.exterior.xy xs, ys = better_tour_poly.exterior.xy
""" """
ERROR HERE : FIXED : ERROR HERE :
Exception has occurred: AttributeError Exception has occurred: AttributeError
'LineString' object has no attribute 'exterior' 'LineString' object has no attribute 'exterior'
""" """
@@ -356,7 +355,7 @@ class Refiner :
# If unsuccessful optimization, use the base_tour. # If unsuccessful optimization, use the base_tour.
if new_tour is None: if new_tour is None:
self.logger.warning("No solution found for the refined tour. Returning the initial tour.") self.logger.warning("Refiner failed: No solution found during second stage optimization.")
new_tour = base_tour new_tour = base_tour
# If only one landmark, return it. # If only one landmark, return it.
@@ -369,6 +368,7 @@ class Refiner :
# Fix the tour using Polygons if the path looks weird. # Fix the tour using Polygons if the path looks weird.
# Conditions : circular trip and invalid polygon. # Conditions : circular trip and invalid polygon.
if base_tour[0].location == base_tour[-1].location and not better_poly.is_valid : if base_tour[0].location == base_tour[-1].location and not better_poly.is_valid :
self.logger.debug("Tours might be funky, attempting to correct with polygons")
better_tour = self.fix_using_polygon(better_tour) better_tour = self.fix_using_polygon(better_tour)
return better_tour return better_tour

View File

@@ -1,3 +1,4 @@
"""Module defining the handling of cache data from Overpass requests."""
import os import os
import json import json
import hashlib import hashlib
@@ -61,7 +62,7 @@ class JSONCache(CachingStrategyBase):
return None return None
def set(self, key, value): def set(self, key, value):
"""Save the JSON data as an ElementTree to the cache.""" """Save the JSON data in the cache."""
filename = self._filename(key) filename = self._filename(key)
try: try:
# Write the JSON data to the cache file # Write the JSON data to the cache file
@@ -94,7 +95,7 @@ class JSONCache(CachingStrategyBase):
def close(self): def close(self):
"""Cleanup method, if needed.""" """Cleanup method, if needed."""
pass
class CachingStrategy: class CachingStrategy:
""" """
@@ -107,6 +108,7 @@ class CachingStrategy:
@classmethod @classmethod
def use(cls, strategy_name='JSON', **kwargs): def use(cls, strategy_name='JSON', **kwargs):
"""Define the caching strategy to use."""
if cls.__strategy: if cls.__strategy:
cls.__strategy.close() cls.__strategy.close()
@@ -119,10 +121,12 @@ class CachingStrategy:
@classmethod @classmethod
def get(cls, key): def get(cls, key):
"""Get the data from the cache."""
return cls.__strategy.get(key) return cls.__strategy.get(key)
@classmethod @classmethod
def set(cls, key, value): def set(cls, key, value):
"""Save the data in the cache."""
cls.__strategy.set(key, value) cls.__strategy.set(key, value)
@classmethod @classmethod

View File

@@ -1,5 +1,6 @@
"""Module allowing connexion to overpass api and fectch data from OSM.""" """Module allowing connexion to overpass api and fectch data from OSM."""
import os import os
import time
import urllib import urllib
import math import math
import logging import logging
@@ -52,24 +53,24 @@ class Overpass :
# Retrieve cached data and identify missing cache entries # Retrieve cached data and identify missing cache entries
cached_responses, non_cached_cells = self._retrieve_cached_data(overlapping_cells, osm_types, selector, conditions, out) cached_responses, non_cached_cells = self._retrieve_cached_data(overlapping_cells, osm_types, selector, conditions, out)
self.logger.info(f'Cache hit for {len(overlapping_cells)-len(non_cached_cells)}/{len(overlapping_cells)} quadrants.') self.logger.debug(f'Cache hit for {len(overlapping_cells)-len(non_cached_cells)}/{len(overlapping_cells)} quadrants.')
# If there is no missing data, return the cached responses after filtering. # If there is no missing data, return the cached responses after filtering.
if not non_cached_cells : if not non_cached_cells :
return Overpass._filter_landmarks(cached_responses, bbox) return Overpass._filter_landmarks(cached_responses, bbox)
# If there is no cached data, fetch all from Overpass. # If there is no cached data, fetch all from Overpass.
elif not cached_responses : if not cached_responses :
query_str = Overpass.build_query(bbox, osm_types, selector, conditions, out) query_str = Overpass.build_query(bbox, osm_types, selector, conditions, out)
self.logger.debug(f'Query string: {query_str}')
return self.fetch_data_from_api(query_str) return self.fetch_data_from_api(query_str)
# Hybrid cache: some data from Overpass, some data from cache. # Resize the bbox for smaller search area and build new query string.
else : non_cached_bbox = Overpass._get_non_cached_bbox(non_cached_cells, bbox)
# Resize the bbox for smaller search area and build new query string. query_str = Overpass.build_query(non_cached_bbox, osm_types, selector, conditions, out)
non_cached_bbox = Overpass._get_non_cached_bbox(non_cached_cells, bbox) self.logger.debug(f'Query string: {query_str}')
query_str = Overpass.build_query(non_cached_bbox, osm_types, selector, conditions, out) non_cached_responses = self.fetch_data_from_api(query_str)
non_cached_responses = self.fetch_data_from_api(query_str) return Overpass._filter_landmarks(cached_responses, bbox) + non_cached_responses
return Overpass._filter_landmarks(cached_responses, bbox) + non_cached_responses
def fetch_data_from_api(self, query_str: str) -> List[dict]: def fetch_data_from_api(self, query_str: str) -> List[dict]:
@@ -94,9 +95,10 @@ class Overpass :
return elements return elements
except urllib.error.URLError as e: except urllib.error.URLError as e:
self.logger.error(f"Error connecting to Overpass API: {e}") self.logger.error(f"Error connecting to Overpass API: {str(e)}")
raise ConnectionError(f"Error connecting to Overpass API: {e}") from e raise ConnectionError(f"Error connecting to Overpass API: {str(e)}") from e
except Exception as exc : except Exception as exc :
self.logger.error(f"unexpected error while fetching data from Overpass: {str(exc)}")
raise Exception(f'An unexpected error occured: {str(exc)}') from exc raise Exception(f'An unexpected error occured: {str(exc)}') from exc
@@ -112,7 +114,7 @@ class Overpass :
with urllib.request.urlopen(request) as response: with urllib.request.urlopen(request) as response:
# Convert the HTTPResponse to a string and load data # Convert the HTTPResponse to a string and load data
response_data = response.read().decode('utf-8') response_data = response.read().decode('utf-8')
data = json.loads(response_data) data = json.loads(response_data)
# Get elements and set cache # Get elements and set cache
@@ -120,7 +122,7 @@ class Overpass :
self.caching_strategy.set(cache_key, elements) self.caching_strategy.set(cache_key, elements)
self.logger.debug(f'Cache set for {cache_key}') self.logger.debug(f'Cache set for {cache_key}')
except urllib.error.URLError as e: except urllib.error.URLError as e:
raise ConnectionError(f"Error connecting to Overpass API: {e}") from e raise ConnectionError(f"Error connecting to Overpass API: {str(e)}") from e
except Exception as exc : except Exception as exc :
raise Exception(f'An unexpected error occured: {str(exc)}') from exc raise Exception(f'An unexpected error occured: {str(exc)}') from exc
@@ -151,7 +153,7 @@ class Overpass :
- If no conditions are provided, the query will just use the `selector` to filter the OSM - If no conditions are provided, the query will just use the `selector` to filter the OSM
elements without additional constraints. elements without additional constraints.
""" """
query = '[out:json];(' query = '[out:json][timeout:20];('
# convert the bbox to string. # convert the bbox to string.
bbox_str = f"({','.join(map(str, bbox))})" bbox_str = f"({','.join(map(str, bbox))})"
@@ -307,9 +309,9 @@ class Overpass :
if min_lat == float('inf') or min_lon == float('inf'): if min_lat == float('inf') or min_lon == float('inf'):
return None return None
return (max(min_lat, original_bbox[0]), return (max(min_lat, original_bbox[0]),
max(min_lon, original_bbox[1]), max(min_lon, original_bbox[1]),
min(max_lat, original_bbox[2]), min(max_lat, original_bbox[2]),
min(max_lon, original_bbox[3])) min(max_lon, original_bbox[3]))
@@ -386,8 +388,8 @@ def get_base_info(elem: dict, osm_type: OSM_TYPES, with_name=False) :
if with_name : if with_name :
name = elem.get('tags', {}).get('name') name = elem.get('tags', {}).get('name')
return osm_id, coords, name return osm_id, coords, name
else :
return osm_id, coords return osm_id, coords
def fill_cache(): def fill_cache():
@@ -397,18 +399,27 @@ def fill_cache():
""" """
overpass = Overpass() overpass = Overpass()
n_files = 0
total = 0
overpass.logger.info('Trip successfully returned, starting to fill cache.')
with os.scandir(OSM_CACHE_DIR) as it: with os.scandir(OSM_CACHE_DIR) as it:
for entry in it: for entry in it:
if entry.is_file() and entry.name.startswith('hollow_'): if entry.is_file() and entry.name.startswith('hollow_'):
total += 1
try : try :
# Read the whole file content as a string # Read the whole file content as a string
with open(entry.path, 'r') as f: with open(entry.path, 'r', encoding='utf-8') as f:
# load data and fill the cache with the query and key # load data and fill the cache with the query and key
json_data = json.load(f) json_data = json.load(f)
overpass.fill_cache(json_data) overpass.fill_cache(json_data)
n_files += 1
time.sleep(1)
# Now delete the file as the cache is filled # Now delete the file as the cache is filled
os.remove(entry.path) os.remove(entry.path)
except Exception as exc : except Exception as exc :
overpass.logger.error(f'An error occured while parsing file {entry.path} as .json file') overpass.logger.error(f'An error occured while parsing file {entry.path} as .json file: {str(exc)}')
overpass.logger.info(f"Successfully filled {n_files}/{total} cache files.")

View File

@@ -72,6 +72,7 @@ sightseeing:
# - castle # - castle
# - museum # - museum
museums: museums:
tourism: tourism:
- museum - museum

View File

@@ -1,12 +1,10 @@
max_bbox_side: 4000 #m max_bbox_side: 4000 #m
radius_close_to: 50 radius_close_to: 50
church_coeff: 0.55 church_coeff: 0.75
nature_coeff: 1.4 nature_coeff: 1.6
overall_coeff: 10 overall_coeff: 10
tag_exponent: 1.15 tag_exponent: 1.15
image_bonus: 1.1 image_bonus: 1.1
viewpoint_bonus: 5 viewpoint_bonus: 10
wikipedia_bonus: 1.25 wikipedia_bonus: 1.25
name_bonus: 3
N_important: 60
pay_bonus: -1 pay_bonus: -1

View File

@@ -5,5 +5,6 @@ max_landmarks: 10
max_landmarks_refiner: 20 max_landmarks_refiner: 20
overshoot: 0.0016 overshoot: 0.0016
time_limit: 1 time_limit: 1
gap_rel: 0.05 gap_rel: 0.025
max_iter: 40 max_iter: 80
N_important: 60

View File

@@ -1,8 +1,7 @@
"""Definition of the Landmark class to handle visitable objects across the world.""" """Definition of the Landmark class to handle visitable objects across the world."""
from typing import Optional, Literal from typing import Optional, Literal
from uuid import uuid4, UUID from uuid import uuid4, UUID
from pydantic import BaseModel, ConfigDict, Field from pydantic import BaseModel, Field
# Output to frontend # Output to frontend
@@ -50,7 +49,8 @@ class Landmark(BaseModel) :
image_url : Optional[str] = None image_url : Optional[str] = None
website_url : Optional[str] = None website_url : Optional[str] = None
wiki_url : Optional[str] = None wiki_url : Optional[str] = None
description : Optional[str] = None # TODO future # keywords: Optional[dict] = {}
# description : Optional[str] = None
duration : Optional[int] = 5 duration : Optional[int] = 5
name_en : Optional[str] = None name_en : Optional[str] = None
@@ -69,6 +69,7 @@ class Landmark(BaseModel) :
is_viewpoint : Optional[bool] = False is_viewpoint : Optional[bool] = False
is_place_of_worship : Optional[bool] = False is_place_of_worship : Optional[bool] = False
def __str__(self) -> str: def __str__(self) -> str:
""" """
String representation of the Landmark object. String representation of the Landmark object.
@@ -122,26 +123,3 @@ class Landmark(BaseModel) :
return (self.uuid == value.uuid or return (self.uuid == value.uuid or
self.osm_id == value.osm_id or self.osm_id == value.osm_id or
(self.name == value.name and self.distance(value) < 0.001)) (self.name == value.name and self.distance(value) < 0.001))
class Toilets(BaseModel) :
"""
Model for toilets. When false/empty the information is either false either not known.
"""
location : tuple
wheelchair : Optional[bool] = False
changing_table : Optional[bool] = False
fee : Optional[bool] = False
opening_hours : Optional[str] = ""
def __str__(self) -> str:
"""
String representation of the Toilets object.
Returns:
str: A formatted string with the toilets location.
"""
return f'Toilets @{self.location}'
model_config = ConfigDict(from_attributes=True)

View File

@@ -2,6 +2,7 @@
from .landmark import Landmark from .landmark import Landmark
from ..utils.get_time_distance import get_time from ..utils.get_time_distance import get_time
from ..utils.description import description_and_keywords
class LinkedLandmarks: class LinkedLandmarks:
""" """
@@ -35,18 +36,23 @@ class LinkedLandmarks:
Create the links between the landmarks in the list by setting their Create the links between the landmarks in the list by setting their
.next_uuid and the .time_to_next attributes. .next_uuid and the .time_to_next attributes.
""" """
# Mark secondary landmarks as such # Mark secondary landmarks as such
self.update_secondary_landmarks() self.update_secondary_landmarks()
for i, landmark in enumerate(self._landmarks[:-1]): for i, landmark in enumerate(self._landmarks[:-1]):
# Set uuid of the next landmark
landmark.next_uuid = self._landmarks[i + 1].uuid landmark.next_uuid = self._landmarks[i + 1].uuid
# Adjust time to reach and total time
time_to_next = get_time(landmark.location, self._landmarks[i + 1].location) time_to_next = get_time(landmark.location, self._landmarks[i + 1].location)
landmark.time_to_reach_next = time_to_next landmark.time_to_reach_next = time_to_next
self.total_time += time_to_next self.total_time += time_to_next
self.total_time += landmark.duration self.total_time += landmark.duration
# Fill in the keywords and description. GOOD IDEA, BAD EXECUTION, tags aren't available anymore at this stage
# landmark.description, landmark.keywords = description_and_keywords(tags)
self._landmarks[-1].next_uuid = None self._landmarks[-1].next_uuid = None
self._landmarks[-1].time_to_reach_next = 0 self._landmarks[-1].time_to_reach_next = 0

View File

@@ -1,7 +1,7 @@
"""Defines the Preferences used as input for trip generation.""" """Defines the Preferences used as input for trip generation."""
from typing import Optional, Literal from typing import Optional, Literal
from pydantic import BaseModel from pydantic import BaseModel, field_validator
class Preference(BaseModel) : class Preference(BaseModel) :
@@ -15,6 +15,13 @@ class Preference(BaseModel) :
type: Literal['sightseeing', 'nature', 'shopping', 'start', 'finish'] type: Literal['sightseeing', 'nature', 'shopping', 'start', 'finish']
score: int # score could be from 1 to 5 score: int # score could be from 1 to 5
@field_validator("type")
@classmethod
def validate_type(cls, v):
if v not in {'sightseeing', 'nature', 'shopping', 'start', 'finish'}:
raise ValueError(f"Invalid type: {v}")
return v
# Input for optimization # Input for optimization
class Preferences(BaseModel) : class Preferences(BaseModel) :

View File

@@ -0,0 +1,26 @@
"""Definition of the Toilets class."""
from typing import Optional
from pydantic import BaseModel, ConfigDict
class Toilets(BaseModel) :
"""
Model for toilets. When false/empty the information is either false either not known.
"""
location : tuple
wheelchair : Optional[bool] = False
changing_table : Optional[bool] = False
fee : Optional[bool] = False
opening_hours : Optional[str] = ""
def __str__(self) -> str:
"""
String representation of the Toilets object.
Returns:
str: A formatted string with the toilets location.
"""
return f'Toilets @{self.location}'
model_config = ConfigDict(from_attributes=True)

View File

@@ -19,30 +19,50 @@ def invalid_client():
([48.8566, 2.3522], {}, 422), ([48.8566, 2.3522], {}, 422),
# Invalid cases: incomplete preferences. # Invalid cases: incomplete preferences.
([48.084588, 7.280405], {"sightseeing": {"type": "nature", "score": 5}, # no shopping ([48.084588, 7.280405], {"sightseeing": {"type": "sightseeing", "score": 5}, # no shopping pref
"nature": {"type": "nature", "score": 5}, "nature": {"type": "nature", "score": 5},
}, 422), }, 422),
([48.084588, 7.280405], {"sightseeing": {"type": "nature", "score": 5}, # no nature ([48.084588, 7.280405], {"sightseeing": {"type": "sightseeing", "score": 5}, # no nature pref
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
([48.084588, 7.280405], {"nature": {"type": "nature", "score": 5}, # no sightseeing ([48.084588, 7.280405], {"nature": {"type": "nature", "score": 5}, # no sightseeing pref
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
([48.084588, 7.280405], {"sightseeing": {"type": "nature", "score": 1}, # mixed up preferences types. TODO: i suggest reducing the complexity by remove the Preference object.
"nature": {"type": "shopping", "score": 1},
"shopping": {"type": "shopping", "score": 1},
}, 422),
([48.084588, 7.280405], {"doesnotexist": {"type": "sightseeing", "score": 2}, # non-existing preferences types
"nature": {"type": "nature", "score": 2},
"shopping": {"type": "shopping", "score": 2},
}, 422),
([48.084588, 7.280405], {"sightseeing": {"type": "sightseeing", "score": 3}, # non-existing preferences types
"nature": {"type": "doesntexisteither", "score": 3},
"shopping": {"type": "shopping", "score": 3},
}, 422),
([48.084588, 7.280405], {"sightseeing": {"type": "sightseeing", "score": -1}, # negative preference value
"nature": {"type": "doesntexisteither", "score": 4},
"shopping": {"type": "shopping", "score": 4},
}, 422),
([48.084588, 7.280405], {"sightseeing": {"type": "sightseeing", "score": 10}, # too high preference value
"nature": {"type": "doesntexisteither", "score": 4},
"shopping": {"type": "shopping", "score": 4},
}, 422),
# Invalid cases: unexisting coords # Invalid cases: unexisting coords
([91, 181], {"sightseeing": {"type": "nature", "score": 5}, ([91, 181], {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5}, "nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
([-91, 181], {"sightseeing": {"type": "nature", "score": 5}, ([-91, 181], {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5}, "nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
([91, -181], {"sightseeing": {"type": "nature", "score": 5}, ([91, -181], {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5}, "nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
([-91, -181], {"sightseeing": {"type": "nature", "score": 5}, ([-91, -181], {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5}, "nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5}, "shopping": {"type": "shopping", "score": 5},
}, 422), }, 422),
@@ -53,8 +73,8 @@ def test_input(invalid_client, start, preferences, status_code): # pylint: dis
Test new trip creation with different sets of preferences and locations. Test new trip creation with different sets of preferences and locations.
""" """
response = invalid_client.post( response = invalid_client.post(
"/trip/new", "/get/landmarks",
json={ json ={
"preferences": preferences, "preferences": preferences,
"start": start "start": start
} }

View File

@@ -1,345 +0,0 @@
"""Collection of tests to ensure correct implementation and track progress. """
import time
from fastapi.testclient import TestClient
import pytest
from .test_utils import load_trip_landmarks, log_trip_details
from ..main import app
@pytest.fixture(scope="module")
def client():
"""Client used to call the app."""
return TestClient(app)
def test_turckheim(client, request): # pylint: disable=redefined-outer-name
"""
Test n°1 : Custom test in Turckheim to ensure small villages are also supported.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 20
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 0},
"shopping": {"type": "shopping", "score": 0},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
# "start": [48.084588, 7.280405]
# "start": [45.74445023349939, 4.8222687890538865]
"start": [45.75156398104873, 4.827154464827647]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert isinstance(landmarks, list) # check that the return type is a list
assert len(landmarks) > 2 # check that there is something to visit
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
# assert 2!= 3
def test_bellecour(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°2 : Custom test in Lyon centre to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 120
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [45.7576485, 4.8330241]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_cologne(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°3 : Custom test in Cologne to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 240
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [50.942352665, 6.957777972392]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_strasbourg(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°4 : Custom test in Strasbourg to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 180
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [48.5846589226, 7.74078715721]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_zurich(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°5 : Custom test in Zurich to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 180
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [47.377884227, 8.5395114066]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_paris(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°6 : Custom test in Paris (les Halles) centre to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 200
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 0},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [48.85468881798671, 2.3423925755998374]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_new_york(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°7 : Custom test in New York to ensure proper decision making in crowded area.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 600
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 5},
"nature": {"type": "nature", "score": 5},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [40.72592726802, -73.9920434795]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"
def test_shopping(client, request) : # pylint: disable=redefined-outer-name
"""
Test n°8 : Custom test in Lyon centre to ensure shopping clusters are found.
Args:
client:
request:
"""
start_time = time.time() # Start timer
duration_minutes = 240
response = client.post(
"/trip/new",
json={
"preferences": {"sightseeing": {"type": "sightseeing", "score": 0},
"nature": {"type": "nature", "score": 0},
"shopping": {"type": "shopping", "score": 5},
"max_time_minute": duration_minutes,
"detour_tolerance_minute": 0},
"start": [45.7576485, 4.8330241]
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], duration_minutes)
# for elem in landmarks :
# print(elem)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert duration_minutes*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {duration_minutes}"
assert duration_minutes*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {duration_minutes}"

View File

@@ -0,0 +1,46 @@
"""Collection of tests to ensure correct implementation and track progress of the get_landmarks_nearby feature. """
from fastapi.testclient import TestClient
import pytest
from ..main import app
@pytest.fixture(scope="module")
def client():
"""Client used to call the app."""
return TestClient(app)
@pytest.mark.parametrize(
"location,status_code",
[
([45.7576485, 4.8330241], 200), # Lyon, France
([41.4020572, 2.1818985], 200), # Barcelona, Spain
([59.3293, 18.0686], 200), # Stockholm, Sweden
([43.6532, -79.3832], 200), # Toronto, Canada
([38.7223, -9.1393], 200), # Lisbon, Portugal
([6.5244, 3.3792], 200), # Lagos, Nigeria
([17.3850, 78.4867], 200), # Hyderabad, India
([30.0444, 31.2357], 200), # Cairo, Egypt
([50.8503, 4.3517], 200), # Brussels, Belgium
([35.2271, -80.8431], 200), # Charlotte, USA
([10.4806, -66.9036], 200), # Caracas, Venezuela
([9.51074, -13.71118], 200), # Conakry, Guinea
]
)
def test_nearby(client, location, status_code): # pylint: disable=redefined-outer-name
"""
Test n°1 : Verify handling of invalid input.
Args:
client:
request:
"""
response = client.post(f"/get-nearby/landmarks/{location[0]}/{location[1]}")
suggestions = response.json()
# checks :
assert response.status_code == status_code # check for successful planning
assert isinstance(suggestions, list) # check that the return type is a list
assert len(suggestions) > 0

View File

@@ -3,7 +3,7 @@
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
import pytest import pytest
from ..structs.landmark import Toilets from ..structs.toilets import Toilets
from ..main import app from ..main import app
@@ -18,7 +18,7 @@ def client():
[ [
({}, None, 422), # Invalid case: no location at all. ({}, None, 422), # Invalid case: no location at all.
([443], None, 422), # Invalid cases: invalid location. ([443], None, 422), # Invalid cases: invalid location.
([443, 433], None, 422), # Invalid cases: invalid location. ([443, 433], None, 422), # Invalid cases: invalid location.
] ]
) )
def test_invalid_input(client, location, radius, status_code): # pylint: disable=redefined-outer-name def test_invalid_input(client, location, radius, status_code): # pylint: disable=redefined-outer-name
@@ -30,12 +30,13 @@ def test_invalid_input(client, location, radius, status_code): # pylint: disa
request: request:
""" """
response = client.post( response = client.post(
"/toilets/new", "/get/toilets",
params={ params={
"location": location, "location": location,
"radius": radius "radius": radius
} }
) )
print(response.json())
# checks : # checks :
assert response.status_code == status_code assert response.status_code == status_code
@@ -58,11 +59,12 @@ def test_no_toilets(client, location, status_code): # pylint: disable=redefin
request: request:
""" """
response = client.post( response = client.post(
"/toilets/new", "/get/toilets",
params={ params={
"location": location "location": location
} }
) )
print(response.json())
toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()] toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()]
# checks : # checks :
@@ -87,12 +89,14 @@ def test_toilets(client, location, status_code): # pylint: disable=redefined-
request: request:
""" """
response = client.post( response = client.post(
"/toilets/new", "/get/toilets",
params={ params={
"location": location, "location": location,
"radius" : 600 "radius" : 600
} }
) )
print(response.json())
toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()] toilets_list = [Toilets.model_validate(toilet) for toilet in response.json()]
# checks : # checks :

View File

@@ -0,0 +1,81 @@
"""Collection of tests to ensure correct implementation and track progress."""
import time
from fastapi.testclient import TestClient
import pytest
from .test_utils import load_trip_landmarks, log_trip_details
from ..structs.preferences import Preferences, Preference
from ..main import app
@pytest.fixture(scope="module")
def client():
"""Client used to call the app."""
return TestClient(app)
@pytest.mark.parametrize(
"sightseeing, shopping, nature, max_time_minute, start_coords, end_coords",
[
# Edge cases
(0, 0, 5, 240, [45.7576485, 4.8330241], None), # Lyon, Bellecour - test shopping only
# Realistic
(5, 0, 0, 20, [48.0845881, 7.2804050], None), # Turckheim
(5, 5, 5, 120, [45.7576485, 4.8330241], None), # Lyon, Bellecour
(5, 2, 5, 240, [50.9423526, 6.9577780], None), # Cologne, centre
(3, 5, 0, 180, [48.5846589226, 7.74078715721], None), # Strasbourg, centre
(2, 4, 5, 180, [47.377884227, 8.5395114066], None), # Zurich, centre
(5, 0, 5, 200, [48.85468881798671, 2.3423925755998374], None), # Paris, centre
(5, 5, 5, 600, [40.72592726802, -73.9920434795], None), # New York, Lower Manhattan
]
)
def test_trip(client, request, sightseeing, shopping, nature, max_time_minute, start_coords, end_coords):
start_time = time.time() # Start timer
prefs = Preferences(
sightseeing=Preference(type='sightseeing', score=sightseeing),
shopping=Preference(type='shopping', score=shopping),
nature=Preference(type='nature', score=nature),
max_time_minute=max_time_minute,
detour_tolerance_minute=0,
)
start = start_coords
end = end_coords
# Step 1: request the list of landmarks in the vicinty of the starting point
response = client.post(
"/get/landmarks",
json={
"preferences": prefs.model_dump(),
"start": start_coords,
"end": end_coords,
}
)
landmarks = response.json()
# Step 2: Feed the landmarks to the optimizer to compute the trip
response = client.post(
"/optimize/trip",
json={
"preferences": prefs.model_dump(),
"landmarks": landmarks,
"start": start,
"end": end,
}
)
result = response.json()
landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])
# Get computation time
comp_time = time.time() - start_time
# Add details to report
log_trip_details(request, landmarks, result['total_time'], prefs.max_time_minute)
# checks :
assert response.status_code == 200 # check for successful planning
assert comp_time < 30, f"Computation time exceeded 30 seconds: {comp_time:.2f} seconds"
assert prefs.max_time_minute*0.8 < result['total_time'], f"Trip too short: {result['total_time']} instead of {prefs.max_time_minute}"
assert prefs.max_time_minute*1.2 > result['total_time'], f"Trip too long: {result['total_time']} instead of {prefs.max_time_minute}"

View File

@@ -1,10 +1,12 @@
"""Helper methods for testing.""" """Helper methods for testing."""
import time
import logging import logging
from functools import wraps
from fastapi import HTTPException from fastapi import HTTPException
from pydantic import ValidationError
from ..structs.landmark import Landmark
from ..cache import client as cache_client from ..cache import client as cache_client
from ..structs.landmark import Landmark
from ..structs.preferences import Preferences, Preference
def landmarks_to_osmid(landmarks: list[Landmark]) -> list[int] : def landmarks_to_osmid(landmarks: list[Landmark]) -> list[int] :
@@ -39,7 +41,7 @@ def fetch_landmark(landmark_uuid: str):
try: try:
landmark = cache_client.get(f'landmark_{landmark_uuid}') landmark = cache_client.get(f'landmark_{landmark_uuid}')
if not landmark : if not landmark :
logger.warning(f'Cache miss for landmark UUID: {landmark_uuid}') logger.error(f'Cache miss for landmark UUID: {landmark_uuid}')
raise HTTPException(status_code=404, detail=f'Landmark with UUID {landmark_uuid} not found in cache.') raise HTTPException(status_code=404, detail=f'Landmark with UUID {landmark_uuid} not found in cache.')
# Validate that the fetched data is a dictionary # Validate that the fetched data is a dictionary
@@ -92,3 +94,34 @@ def log_trip_details(request, landmarks: list[Landmark], duration: int, target_d
request.node.trip_details = trip_string request.node.trip_details = trip_string
request.node.trip_duration = str(duration) # result['total_time'] request.node.trip_duration = str(duration) # result['total_time']
request.node.target_duration = str(target_duration) request.node.target_duration = str(target_duration)
def trip_params(
sightseeing: int,
shopping: int,
nature: int,
max_time_minute: int,
start_coords: tuple[float, float] = None,
end_coords: tuple[float, float] = None,
):
def decorator(test_func):
@wraps(test_func)
def wrapper(client, request):
prefs = Preferences(
sightseeing=Preference(type='sightseeing', score=sightseeing),
shopping=Preference(type='shopping', score=shopping),
nature=Preference(type='nature', score=nature),
max_time_minute=max_time_minute,
detour_tolerance_minute=0,
)
start = start_coords
end = end_coords
# Inject into test function
return test_func(client, request, prefs, start, end)
return wrapper
return decorator

View File

View File

@@ -2,8 +2,8 @@
import logging import logging
from ..overpass.overpass import Overpass, get_base_info from ..overpass.overpass import Overpass, get_base_info
from ..structs.landmark import Toilets from ..structs.toilets import Toilets
from .utils import create_bbox from ..utils.bbox import create_bbox
# silence the overpass logger # silence the overpass logger
@@ -65,7 +65,7 @@ class ToiletsManager:
try: try:
result = self.overpass.fetch_data_from_api(query_str=query) result = self.overpass.fetch_data_from_api(query_str=query)
except Exception as e: except Exception as e:
self.logger.error(f"Error fetching landmarks: {e}") self.logger.error(f"Error fetching toilets: {e}")
return None return None
toilets_list = self.to_toilets(result) toilets_list = self.to_toilets(result)

View File

@@ -0,0 +1,42 @@
"""API entry point for fetching toilet locations."""
from fastapi import HTTPException, APIRouter, Query
from .toilets_manager import ToiletsManager
from ..structs.toilets import Toilets
# Initialize the API router
router = APIRouter()
@router.post("/get/toilets")
def get_toilets(
location: tuple[float, float] = Query(...),
radius: int = 500
) -> list[Toilets] :
"""
Endpoint to find toilets within a specified radius from a given location.
This endpoint expects the `location` and `radius` as **query parameters**, not in the request body.
Args:
location (tuple[float, float]): The latitude and longitude of the location to search from.
radius (int, optional): The radius (in meters) within which to search for toilets. Defaults to 500 meters.
Returns:
list[Toilets]: A list of Toilets objects that meet the criteria.
"""
if location is None:
raise HTTPException(status_code=406, detail="Coordinates not provided or invalid")
if not (-90 <= location[0] <= 90 or -180 <= location[1] <= 180):
raise HTTPException(status_code=422, detail="Start coordinates not in range")
toilets_manager = ToiletsManager(location, radius)
try :
toilets_list = toilets_manager.generate_toilet_list()
except KeyError as exc:
raise HTTPException(status_code=404, detail="No toilets found") from exc
return toilets_list

View File

@@ -24,4 +24,4 @@ def create_bbox(coords: tuple[float, float], radius: int):
lon_min = lon - d_lon * 180 / m.pi lon_min = lon - d_lon * 180 / m.pi
lon_max = lon + d_lon * 180 / m.pi lon_max = lon + d_lon * 180 / m.pi
return (lat_min, lon_min, lat_max, lon_max) return (lat_min, lon_min, lat_max, lon_max)

View File

@@ -0,0 +1,123 @@
"""Add more information about the landmarks by writing a short description and keywords. """
def description_and_keywords(tags: dict):
"""
Generates a description and a set of keywords for a given landmark based on its tags.
Params:
tags (dict): A dictionary containing metadata about the landmark, including its name,
importance, height, date of construction, and visitor information.
Returns:
description (str): A string description of the landmark.
keywords (dict): A dictionary of keywords with fields such as 'importance', 'height',
'place_type', and 'date'.
"""
# Extract relevant fields
name = tags.get('name')
importance = tags.get('importance', None)
n_visitors = tags.get('tourism:visitors', None)
height = tags.get('height')
place_type = get_place_type(tags)
date = get_date(tags)
if place_type is None :
return None, None
# Start the description.
if importance is None :
if len(tags.keys()) < 5 :
return None, None
if len(tags.keys()) < 10 :
description = f"{name} is a well known {place_type}."
elif len(tags.keys()) < 17 :
importance = 'national'
description = f"{name} is a {place_type} of national importance."
else :
importance = 'international'
description = f"{name} is an internationally famous {place_type}."
else :
description = f"{name} is a {place_type} of {importance} importance."
if height is not None and date is not None :
description += f" This {place_type} was constructed in {date} and is ca. {height} meters high."
elif height is not None :
description += f" This {place_type} stands ca. {height} meters tall."
elif date is not None:
description += f" It was constructed in {date}."
# Format the visitor number
if n_visitors is not None :
n_visitors = int(n_visitors)
if n_visitors < 1000000 :
description += f" It welcomes {int(n_visitors/1000)} thousand visitors every year."
else :
description += f" It welcomes {round(n_visitors/1000000, 1)} million visitors every year."
# Set the keywords.
keywords = {"importance": importance,
"height": height,
"place_type": place_type,
"date": date}
return description, keywords
def get_place_type(tags):
"""
Determines the type of the place based on available tags such as 'amenity', 'building',
'historic', and 'leisure'. The priority order is: 'historic' > 'building' (if not generic) >
'amenity' > 'leisure'.
Params:
tags (dict): A dictionary containing metadata about the place.
Returns:
place_type (str): The determined type of the place, or None if no relevant type is found.
"""
amenity = tags.get('amenity', None)
building = tags.get('building', None)
historic = tags.get('historic', None)
leisure = tags.get('leisure')
if historic and historic != "yes":
return historic
if building and building not in ["yes", "civic", "government", "apartments", "residential", "commericial", "industrial", "retail", "religious", "public", "service"]:
return building
if amenity:
return amenity
if leisure:
return leisure
return None
def get_date(tags):
"""
Extracts the most relevant date from the available tags, prioritizing 'construction_date',
'start_date', 'year_of_construction', and 'opening_date' in that order.
Params:
tags (dict): A dictionary containing metadata about the place.
Returns:
date (str): The most relevant date found, or None if no date is available.
"""
construction_date = tags.get('construction_date', None)
opening_date = tags.get('opening_date', None)
start_date = tags.get('start_date', None)
year_of_construction = tags.get('year_of_construction', None)
# Prioritize based on availability
if construction_date:
return construction_date
if start_date:
return start_date
if year_of_construction:
return year_of_construction
if opening_date:
return opening_date
return None

View File

@@ -1,17 +0,0 @@
"""Helper function to return only the major landmarks from a large list."""
from ..structs.landmark import Landmark
def take_most_important(landmarks: list[Landmark], n_important) -> list[Landmark]:
"""
Given a list of landmarks, return the n_important most important landmarks
Args:
landmarks: list[Landmark] - list of landmarks
n_important: int - number of most important landmarks to return
Returns:
list[Landmark] - list of the n_important most important landmarks
"""
# Sort landmarks by attractiveness (descending)
sorted_landmarks = sorted(landmarks, key=lambda x: x.attractiveness, reverse=True)
return sorted_landmarks[:n_important]

1330
backend/uv.lock generated Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -1,10 +1,12 @@
import 'package:anyway/utils/get_first_page.dart';
import 'package:anyway/utils/load_trips.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:anyway/constants.dart'; import 'package:anyway/constants.dart';
import 'package:anyway/layout.dart';
void main() => runApp(const App()); void main() => runApp(const App());
final GlobalKey<ScaffoldMessengerState> rootScaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>(); final GlobalKey<ScaffoldMessengerState> rootScaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
final SavedTrips savedTrips = SavedTrips();
class App extends StatelessWidget { class App extends StatelessWidget {
const App({super.key}); const App({super.key});
@@ -14,7 +16,7 @@ class App extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: APP_NAME, title: APP_NAME,
home: BasePage(mainScreen: "map"), home: getFirstPage(),
theme: APP_THEME, theme: APP_THEME,
scaffoldMessengerKey: rootScaffoldMessengerKey scaffoldMessengerKey: rootScaffoldMessengerKey
); );

View File

@@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:anyway/modules/landmark_card.dart'; import 'package:anyway/modules/landmark_card.dart';
import 'package:anyway/structs/landmark.dart'; import 'package:anyway/structs/landmark.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:anyway/main.dart';
@@ -25,30 +24,7 @@ List<Widget> landmarksList(Trip trip) {
for (Landmark landmark in trip.landmarks) { for (Landmark landmark in trip.landmarks) {
children.add( children.add(
Dismissible( LandmarkCard(landmark, trip),
key: ValueKey<int>(landmark.hashCode),
child: LandmarkCard(landmark),
dismissThresholds: {DismissDirection.endToStart: 0.95, DismissDirection.startToEnd: 0.95},
onDismissed: (direction) {
log('Removing ${landmark.name}');
trip.removeLandmark(landmark);
rootScaffoldMessengerKey.currentState!.showSnackBar(
SnackBar(content: Text("We won't show ${landmark.name} again"))
);
},
background: Container(color: Colors.red),
secondaryBackground: Container(
color: Colors.red,
child: Icon(
Icons.delete,
color: Colors.white,
),
padding: EdgeInsets.all(15),
alignment: Alignment.centerRight,
),
)
); );
if (landmark.next != null) { if (landmark.next != null) {

View File

@@ -1,9 +1,20 @@
import 'package:anyway/constants.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:anyway/pages/current_trip.dart'; import 'package:anyway/pages/current_trip.dart';
final List<String> statusTexts = [
'Parsing your preferences...',
'Finding the best places...',
'Crunching the numbers...',
'Calculating the best route...',
'Making sure you have a great time...',
];
class CurrentTripLoadingIndicator extends StatefulWidget { class CurrentTripLoadingIndicator extends StatefulWidget {
final Trip trip; final Trip trip;
const CurrentTripLoadingIndicator({ const CurrentTripLoadingIndicator({
@@ -15,46 +26,137 @@ class CurrentTripLoadingIndicator extends StatefulWidget {
State<CurrentTripLoadingIndicator> createState() => _CurrentTripLoadingIndicatorState(); State<CurrentTripLoadingIndicator> createState() => _CurrentTripLoadingIndicatorState();
} }
class _CurrentTripLoadingIndicatorState extends State<CurrentTripLoadingIndicator> { class _CurrentTripLoadingIndicatorState extends State<CurrentTripLoadingIndicator> {
@override @override
Widget build(BuildContext context) => Center( Widget build(BuildContext context) => Stack(
child: FutureBuilder( fit: StackFit.expand,
future: widget.trip.cityName, children: [
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { // In the very center of the panel, show the greeter which tells the user that the trip is being generated
Widget greeter; Center(child: loadingText(widget.trip)),
Widget loadingIndicator = const Padding( // As a gimmick, and a way to show that the app is still working, show a few loading dots
padding: EdgeInsets.only(top: 10), Align(
child: CircularProgressIndicator() alignment: Alignment.bottomCenter,
); child: statusText(),
)
if (snapshot.hasData) { ],
greeter = AutoSizeText(
maxLines: 1,
'Generating your trip to ${snapshot.data}...',
style: greeterStyle,
);
} else if (snapshot.hasError) {
// the exact error is shown in the central part of the trip overview. No need to show it here
greeter = AutoSizeText(
maxLines: 1,
'Error while loading trip.',
style: greeterStyle,
);
} else {
greeter = AutoSizeText(
maxLines: 1,
'Generating your trip...',
style: greeterStyle,
);
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
greeter,
loadingIndicator,
],
);
}
)
); );
} }
// automatically cycle through the greeter texts
class statusText extends StatefulWidget {
const statusText({Key? key}) : super(key: key);
@override
_statusTextState createState() => _statusTextState();
}
class _statusTextState extends State<statusText> {
int statusIndex = 0;
@override
void initState() {
super.initState();
Future.delayed(Duration(seconds: 5), () {
setState(() {
statusIndex = (statusIndex + 1) % statusTexts.length;
});
});
}
@override
Widget build(BuildContext context) {
return AutoSizeText(
statusTexts[statusIndex],
style: Theme.of(context).textTheme.labelSmall,
);
}
}
Widget loadingText(Trip trip) => FutureBuilder(
future: trip.cityName,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
Widget greeter;
if (snapshot.hasData) {
greeter = AnimatedGradientText(
text: 'Creating your trip to ${snapshot.data}...',
style: greeterStyle,
);
} else if (snapshot.hasError) {
// the exact error is shown in the central part of the trip overview. No need to show it here
greeter = AnimatedGradientText(
text: 'Error while loading trip.',
style: greeterStyle,
);
} else {
greeter = AnimatedGradientText(
text: 'Creating your trip...',
style: greeterStyle,
);
}
return greeter;
}
);
class AnimatedGradientText extends StatefulWidget {
final String text;
final TextStyle style;
const AnimatedGradientText({
Key? key,
required this.text,
required this.style,
}) : super(key: key);
@override
_AnimatedGradientTextState createState() => _AnimatedGradientTextState();
}
class _AnimatedGradientTextState extends State<AnimatedGradientText> with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
)..repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return ShaderMask(
shaderCallback: (bounds) {
return LinearGradient(
colors: [GRADIENT_START, GRADIENT_END, GRADIENT_START],
stops: [
_controller.value - 1.0,
_controller.value,
_controller.value + 1.0,
],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: Text(
widget.text,
style: widget.style,
),
);
},
);
}
}

View File

@@ -36,7 +36,7 @@ class _CurrentTripPanelState extends State<CurrentTripPanel> {
child: SizedBox( child: SizedBox(
// reuse the exact same height as the panel has when collapsed // reuse the exact same height as the panel has when collapsed
// this way the greeter will be centered when the panel is collapsed // this way the greeter will be centered when the panel is collapsed
height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20, height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT,
child: CurrentTripErrorMessage(trip: widget.trip) child: CurrentTripErrorMessage(trip: widget.trip)
), ),
); );
@@ -46,19 +46,20 @@ class _CurrentTripPanelState extends State<CurrentTripPanel> {
child: SizedBox( child: SizedBox(
// reuse the exact same height as the panel has when collapsed // reuse the exact same height as the panel has when collapsed
// this way the greeter will be centered when the panel is collapsed // this way the greeter will be centered when the panel is collapsed
height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20, height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT,
child: CurrentTripLoadingIndicator(trip: widget.trip), child: CurrentTripLoadingIndicator(trip: widget.trip),
), ),
); );
} else { } else {
return ListView( return ListView(
controller: widget.controller, controller: widget.controller,
padding: const EdgeInsets.only(bottom: 30), padding: const EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 30),
children: [ children: [
SizedBox( SizedBox(
// reuse the exact same height as the panel has when collapsed // reuse the exact same height as the panel has when collapsed
// this way the greeter will be centered when the panel is collapsed // this way the greeter will be centered when the panel is collapsed
height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 20, // note that we need to account for the padding above
height: MediaQuery.of(context).size.height * TRIP_PANEL_MIN_HEIGHT - 10,
child: CurrentTripGreeter(trip: widget.trip), child: CurrentTripGreeter(trip: widget.trip),
), ),
@@ -72,7 +73,7 @@ class _CurrentTripPanelState extends State<CurrentTripPanel> {
const Padding(padding: EdgeInsets.only(top: 10)), const Padding(padding: EdgeInsets.only(top: 10)),
Center(child: saveButton(widget.trip)), Center(child: saveButton(trip: widget.trip)),
], ],
); );
} }

View File

@@ -3,39 +3,53 @@ import 'package:anyway/main.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
Widget saveButton(Trip trip) => ElevatedButton(
onPressed: () async { class saveButton extends StatefulWidget {
SharedPreferences prefs = await SharedPreferences.getInstance(); Trip trip;
trip.toPrefs(prefs); saveButton({super.key, required this.trip});
rootScaffoldMessengerKey.currentState!.showSnackBar(
SnackBar( @override
content: Text('Trip saved'), State<saveButton> createState() => _saveButtonState();
duration: Duration(seconds: 2), }
dismissDirection: DismissDirection.horizontal
class _saveButtonState extends State<saveButton> {
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () async {
savedTrips.addTrip(widget.trip);
// SharedPreferences prefs = await SharedPreferences.getInstance();
// setState(() => widget.trip.toPrefs(prefs));
rootScaffoldMessengerKey.currentState!.showSnackBar(
SnackBar(
content: Text('Trip saved'),
duration: Duration(seconds: 2),
dismissDirection: DismissDirection.horizontal
)
);
},
child: SizedBox(
width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.save,
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 10, top: 5, bottom: 5, right: 5),
child: AutoSizeText(
'Save trip',
maxLines: 2,
),
),
),
],
),
) )
); );
}, }
child: SizedBox( }
width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.save,
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 10, top: 5, bottom: 5, right: 5),
child: AutoSizeText(
'Save trip',
maxLines: 2,
),
),
),
],
),
)
);

View File

@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
Future<void> helpDialog(BuildContext context, String title, String content) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: Text(content),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Got it!'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}

View File

@@ -1,3 +1,5 @@
import 'package:anyway/main.dart';
import 'package:anyway/structs/trip.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@@ -6,8 +8,12 @@ import 'package:anyway/structs/landmark.dart';
class LandmarkCard extends StatefulWidget { class LandmarkCard extends StatefulWidget {
final Landmark landmark; final Landmark landmark;
final Trip parentTrip;
LandmarkCard(this.landmark); LandmarkCard(
this.landmark,
this.parentTrip,
);
@override @override
_LandmarkCardState createState() => _LandmarkCardState(); _LandmarkCardState createState() => _LandmarkCardState();
@@ -17,110 +23,149 @@ class LandmarkCard extends StatefulWidget {
class _LandmarkCardState extends State<LandmarkCard> { class _LandmarkCardState extends State<LandmarkCard> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ThemeData theme = Theme.of(context); if (widget.landmark.type == typeStart || widget.landmark.type == typeFinish) {
return TextButton.icon(
onPressed: () {},
icon: widget.landmark.type.icon,
label: Text(widget.landmark.name),
);
}
// else:
return Container( return Container(
height: 160,
child: Card( child: Card(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
), ),
elevation: 5, elevation: 5,
clipBehavior: Clip.antiAliasWithSaveLayer, clipBehavior: Clip.antiAliasWithSaveLayer,
child: Row( // if the image is available, display it on the left side of the card, otherwise only display the text
crossAxisAlignment: CrossAxisAlignment.start, child: widget.landmark.imageURL != null ? splitLayout() : textLayout(),
children: [ ),
Container( // the image on the left );
// inherit the height of the parent container }
height: double.infinity,
// force a fixed width Widget splitLayout() {
width: 160, // If an image is available, display it on the left side of the card
child: CachedNetworkImage( return Row(
imageUrl: widget.landmark.imageURL ?? '', crossAxisAlignment: CrossAxisAlignment.start,
placeholder: (context, url) => Center(child: CircularProgressIndicator()), children: [
errorWidget: (context, error, stackTrace) => Icon(Icons.question_mark_outlined), Container(
// TODO: make this a switch statement to load a placeholder if null // the image on the left
// cover the whole container meaning the image will be cropped width: 160,
fit: BoxFit.cover, height: 160,
),
), child: CachedNetworkImage(
Flexible( imageUrl: widget.landmark.imageURL ?? '',
child: Padding( placeholder: (context, url) => Center(child: CircularProgressIndicator()),
padding: EdgeInsets.all(10), errorWidget: (context, error, stackTrace) => Icon(Icons.question_mark_outlined),
child: Column( fit: BoxFit.cover,
children: [ ),
Row(
children: [
Flexible(
child: Text(
widget.landmark.name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
maxLines: 2,
),
)
],
),
if (widget.landmark.nameEN != null)
Row(
children: [
Flexible(
child: Text(
widget.landmark.nameEN!,
style: const TextStyle(
fontSize: 16,
),
maxLines: 1,
),
)
],
),
SingleChildScrollView(
// allows the buttons to be scrolled
scrollDirection: Axis.horizontal,
child: Wrap(
spacing: 10,
// show the type, the website, and the wikipedia link as buttons/labels in a row
children: [
TextButton.icon(
onPressed: () {},
icon: widget.landmark.type.icon,
label: Text(widget.landmark.type.name),
),
if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0)
TextButton.icon(
onPressed: () {},
icon: Icon(Icons.hourglass_bottom),
label: Text('${widget.landmark.duration!.inMinutes} minutes'),
),
if (widget.landmark.websiteURL != null)
TextButton.icon(
onPressed: () async {
// open a browser with the website link
await launchUrl(Uri.parse(widget.landmark.websiteURL!));
},
icon: Icon(Icons.link),
label: Text('Website'),
),
if (widget.landmark.wikipediaURL != null)
TextButton.icon(
onPressed: () async {
// open a browser with the wikipedia link
await launchUrl(Uri.parse(widget.landmark.wikipediaURL!));
},
icon: Icon(Icons.book),
label: Text('Wikipedia'),
),
],
),
),
],
),
),
),
],
), ),
Flexible(
child: textLayout(),
),
],
);
}
Widget textLayout() {
return Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
Row(
children: [
Flexible(
child: Text(
widget.landmark.name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
maxLines: 2,
),
)
],
),
if (widget.landmark.nameEN != null)
Row(
children: [
Flexible(
child: Text(
widget.landmark.nameEN!,
style: const TextStyle(
fontSize: 16,
),
maxLines: 1,
),
)
],
),
Padding(padding: EdgeInsets.only(top: 10)),
Align(
alignment: Alignment.centerLeft,
child: SingleChildScrollView(
// allows the buttons to be scrolled
scrollDirection: Axis.horizontal,
child: Wrap(
spacing: 10,
// show the type, the website, and the wikipedia link as buttons/labels in a row
children: [
TextButton.icon(
onPressed: () {},
icon: widget.landmark.type.icon,
label: Text(widget.landmark.type.name),
),
if (widget.landmark.duration != null && widget.landmark.duration!.inMinutes > 0)
TextButton.icon(
onPressed: () {},
icon: Icon(Icons.hourglass_bottom),
label: Text('${widget.landmark.duration!.inMinutes} minutes'),
),
if (widget.landmark.websiteURL != null)
TextButton.icon(
onPressed: () async {
// open a browser with the website link
await launchUrl(Uri.parse(widget.landmark.websiteURL!));
},
icon: Icon(Icons.link),
label: Text('Website'),
),
PopupMenuButton(
icon: Icon(Icons.settings),
style: TextButtonTheme.of(context).style,
itemBuilder: (context) => [
PopupMenuItem(
child: ListTile(
leading: Icon(Icons.delete),
title: Text('Delete'),
onTap: () async {
widget.parentTrip.removeLandmark(widget.landmark);
rootScaffoldMessengerKey.currentState!.showSnackBar(
SnackBar(content: Text("We won't show ${widget.landmark.name} again"))
);
},
),
),
PopupMenuItem(
child: ListTile(
leading: Icon(Icons.star),
title: Text('Favorite'),
onTap: () async {
// delete the landmark
// await deleteLandmark(widget.landmark);
},
),
),
],
)
],
),
),
),
],
), ),
); );
} }

View File

@@ -1,5 +1,5 @@
import 'package:anyway/layout.dart';
import 'package:anyway/main.dart'; import 'package:anyway/main.dart';
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/structs/preferences.dart'; import 'package:anyway/structs/preferences.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:anyway/utils/fetch_trip.dart'; import 'package:anyway/utils/fetch_trip.dart';
@@ -57,7 +57,7 @@ class _NewTripButtonState extends State<NewTripButton> {
fetchTrip(trip, widget.preferences); fetchTrip(trip, widget.preferences);
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => BasePage(mainScreen: "map", trip: trip) builder: (context) => TripPage(trip: trip)
) )
); );
} }

View File

@@ -9,6 +9,15 @@ import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
const Map<String, List> debugLocations = {
'paris': [48.8575, 2.3514],
'london': [51.5074, -0.1278],
'new york': [40.7128, -74.0060],
'tokyo': [35.6895, 139.6917],
};
class NewTripLocationSearch extends StatefulWidget { class NewTripLocationSearch extends StatefulWidget {
Future<SharedPreferences> prefs = SharedPreferences.getInstance(); Future<SharedPreferences> prefs = SharedPreferences.getInstance();
Trip trip; Trip trip;
@@ -27,26 +36,35 @@ class _NewTripLocationSearchState extends State<NewTripLocationSearch> {
setTripLocation (String query) async { setTripLocation (String query) async {
List<Location> locations = []; List<Location> locations = [];
Location startLocation;
log('Searching for: $query'); log('Searching for: $query');
if (GeocodingPlatform.instance != null) {
try{ locations.addAll(await locationFromAddress(query));
locations = await locationFromAddress(query);
} catch (e) {
log('No results found for: $query : $e');
} }
if (locations.isNotEmpty) { if (locations.isNotEmpty) {
Location location = locations.first; startLocation = locations.first;
widget.trip.landmarks.clear(); } else {
widget.trip.addLandmark( log('No results found for: $query. Is geocoding available?');
Landmark( log('Setting Fallback location');
uuid: 'pending', List coordinates = debugLocations[query.toLowerCase()] ?? [48.8575, 2.3514];
name: query, startLocation = Location(
location: [location.latitude, location.longitude], latitude: coordinates[0],
type: typeStart longitude: coordinates[1],
) timestamp: DateTime.now(),
); );
} }
widget.trip.landmarks.clear();
widget.trip.addLandmark(
Landmark(
uuid: 'pending',
name: query,
location: [startLocation.latitude, startLocation.longitude],
type: typeStart
)
);
} }
late Widget locationSearchBar = SearchBar( late Widget locationSearchBar = SearchBar(

View File

@@ -26,7 +26,7 @@ class _NewTripMapState extends State<NewTripMap> {
target: LatLng(48.8566, 2.3522), target: LatLng(48.8566, 2.3522),
zoom: 11.0, zoom: 11.0,
); );
late GoogleMapController _mapController; GoogleMapController? _mapController;
final Set<Marker> _markers = <Marker>{}; final Set<Marker> _markers = <Marker>{};
_onLongPress(LatLng location) { _onLongPress(LatLng location) {
@@ -56,11 +56,15 @@ class _NewTripMapState extends State<NewTripMap> {
), ),
) )
); );
_mapController.moveCamera( // check if the controller is ready
CameraUpdate.newLatLng(
LatLng(landmark.location[0], landmark.location[1]) if (_mapController != null) {
) _mapController!.animateCamera(
); CameraUpdate.newLatLng(
LatLng(landmark.location[0], landmark.location[1])
)
);
}
setState(() {}); setState(() {});
} }
} }

View File

@@ -2,13 +2,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
class OnboardingCard extends StatelessWidget { class OnboardingCard extends StatelessWidget {
int index; final String title;
String title; final String description;
String description; final String imagePath;
String imagePath;
OnboardingCard({ const OnboardingCard({
required this.index,
required this.title, required this.title,
required this.description, required this.description,
required this.imagePath, required this.imagePath,
@@ -16,41 +14,35 @@ class OnboardingCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Color baseColor = Theme.of(context).colorScheme.secondary;
// have a different color for each card, incrementing the hue return Padding(
Color currentColor = baseColor.withAlpha(baseColor.alpha - index * 30); padding: EdgeInsets.all(20),
return Container( child: Column(
color: currentColor, mainAxisAlignment: MainAxisAlignment.center,
alignment: Alignment.center, children: [
child: Padding( Text(
padding: EdgeInsets.all(20), title,
child: Column( style: TextStyle(
mainAxisAlignment: MainAxisAlignment.center, fontSize: 24,
children: [ fontWeight: FontWeight.bold,
Text( color: Colors.white,
title,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
), ),
Padding(padding: EdgeInsets.only(top: 20)), ),
SvgPicture.asset( Padding(padding: EdgeInsets.only(top: 20)),
imagePath, SvgPicture.asset(
height: 200, imagePath,
), height: 200,
Padding(padding: EdgeInsets.only(top: 20)), ),
Text( Padding(padding: EdgeInsets.only(top: 20)),
description, Text(
style: TextStyle( description,
fontSize: 16, style: TextStyle(
), fontSize: 16,
), ),
),
] ]
), ),
)
); );
} }
} }

View File

@@ -19,8 +19,7 @@ class StepBetweenLandmarks extends StatefulWidget {
class _StepBetweenLandmarksState extends State<StepBetweenLandmarks> { class _StepBetweenLandmarksState extends State<StepBetweenLandmarks> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int timeRounded = 5 * ((widget.current.tripTime?.inMinutes ?? 0) ~/ 5); int time = widget.current.tripTime?.inMinutes ?? 0;
// ~/ is integer division (rounding)
return Container( return Container(
margin: EdgeInsets.all(10), margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10), padding: EdgeInsets.all(10),
@@ -34,7 +33,7 @@ class _StepBetweenLandmarksState extends State<StepBetweenLandmarks> {
Column( Column(
children: [ children: [
Icon(Icons.directions_walk), Icon(Icons.directions_walk),
Text("~$timeRounded min", style: TextStyle(fontSize: 10)), Text("$time min", style: TextStyle(fontSize: 10)),
], ],
), ),
Spacer(), Spacer(),

View File

@@ -1,11 +1,12 @@
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/utils/load_trips.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:anyway/layout.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
class TripsOverview extends StatefulWidget { class TripsOverview extends StatefulWidget {
final Future<List<Trip>> trips; final SavedTrips trips;
const TripsOverview({ const TripsOverview({
super.key, super.key,
required this.trips, required this.trips,
@@ -16,50 +17,34 @@ class TripsOverview extends StatefulWidget {
} }
class _TripsOverviewState extends State<TripsOverview> { class _TripsOverviewState extends State<TripsOverview> {
Widget listBuild (BuildContext context, SavedTrips trips) {
Widget listBuild (BuildContext context, AsyncSnapshot<List<Trip>> snapshot) {
List<Widget> children; List<Widget> children;
if (snapshot.hasData) { List<Trip> items = trips.trips;
children = List<Widget>.generate(snapshot.data!.length, (index) { children = List<Widget>.generate(items.length, (index) {
Trip trip = snapshot.data![index]; Trip trip = items[index];
return ListTile( return ListTile(
title: FutureBuilder( title: FutureBuilder(
future: trip.cityName, future: trip.cityName,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
return Text("Trip to ${snapshot.data}"); return Text("Trip to ${snapshot.data}");
} else if (snapshot.hasError) { } else if (snapshot.hasError) {
return Text("Error: ${snapshot.error}"); return Text("Error: ${snapshot.error}");
} else { } else {
return const Text("Trip to ..."); return const Text("Trip to ...");
} }
},
),
leading: Icon(Icons.pin_drop),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => BasePage(mainScreen: "map", trip: trip)
)
);
}, },
);
});
} else if (snapshot.hasError) {
children = [
const Icon(
Icons.error_outline,
color: Colors.red,
size: 60,
), ),
Padding( leading: Icon(Icons.pin_drop),
padding: const EdgeInsets.only(top: 16), onTap: () {
child: Text('Error: ${snapshot.error}'), Navigator.of(context).push(
), MaterialPageRoute(
]; builder: (context) => TripPage(trip: trip)
} else { )
children = [Center(child: CircularProgressIndicator())]; );
} },
);
});
return ListView( return ListView(
children: children, children: children,
@@ -69,9 +54,11 @@ class _TripsOverviewState extends State<TripsOverview> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder( return ListenableBuilder(
future: widget.trips, listenable: widget.trips,
builder: listBuild, builder: (BuildContext context, Widget? child) {
return listBuild(context, widget.trips);
}
); );
} }
} }

View File

@@ -1,3 +1,6 @@
import 'package:anyway/main.dart';
import 'package:anyway/modules/help_dialog.dart';
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/pages/settings.dart'; import 'package:anyway/pages/settings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -8,22 +11,24 @@ import 'package:anyway/modules/trips_saved_list.dart';
import 'package:anyway/utils/load_trips.dart'; import 'package:anyway/utils/load_trips.dart';
import 'package:anyway/pages/new_trip_location.dart'; import 'package:anyway/pages/new_trip_location.dart';
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/pages/onboarding.dart'; import 'package:anyway/pages/onboarding.dart';
// BasePage is the scaffold that holds all other pages // BasePage is the scaffold that holds a child page and a side drawer
// A side drawer is used to switch between pages // The side drawer is the main way to switch between pages
class BasePage extends StatefulWidget { class BasePage extends StatefulWidget {
final String mainScreen; final Widget mainScreen;
final Trip? trip; final Widget title;
final List<String> helpTexts;
const BasePage({ const BasePage({
super.key, super.key,
required this.mainScreen, required this.mainScreen,
this.trip, this.title = const Text(APP_NAME),
this.helpTexts = const [],
}); });
@override @override
@@ -34,53 +39,25 @@ class _BasePageState extends State<BasePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget currentView = const Text("loading..."); savedTrips.loadTrips();
Future<List<Trip>> trips = loadTrips();
if (widget.mainScreen == "map") {
if (widget.trip != null) {
currentView = TripPage(trip: widget.trip!);
} else {
currentView = FutureBuilder(
future: trips,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Trip> availableTrips = snapshot.data!;
if (availableTrips.isNotEmpty) {
return TripPage(trip: availableTrips[0]);
} else {
return Scaffold(
body: Center(
child: Text("Wow, so empty!"),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NewTripPage()
)
);
},
label: Text("Plan a trip"),
),
);
}
} else {
return const Text("loading...");
}
},
);
}
} else if (widget.mainScreen == "tutorial") {
currentView = OnboardingPage();
} else if (widget.mainScreen == "settings") {
currentView = SettingsPage();
}
return Scaffold( return Scaffold(
appBar: AppBar(title: Text(APP_NAME)), appBar: AppBar(
body: Center(child: currentView), title: widget.title,
actions: [
IconButton(
icon: const Icon(Icons.help),
tooltip: 'Help',
onPressed: () {
if (widget.helpTexts.isNotEmpty) {
helpDialog(context, widget.helpTexts[0], widget.helpTexts[1]);
}
}
),
],
),
body: Center(child: widget.mainScreen),
drawer: Drawer( drawer: Drawer(
child: Column( child: Column(
children: [ children: [
@@ -104,7 +81,8 @@ class _BasePageState extends State<BasePage> {
ListTile( ListTile(
title: const Text('Your Trips'), title: const Text('Your Trips'),
leading: const Icon(Icons.map), leading: const Icon(Icons.map),
selected: widget.mainScreen == "map", // TODO: this is not working!
selected: widget.mainScreen is TripPage,
onTap: () {}, onTap: () {},
trailing: ElevatedButton( trailing: ElevatedButton(
onPressed: () { onPressed: () {
@@ -122,11 +100,11 @@ class _BasePageState extends State<BasePage> {
// through the options in the drawer if there isn't enough vertical // through the options in the drawer if there isn't enough vertical
// space to fit everything. // space to fit everything.
Expanded( Expanded(
child: TripsOverview(trips: trips), child: TripsOverview(trips: savedTrips),
), ),
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: () async {
removeAllTripsFromPrefs(); savedTrips.clearTrips();
}, },
child: const Text('Clear trips'), child: const Text('Clear trips'),
), ),
@@ -134,11 +112,12 @@ class _BasePageState extends State<BasePage> {
ListTile( ListTile(
title: const Text('How to use'), title: const Text('How to use'),
leading: Icon(Icons.help), leading: Icon(Icons.help),
selected: widget.mainScreen == "tutorial", // TODO: this is not working!
selected: widget.mainScreen is OnboardingPage,
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => BasePage(mainScreen: "tutorial") builder: (context) => OnboardingPage()
) )
); );
}, },
@@ -148,11 +127,12 @@ class _BasePageState extends State<BasePage> {
ListTile( ListTile(
title: const Text('Settings'), title: const Text('Settings'),
leading: const Icon(Icons.settings), leading: const Icon(Icons.settings),
selected: widget.mainScreen == "settings", // TODO: this is not working!
selected: widget.mainScreen is SettingsPage,
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => BasePage(mainScreen: "settings") builder: (context) => SettingsPage()
) )
); );
}, },

View File

@@ -1,4 +1,5 @@
import 'package:anyway/constants.dart'; import 'package:anyway/constants.dart';
import 'package:anyway/pages/base_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart'; import 'package:sliding_up_panel/sliding_up_panel.dart';
@@ -10,7 +11,7 @@ final Shader textGradient = APP_GRADIENT.createShader(Rect.fromLTWH(0.0, 0.0, 20
TextStyle greeterStyle = TextStyle( TextStyle greeterStyle = TextStyle(
foreground: Paint()..shader = textGradient, foreground: Paint()..shader = textGradient,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 26 fontSize: 25
); );
@@ -31,7 +32,8 @@ class _TripPageState extends State<TripPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SlidingUpPanel( return BasePage(
mainScreen: SlidingUpPanel(
// use panelBuilder instead of panel so that we can reuse the scrollcontroller for the listview // use panelBuilder instead of panel so that we can reuse the scrollcontroller for the listview
panelBuilder: (scrollcontroller) => CurrentTripPanel(controller: scrollcontroller, trip: widget.trip), panelBuilder: (scrollcontroller) => CurrentTripPanel(controller: scrollcontroller, trip: widget.trip),
// using collapsed and panelBuilder seems to show both at the same time, so we include the greeter in the panelBuilder // using collapsed and panelBuilder seems to show both at the same time, so we include the greeter in the panelBuilder
@@ -41,7 +43,7 @@ class _TripPageState extends State<TripPage> {
maxHeight: MediaQuery.of(context).size.height * TRIP_PANEL_MAX_HEIGHT, maxHeight: MediaQuery.of(context).size.height * TRIP_PANEL_MAX_HEIGHT,
// padding in this context is annoying: it offsets the notion of vertical alignment. // padding in this context is annoying: it offsets the notion of vertical alignment.
// children that want to be centered vertically need to have their size adjusted by 2x the padding // children that want to be centered vertically need to have their size adjusted by 2x the padding
padding: const EdgeInsets.all(10.0), // padding: const EdgeInsets.all(10.0),
// Panel snapping should not be disabled because it significantly improves the user experience // Panel snapping should not be disabled because it significantly improves the user experience
// panelSnapping: false // panelSnapping: false
borderRadius: const BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), borderRadius: const BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)),
@@ -52,6 +54,13 @@ class _TripPageState extends State<TripPage> {
color: Colors.black, color: Colors.black,
) )
], ],
),
title: FutureBuilder(
future: widget.trip.cityName,
builder: (context, snapshot) => Text(
'Your trip to ${snapshot.hasData ? snapshot.data! : "..."}',
)
),
); );
} }
} }

View File

@@ -1,5 +1,5 @@
import 'package:anyway/modules/new_trip_button.dart';
import 'package:anyway/modules/new_trip_options_button.dart'; import 'package:anyway/modules/new_trip_options_button.dart';
import 'package:anyway/pages/base_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import "package:anyway/structs/trip.dart"; import "package:anyway/structs/trip.dart";
@@ -19,23 +19,28 @@ class _NewTripPageState extends State<NewTripPage> {
final TextEditingController lonController = TextEditingController(); final TextEditingController lonController = TextEditingController();
Trip trip = Trip(); Trip trip = Trip();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// floating search bar and map as a background // floating search bar and map as a background
return Scaffold( return BasePage(
appBar: AppBar( mainScreen: Scaffold(
title: const Text('New Trip'), body: Stack(
children: [
NewTripMap(trip),
Padding(
padding: EdgeInsets.all(15),
child: NewTripLocationSearch(trip),
),
],
),
floatingActionButton: NewTripOptionsButton(trip: trip),
), ),
body: Stack( title: Text("New Trip"),
children: [ helpTexts: [
NewTripMap(trip), "Setting the start location",
Padding( "To set the starting point, type a city name in the search bar. You can also navigate the map like you're used to and long press anywhere to set a starting point."
padding: EdgeInsets.all(15), ],
child: NewTripLocationSearch(trip),
),
],
),
floatingActionButton: NewTripOptionsButton(trip: trip),
); );
} }
} }

View File

@@ -1,4 +1,5 @@
import 'package:anyway/modules/new_trip_button.dart'; import 'package:anyway/modules/new_trip_button.dart';
import 'package:anyway/pages/base_page.dart';
import 'package:anyway/structs/preferences.dart'; import 'package:anyway/structs/preferences.dart';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@@ -19,41 +20,54 @@ class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return BasePage(
body: ListView( mainScreen: Scaffold(
children: [ body: ListView(
// Center( children: [
// child: CircleAvatar( // Center(
// radius: 100, // child: CircleAvatar(
// child: Icon(Icons.person, size: 100), // radius: 100,
// ) // child: Icon(Icons.person, size: 100),
// ), // )
Padding(padding: EdgeInsets.only(top: 30)), // ),
Center( // Padding(padding: EdgeInsets.only(top: 30)),
child: FutureBuilder( // Center(
future: widget.trip.cityName, // child: FutureBuilder(
builder: (context, snapshot) => Text( // future: widget.trip.cityName,
'Your trip to ${snapshot.hasData ? snapshot.data! : "..."}', // builder: (context, snapshot) => Text(
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold) // 'Your trip to ${snapshot.hasData ? snapshot.data! : "..."}',
) // style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)
) // )
), // )
// ),
Center( Center(
child: Padding( child: Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 0), padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 0),
child: Text('Tell us about your ideal trip.', style: TextStyle(fontSize: 18)) child: Text('Tell us about your ideal trip.', style: TextStyle(fontSize: 18))
),
), ),
),
Divider(indent: 25, endIndent: 25, height: 50), Divider(indent: 25, endIndent: 25, height: 50),
durationPicker(preferences.maxTime), durationPicker(preferences.maxTime),
preferenceSliders([preferences.sightseeing, preferences.shopping, preferences.nature]), preferenceSliders([preferences.sightseeing, preferences.shopping, preferences.nature]),
] ]
),
floatingActionButton: NewTripButton(trip: widget.trip, preferences: preferences),
), ),
floatingActionButton: NewTripButton(trip: widget.trip, preferences: preferences),
title: FutureBuilder(
future: widget.trip.cityName,
builder: (context, snapshot) => Text(
'Your trip to ${snapshot.hasData ? snapshot.data! : "..."}',
)
),
helpTexts: [
'Trip preferences',
'Set your preferences for this trip. These will be used to generate a custom itinerary.'
],
); );
} }

View File

@@ -1,7 +1,33 @@
import 'dart:ui';
import 'package:anyway/constants.dart';
import 'package:anyway/modules/onboarding_card.dart'; import 'package:anyway/modules/onboarding_card.dart';
import 'package:anyway/pages/new_trip_location.dart'; import 'package:anyway/pages/new_trip_location.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
const List<Widget> onboardingCards = [
OnboardingCard(
title: "Welcome to anyway!",
description: "Anyway helps you plan a city trip that suits your wishes.",
imagePath: "assets/city.svg"
),
OnboardingCard(
title: "Find your way",
description: "Bored by churches? No problem! Hate shopping? No worries! Instead of suggesting the generic trips that bore you, anyway will try to give you recommendations that really suit you.",
imagePath: "assets/plan.svg"
),
OnboardingCard(
title: "Change your mind",
description: "Feet get sore, the weather changes. Anyway understands that! Move or remove destinations, visit hidden gems along your journey, do your own thing. Anyway adapts to your spontaneous decisions.",
imagePath: "assets/cat.svg"
),
OnboardingCard(
title: "Feeling lost?",
description: "Whenever you are confused or need help with the app, look out for the question mark in the top right corner. Help is just a tap away!",
imagePath: "assets/confused.svg"
),
];
class OnboardingPage extends StatefulWidget { class OnboardingPage extends StatefulWidget {
const OnboardingPage({super.key}); const OnboardingPage({super.key});
@@ -10,37 +36,83 @@ class OnboardingPage extends StatefulWidget {
} }
class _OnboardingPageState extends State<OnboardingPage> { class _OnboardingPageState extends State<OnboardingPage> {
final PageController _controller = PageController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final PageController _controller = PageController();
return Scaffold( return Scaffold(
body: Stack( body: Stack(
children: [ children: [
AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Stack(
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: APP_GRADIENT.colors,
stops: [
(_controller.hasClients ? _controller.page ?? _controller.initialPage : _controller.initialPage) / onboardingCards.length,
(_controller.hasClients ? _controller.page ?? _controller.initialPage + 1 : _controller.initialPage + 1) / onboardingCards.length,
],
),
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
color: Colors.black.withOpacity(0),
),
),
],
);
},
),
PageView( PageView(
// horizontally scrollable list of pages
controller: _controller, controller: _controller,
children: List.generate(
children: [ onboardingCards.length,
OnboardingCard(index: 1, title: "Welcome to anyway!", description: "Anyway helps you plan a city trip that suits your wishes.", imagePath: "assets/city.svg"), (index) {
OnboardingCard(index: 2, title: "Find your way", description: "Bored by churches? No problem! Hate shopping? No worries! More than showing you the typical 'must-sees' of a city, anyway will try to give you recommendations that really suit you.", imagePath: "assets/plan.svg"), return Container(
OnboardingCard(index: 3, title: "Change your mind", description: "Life happens when you're busy making plans. Anyway understands that! Move or remove destinations, visit hidden gems along your journey, do your own thing. Anyway adapts to your spontaneous decisions.", imagePath: "assets/cat.svg"), alignment: Alignment.center,
], child: onboardingCards[index],
);
}
),
), ),
], ],
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton.extended(
onPressed: () { onPressed: () {
if (_controller.page == 2) { if (_controller.page == onboardingCards.length - 1) {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const NewTripPage() builder: (context) => const NewTripPage()
) )
);
} else {
_controller.nextPage(duration: Duration(milliseconds: 500), curve: Curves.ease);
}
},
label: AnimatedBuilder(
animation: _controller,
builder: (context, child) {
if ((_controller.page ?? _controller.initialPage) == onboardingCards.length - 1) {
return Row(
children: [
const Text("Start planning!"),
Padding(padding: const EdgeInsets.only(right: 8.0)),
const Icon(Icons.map_outlined)
],
); );
} else { } else {
_controller.nextPage(duration: Duration(milliseconds: 500), curve: Curves.ease); return const Icon(Icons.arrow_forward);
} }
}, }
child: Icon(Icons.arrow_forward), )
), ),
); );
} }

View File

@@ -1,5 +1,6 @@
import 'package:anyway/constants.dart'; import 'package:anyway/constants.dart';
import 'package:anyway/main.dart'; import 'package:anyway/main.dart';
import 'package:anyway/pages/base_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@@ -16,30 +17,37 @@ class SettingsPage extends StatefulWidget {
class _SettingsPageState extends State<SettingsPage> { class _SettingsPageState extends State<SettingsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListView( return BasePage(
padding: EdgeInsets.all(15), mainScreen: ListView(
children: [ padding: EdgeInsets.all(15),
// First a round, centered image children: [
Center( // First a round, centered image
child: CircleAvatar( Center(
radius: 75, child: CircleAvatar(
child: Icon(Icons.settings, size: 100), radius: 75,
) child: Icon(Icons.settings, size: 100),
), )
Center( ),
child: Text('Global settings', style: TextStyle(fontSize: 24)) Center(
), child: Text('Global settings', style: TextStyle(fontSize: 24))
),
Divider(indent: 25, endIndent: 25, height: 50), Divider(indent: 25, endIndent: 25, height: 50),
darkMode(), darkMode(),
setLocationUsage(), setLocationUsage(),
setDebugMode(), setDebugMode(),
Divider(indent: 25, endIndent: 25, height: 50), Divider(indent: 25, endIndent: 25, height: 50),
privacyInfo(), privacyInfo(),
] ]
),
title: Text('Settings'),
helpTexts: [
'Settings',
'Preferences set in this page are global and will affect the entire application.'
],
); );
} }
@@ -169,7 +177,9 @@ class _SettingsPageState extends State<SettingsPage> {
return Center( return Center(
child: Column( child: Column(
children: [ children: [
Text('Our privacy policy is available under:'), Text('AnyWay does not collect or store any of the data that is submitted via the app. The location of your trip is not stored. The location feature is only used to show your current location on the map, it is not transmitted to our servers.', textAlign: TextAlign.center),
Padding(padding: EdgeInsets.only(top: 3)),
Text('Our full privacy policy is available under:', textAlign: TextAlign.center),
TextButton.icon( TextButton.icon(
icon: Icon(Icons.info), icon: Icon(Icons.info),

View File

@@ -24,8 +24,7 @@ final class Landmark extends LinkedListEntry<Landmark>{
// description to be shown in the overview // description to be shown in the overview
final String? nameEN; final String? nameEN;
final String? websiteURL; final String? websiteURL;
final String? wikipediaURL; String? imageURL; // not final because it can be patched
final String? imageURL;
final String? description; final String? description;
final Duration? duration; final Duration? duration;
final bool? visited; final bool? visited;
@@ -44,7 +43,6 @@ final class Landmark extends LinkedListEntry<Landmark>{
this.nameEN, this.nameEN,
this.websiteURL, this.websiteURL,
this.wikipediaURL,
this.imageURL, this.imageURL,
this.description, this.description,
this.duration, this.duration,
@@ -70,7 +68,6 @@ final class Landmark extends LinkedListEntry<Landmark>{
final isSecondary = json['is_secondary'] as bool?; final isSecondary = json['is_secondary'] as bool?;
final nameEN = json['name_en'] as String?; final nameEN = json['name_en'] as String?;
final websiteURL = json['website_url'] as String?; final websiteURL = json['website_url'] as String?;
final wikipediaURL = json['wikipedia_url'] as String?;
final imageURL = json['image_url'] as String?; final imageURL = json['image_url'] as String?;
final description = json['description'] as String?; final description = json['description'] as String?;
var duration = Duration(minutes: json['duration'] ?? 0) as Duration?; var duration = Duration(minutes: json['duration'] ?? 0) as Duration?;
@@ -85,7 +82,6 @@ final class Landmark extends LinkedListEntry<Landmark>{
isSecondary: isSecondary, isSecondary: isSecondary,
nameEN: nameEN, nameEN: nameEN,
websiteURL: websiteURL, websiteURL: websiteURL,
wikipediaURL: wikipediaURL,
imageURL: imageURL, imageURL: imageURL,
description: description, description: description,
duration: duration, duration: duration,
@@ -112,7 +108,6 @@ final class Landmark extends LinkedListEntry<Landmark>{
'is_secondary': isSecondary, 'is_secondary': isSecondary,
'name_en': nameEN, 'name_en': nameEN,
'website_url': websiteURL, 'website_url': websiteURL,
'wikipedia_url': wikipediaURL,
'image_url': imageURL, 'image_url': imageURL,
'description': description, 'description': description,
'duration': duration?.inMinutes, 'duration': duration?.inMinutes,
@@ -130,7 +125,7 @@ class LandmarkType {
LandmarkType({required this.name, this.icon = const Icon(Icons.location_on)}) { LandmarkType({required this.name, this.icon = const Icon(Icons.location_on)}) {
switch (name) { switch (name) {
case 'sightseeing': case 'sightseeing':
icon = const Icon(Icons.church); icon = const Icon(Icons.castle);
break; break;
case 'nature': case 'nature':
icon = const Icon(Icons.eco); icon = const Icon(Icons.eco);

View File

@@ -113,10 +113,3 @@ LinkedList<Landmark> readLandmarks(SharedPreferences prefs, String? firstUUID) {
} }
return landmarks; return landmarks;
} }
void removeAllTripsFromPrefs () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.clear();
}

View File

@@ -1,5 +1,6 @@
import "dart:convert"; import "dart:convert";
import "dart:developer"; import "dart:developer";
import "package:anyway/utils/load_landmark_image.dart";
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:anyway/constants.dart'; import 'package:anyway/constants.dart';
@@ -85,6 +86,20 @@ fetchTrip(
} }
patchLandmarkImage(Landmark landmark) async {
// patch the landmark to include an image from an external source
if (landmark.imageURL == null) {
String? newUrl = await getImageUrlFromName(landmark.name);
if (newUrl != null) {
landmark.imageURL = newUrl;
}
} else if (landmark.imageURL!.contains("photos.app.goo.gl")) {
// the image is a google photos link, we should get the image behind the link
String? newUrl = await getImageUrlFromGooglePhotos(landmark.imageURL!);
// also set the new url if it is null
landmark.imageURL = newUrl;
}
}
Future<(Landmark, String?)> fetchLandmark(String uuid) async { Future<(Landmark, String?)> fetchLandmark(String uuid) async {
final response = await dio.get( final response = await dio.get(
@@ -101,5 +116,7 @@ Future<(Landmark, String?)> fetchLandmark(String uuid) async {
log(response.data.toString()); log(response.data.toString());
Map<String, dynamic> json = response.data; Map<String, dynamic> json = response.data;
String? nextUUID = json["next_uuid"]; String? nextUUID = json["next_uuid"];
return (Landmark.fromJson(json), nextUUID); Landmark landmark = Landmark.fromJson(json);
patchLandmarkImage(landmark);
return (landmark, nextUUID);
} }

View File

@@ -0,0 +1,41 @@
import 'package:anyway/pages/current_trip.dart';
import 'package:anyway/pages/onboarding.dart';
import 'package:anyway/structs/trip.dart';
import 'package:anyway/utils/load_trips.dart';
import 'package:flutter/material.dart';
Widget getFirstPage() {
SavedTrips trips = SavedTrips();
trips.loadTrips();
return ListenableBuilder(
listenable: trips,
builder: (BuildContext context, Widget? child) {
List<Trip> items = trips.trips;
if (items.isNotEmpty) {
return TripPage(trip: items[0]);
} else {
return OnboardingPage();
}
}
);
// Future<List<Trip>> trips = loadTrips();
// // test if there are any active trips
// // if there are, return the trip list
// // if there are not, return the onboarding page
// return FutureBuilder(
// future: trips,
// builder: (context, snapshot) {
// if (snapshot.hasData) {
// List<Trip> availableTrips = snapshot.data!;
// if (availableTrips.isNotEmpty) {
// return TripPage(trip: availableTrips[0]);
// } else {
// return OnboardingPage();
// }
// } else {
// return CircularProgressIndicator();
// }
// }
// );
}

View File

@@ -0,0 +1,71 @@
import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:fuzzywuzzy/fuzzywuzzy.dart';
import 'dart:convert';
import 'package:fuzzywuzzy/model/extracted_result.dart';
const String baseUrl = "https://en.wikipedia.org/w/api.php";
final Dio dio = Dio();
Future<int?> bestPageMatch(String title) async {
final response = await dio.get(baseUrl, queryParameters: {
"action": "query",
"format": "json",
"list": "prefixsearch",
"pssearch": title,
});
final data = jsonDecode(response.toString());
log(data.toString());
final List<dynamic> results = data["query"]["prefixsearch"] ?? {};
final Map<String, int> titlesAndIds = {
for (var d in results) d["title"]: d["pageid"]
};
if (titlesAndIds.isEmpty) {
log("No pages found for $title");
return null;
}
// after the empty check, we can safely assume that there is a best match
final ExtractedResult<String> bestMatch = extractOne(
query: title,
choices: titlesAndIds.keys.toList(),
cutoff: 70,
);
return titlesAndIds[bestMatch.choice];
}
Future<String?> getImageUrl(int pageId) async {
final response = await dio.get(baseUrl, queryParameters: {
"action": "query",
"format": "json",
"prop": "pageimages",
"pageids": pageId,
"pithumbsize": 500,
});
final data = jsonDecode(response.toString());
final pageData = data["query"]["pages"][pageId.toString()];
return pageData["thumbnail"]?["source"];
}
Future<String?> getImageUrlFromName(String title) async {
int? pageId = await bestPageMatch(title);
if (pageId == null) {
return null;
}
return await getImageUrl(pageId);
}
Future<String?> getImageUrlFromGooglePhotos(String url) async {
// this is a very simple implementation that just gets the image behind the link
// it is not guaranteed to work for all google photos links
final response = await dio.get(url);
final data = response.toString();
final int start = data.indexOf("https://lh3.googleusercontent.com");
final int end = data.indexOf('"', start);
return data.substring(start, end);
}

View File

@@ -1,19 +1,39 @@
import 'dart:collection';
import 'package:anyway/structs/trip.dart'; import 'package:anyway/structs/trip.dart';
import 'package:anyway/structs/landmark.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
Future<List<Trip>> loadTrips() async { import 'package:flutter/foundation.dart';
SharedPreferences prefs = await SharedPreferences.getInstance();
List<Trip> trips = []; class SavedTrips extends ChangeNotifier {
Set<String> keys = prefs.getKeys(); List<Trip> _trips = [];
for (String key in keys) {
if (key.startsWith('trip_')) { List<Trip> get trips => _trips;
String uuid = key.replaceFirst('trip_', '');
trips.add(Trip.fromPrefs(prefs, uuid)); void loadTrips() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<Trip> trips = [];
Set<String> keys = prefs.getKeys();
for (String key in keys) {
if (key.startsWith('trip_')) {
String uuid = key.replaceFirst('trip_', '');
trips.add(Trip.fromPrefs(prefs, uuid));
}
} }
_trips = trips;
notifyListeners();
}
void addTrip(Trip trip) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
trip.toPrefs(prefs);
_trips.add(trip);
notifyListeners();
}
void clearTrips () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.clear();
_trips = [];
notifyListeners();
} }
return trips;
} }

View File

@@ -101,10 +101,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: collection name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.18.0" version: "1.19.0"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@@ -232,6 +232,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
fuzzywuzzy:
dependency: "direct main"
description:
name: fuzzywuzzy
sha256: "3004379ffd6e7f476a0c2091f38f16588dc45f67de7adf7c41aa85dec06b432c"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
geocoding: geocoding:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -404,18 +412,18 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "10.0.5" version: "10.0.7"
leak_tracker_flutter_testing: leak_tracker_flutter_testing:
dependency: transitive dependency: transitive
description: description:
name: leak_tracker_flutter_testing name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.5" version: "3.0.8"
leak_tracker_testing: leak_tracker_testing:
dependency: transitive dependency: transitive
description: description:
@@ -700,7 +708,7 @@ packages:
dependency: transitive dependency: transitive
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.99" version: "0.0.0"
sliding_up_panel: sliding_up_panel:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -745,10 +753,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: stack_trace name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.11.1" version: "1.12.0"
stream_channel: stream_channel:
dependency: transitive dependency: transitive
description: description:
@@ -769,10 +777,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: string_scanner name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
synchronized: synchronized:
dependency: transitive dependency: transitive
description: description:
@@ -793,10 +801,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.2" version: "0.7.3"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@@ -913,10 +921,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: vm_service name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "14.2.5" version: "14.3.0"
web: web:
dependency: transitive dependency: transitive
description: description:

View File

@@ -51,6 +51,7 @@ dependencies:
flutter_launcher_icons: ^0.13.1 flutter_launcher_icons: ^0.13.1
permission_handler: ^11.3.1 permission_handler: ^11.3.1
geolocator: ^13.0.1 geolocator: ^13.0.1
fuzzywuzzy: ^1.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@@ -1,30 +0,0 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// import 'package:anyway/main.dart';
import 'package:anyway/layout.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(BasePage(mainScreen: "map",));
// Verfiy that the title is displayed
expect(find.text('City Nav'), findsOneWidget);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}

1091
report.html Normal file

File diff suppressed because it is too large Load Diff

48
status Normal file
View File

@@ -0,0 +1,48 @@
error: wrong number of arguments, should be from 1 to 2
usage: git config [<options>]
Config file location
--[no-]global use global config file
--[no-]system use system config file
--[no-]local use repository config file
--[no-]worktree use per-worktree config file
-f, --[no-]file <file>
use given config file
--[no-]blob <blob-id> read config from given blob object
Action
--[no-]get get value: name [value-pattern]
--[no-]get-all get all values: key [value-pattern]
--[no-]get-regexp get values for regexp: name-regex [value-pattern]
--[no-]get-urlmatch get value specific for the URL: section[.var] URL
--[no-]replace-all replace all matching variables: name value [value-pattern]
--[no-]add add a new variable: name value
--[no-]unset remove a variable: name [value-pattern]
--[no-]unset-all remove all matches: name [value-pattern]
--[no-]rename-section rename section: old-name new-name
--[no-]remove-section remove a section: name
-l, --[no-]list list all
--[no-]fixed-value use string equality when comparing values to 'value-pattern'
-e, --[no-]edit open an editor
--[no-]get-color find the color configured: slot [default]
--[no-]get-colorbool find the color setting: slot [stdout-is-tty]
Type
-t, --[no-]type <type>
value is given this type
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--bool-or-str value is --bool or string
--path value is a path (file or directory name)
--expiry-date value is an expiry date
Other
-z, --[no-]null terminate values with NUL byte
--[no-]name-only show variable names only
--[no-]includes respect include directives on lookup
--[no-]show-origin show origin of config (file, standard input, blob, command line)
--[no-]show-scope show scope of config (worktree, local, global, system, command)
--[no-]default <value>
with --get, use default value when missing entry