The Marine Metrics API is a Python-based application for analyzing maritime data, including vessel compliance, speed differences, and metrics over specific time periods. It provides a set of functionalities to filter and analyze maritime data to improve decision-making processes in maritime operations.
- Vessel Data Retrieval: Fetch raw and filtered data for vessels.
- Compliance Score Calculation: Compare compliance scores based on speed adherence between vessels.
- Speed Difference Calculation: Calculate the speed differences between actual and proposed speeds for vessels.
- Data Filtering: Filter invalid data, including outliers, missing values, and incorrect geocoordinates.
- Reporting: Report invalid data and produce suggestions.
The application requires reading data from a CSV file. The path to this CSV file is configurable via the CSV_PATH
parameter in the config.py
file. The default dataset is the data/vessel_data.csv
-
Clone the Repository:
git clone https://github.com/CortoMaltese3/MaritimeMetricsAPI.git cd MaritimeMetricsAPI git checkout main
-
Set Up a Virtual Environment (optional but recommended):
# Using venv python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` # Or using Conda conda create --name maritime python=3.8 conda activate maritime
-
Install Dependencies:
pip install -r requirements.txt
-
Create a
.env
File based on the.env.template
in the root directory. -
Start the Flask Application Locally:
flask run
- Ensure Docker and Docker-Compose are Installed:
- Follow steps 1 to 4 from the Developers section.
- Use Docker Compose to Run the Application:
docker-compose up --build
- Get Vessel Invalid Data:
GET /api/vessel_invalid_data/<vessel_code>
- Get Vessel Speed Difference:
GET /api/vessel_speed_difference/<vessel_code>
- Compare Vessel Compliance:
GET /api/vessel_compliance_comparison/<vessel_code1>/<vessel_code2>
- Get Vessel Metrics:
GET /api/vessel_metrics/<vessel_code>/<start_date>/<end_date>
- Get Raw Vessel Metrics:
GET /api/vessel_raw_metrics/<vessel_code>/<start_date>/<end_date>
The API uses standard HTTP response codes to indicate the success or failure of requests:
200 OK
: The request was successful.400 Bad Request
: The request was invalid or cannot be served.404 Not Found
: The requested resource could not be found.500 Internal Server Error
: An error occurred in the server.
The application logs important actions and errors, facilitating debugging and monitoring. The logs are stored locally in the app.log file.
Developer documentation, including a detailed description of API endpoints and usage examples, can be found here.
Ensure you run the tests and comply with the linting standards before opening a pull request:
- Run tests:
python -m unittest tests/test_api.py
- Check linting:
pylint app/ --fail-under=8
Failure to meet the test coverage and linting standards will result in CI pipeline failures.
MarineMetricsAPI includes a Swagger UI interface that allows developers and users to interactively test the API endpoints without writing any code. The Swagger UI provides a web-based interface where you can see all available API endpoints, their required parameters, and even execute API calls directly from your browser. More information can be found in the documentation.