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_CACHE_NAME = "" DB_CACHE_USER = "" DB_CACHE_PASSWORD = "" DB_CACHE_HOST = "" DB_CACHE_PORT = "" DB_CACHE_TABLE_NAME = "" DB_CACHE_URL = ""
-
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
- Install Docker
- Pull the image from Docker Hub
docker pull epilefs/buhay-api
- Run the downloaded image
docker run -p 8080:8080 epilefs/buhay-api
- By default, the API will be available at:
http://0.0.0.0:8080
-
Start the development server:
fastapi dev main.py
-
By default, the API will be available at:
http://127.0.0.1:8000
-
Install Postman.
-
Use the
/directions
endpoint to calculate the safest route.- If running with the fastapi server, use
http://127.0.0.1:8000/directions
- If running with Docker, use
http://0.0.0.0:8080/directions
In the request body, the endpoint requires a JSON parameter of the form
{ "start" : "<longitude>,<latitude>", "end" : "<longitude>,<latitude>" }
- If running with the fastapi server, use
-
The response will be in the form
{ "route" : { "duration": float, "distanceKm": float }, "geojson" : <geojson_data>, "message" : str }
-
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.