This API calculates the safest route between a start and an end location, using flood risk data from the UP NOAH dataset, which is pre-loaded via a remote database.
-
Python: Ensure Python 3.13 is installed.
- To verify, run:
python3.13 --version
- If not installed, download and install it from the official Python website.
- To verify, run:
-
Database Credentials: Add a
db_env.py
file in the main directory containing the database credentials. This file should be formatted as follows:DB_NAME = "" DB_USER = "" DB_PASSWORD = "" DB_HOST = "" DB_PORT = "" TABLE_NAME = ""
-
Clone the repository or download the source code.
-
Navigate to the project directory.
-
Set up a virtual environment:
python3.13 -m venv .venv
-
Activate the virtual environment:
source .venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Start the development server:
fastapi dev main.py
-
By default, the API will be available at:
http://127.0.0.1:8000
-
Use the
/directions
endpoint to calculate the safest route. Example:http://127.0.0.1:8000/directions?start=<longitude,latitude>&end=<longitude,latitude>
Replace
<longitude,latitude>
with the appropriate coordinates for the start and end locations.Example for Quezon City:
http://127.0.0.1:8000/directions?start=121.0437,14.6760&end=121.0567,14.6517
-
Ensure the virtual environment is activated:
source .venv/bin/activate
-
Run the test suite using
pytest
:pytest
-
View the test results in the terminal. Pytest will display detailed feedback about the tests.
- The UP NOAH dataset is pre-loaded and does not require manual setup.
- Modify the
host
andport
in thefastapi
command if needed to match your environment. - Ensure the
db_env.py
file is correctly configured for database access. - Route requests with a location outside Quezon City could result to an incorrect route data since flood data is limited to Quezon City only.
For further assistance, refer to the FastAPI documentation or contact the project maintainer.