Models Module
Module defining the data models and business logic for the maritime data application.
Includes classes and methods for loading and processing maritime data, such as filtering invalid data, calculating compliance scores, and comparing vessel metrics. The primary class, MaritimeData, encapsulates the logic for data handling, including loading from CSV, data cleansing, and metrics computation.
- class app.models.MaritimeData(csv_path: str)[source]
Manages maritime data operations, including loading, filtering, and processing vessel data.
The class provides functionality to load vessel data from a CSV file, apply several filters to clean the data, and calculate metrics for vessels over specified periods.
- Parameters:
csv_path (str) – Path to the CSV file containing maritime data.
- calculate_compliance_score(vessel_code: int) float [source]
Computes a compliance score based on the deviation from proposed speeds.
The score is an average percentage representing how closely the vessel’s actual speed adheres to proposed speeds, with higher scores indicating closer adherence.
- Parameters:
vessel_code – The unique identifier for the vessel.
- Returns:
The compliance score as a float rounded to two decimal places.
- Return type:
float
- compare_vessel_compliance(vessel_code1: int, vessel_code2: int) str [source]
Compares the compliance scores of two vessels and indicates which is more compliant.
Calculates compliance scores for both vessels based on their adherence to proposed speeds and returns a message comparing these scores.
- Parameters:
vessel_code1 – Unique identifier for the first vessel.
vessel_code2 – Unique identifier for the second vessel.
- Returns:
Message indicating which vessel is more compliant or if they have eq compliance.
- Return type:
str
- get_invalid_data_for_vessel(vessel_code: int) Dict[str, Dict[str, Dict[str, int]]] [source]
Retrieves a summary of invalid data entries for a specific vessel.
Organizes invalid data entries by problem type and affected columns, providing a detailed breakdown of issues identified in the vessel’s data.
- Parameters:
vessel_code – The unique identifier for the vessel.
- Returns:
A nested dictionary summarizing invalid data by problem type and column.
- Return type:
Dict[str, Dict[str, Dict[str, int]]]
- get_metrics_for_vessel_period(vessel_code: int, start_date: str, end_date: str, limit=None) List[Dict[str, Any]] [source]
Retrieves filtered data metrics for a specific vessel over a given period.
Metrics include calculated speed differences between actual and proposed speeds. If no data exists for the given period, an empty list is returned.
- Parameters:
vessel_code – Unique identifier for the vessel.
start_date – Start of the period in ‘YYYY-MM-DD’ format.
end_date – End of the period in ‘YYYY-MM-DD’ format.
- Returns:
List of dictionaries with data for each record within the period.
- Return type:
List[Dict[str, Any]]
- get_raw_metrics_for_vessel_period(vessel_code: int, start_date: str, end_date: str, limit=None) List[Dict[str, Any]] [source]
Retrieves raw data metrics for a specific vessel over a given period.
Provides unfiltered access to data for in-depth analysis. but without applying any data cleansing or additional calculations.
- Parameters:
vessel_code – Unique identifier for the vessel.
start_date – Start of the period in ‘YYYY-MM-DD’ format.
end_date – End of the period in ‘YYYY-MM-DD’ format.
- Returns:
List of dictionaries with raw data for each record within the period.
- Return type:
List[Dict[str, Any]]
- get_speed_differences_for_vessel(vessel_code: int, limit=None) List[Dict[str, Any]] [source]
Calculates the speed differences between actual and proposed speeds for a vessel.
For each record pertaining to the specified vessel, computes the absolute difference between actual and proposed speeds over ground, adding these as a new metric.
- Parameters:
vessel_code – The unique identifier for the vessel.
- Returns:
A list of dictionaries, each containing latitude, longitude, and the calculated speed difference for a record.
- Return type:
List[Dict[str, Any]]
Views Module
Module containing Flask route definitions for the web application.
This module defines the API endpoints of the web application, handling the requests to various functionalities such as retrieving invalid data for vessels, comparing vessel compliance scores, and fetching vessel speed differences. Each route is associated with a specific function that processes the request and returns a response to the client.
- app.views.get_vessel_invalid_data(vessel_code: str) Response [source]
Retrieves a summary of invalid data for a specific vessel based on its code.
- Parameters:
vessel_code – The unique code identifying the vessel.
- Returns:
A JSON response containing a summary of invalid data issues.
- Return type:
Response
Example response:
{ "message": "Found invalid data for this vessel", "vessel_code": 3001, "invalid_data": { "below_zero": { "proposed_speed_overground": 30686, "predicted_fuel_consumption": 1669, "power": 1375 } ... } }
- app.views.get_vessel_metrics(vessel_code: str, start_date: str, end_date: str) Response [source]
Retrieves metrics for a specific vessel within a given time period.
- Parameters:
vessel_code – The unique code identifying the vessel.
start_date – The start date of the period (inclusive).
end_date – The end date of the period (inclusive).
- Returns:
A JSON response containing the metrics for the specified vessel and period.
- Return type:
Response
Example response:
[ { "vessel_code": 3001, "datetime": "2023-06-01 00:01:00", "latitude": 10.2894496918, "longitude": -14.7888498306, "power": 0.0, "fuel_consumption": 0.0, "actual_speed_overground": 0.09999, "proposed_speed_overground": 0.9464979896, "predicted_fuel_consumption": 0.0, "speed_difference": 0.8465079896 } ... ]
- app.views.get_vessel_problems(vessel_code: str)[source]
Retrieves a summary of problematic data groups for a specific vessel.
- Parameters:
vessel_code – The unique code identifying the vessel.
- Returns:
A JSON response containing the summary of problematic data groups.
- Return type:
Response
- app.views.get_vessel_raw_metrics(vessel_code: str, start_date: str, end_date: str) Response [source]
Retrieves raw data metrics for a specific vessel over a specified period.
- Parameters:
vessel_code – The unique code identifying the vessel.
start_date – The start date of the period (inclusive).
end_date – The end date of the period (inclusive).
- Returns:
A JSON response containing the raw data for the vessel within the specified period.
- Return type:
Response
Example response:
[ { "vessel_code": 3001, "datetime": "2023-06-01 00:00:00", "latitude": 10.2894458771, "longitude": -14.7888755798, "power": 0.0, "fuel_consumption": 0.0, "actual_speed_overground": 0.039996, "proposed_speed_overground": -0.1899042625, "predicted_fuel_consumption": 0.0 } ... ]
- app.views.get_vessel_speed_difference(vessel_code: str) Response [source]
Provides the speed differences between actual and proposed speeds for a vessel.
- Parameters:
vessel_code – The unique code identifying the vessel.
- Returns:
A JSON response containing the speed differences for the vessel.
- Return type:
Response
Example response:
{ "message": "Speed differences for the vessel", "vessel_code": 19310, "speed_differences": [ { "latitude": 49.2837677001953, "longitude": -123.177825927734, "speed_difference": 0.747206647694111 } ... ] }
- app.views.vessel_compliance_comparison(vessel_code1: str, vessel_code2: str) Response [source]
Compares the compliance scores between two vessels based on their speed adherence.
- Parameters:
vessel_code1 – The unique code identifying the first vessel.
vessel_code2 – The unique code identifying the second vessel.
- Returns:
A JSON response indicating the comparison result.
- Return type:
Response
Example response:
{ "message": "Vessel 19310 is more compliant with a compliance score of 83.54% compared to Vessel 3001's score of 72.11%." }