pipeline.src.shared_tasks.alerts
Functions
|
Return DataFrame of vessels with active silenced alerts of the given type. |
|
Return DataFrame of vessels with active (non archived) reporting originating from |
|
Return ids of pending alerts corresponding to alert_type |
|
Return ids of reportings corresponding to alert_type |
|
Generates alerts from the input vessels_in_alert, which must contain the |
|
Filters alerts to keep only alerts of vessels that are not in |
|
Updates the pending_alerts that have the specified alert_config_name by: |
Module Contents
- pipeline.src.shared_tasks.alerts.extract_silenced_alerts(alert_type: str, number_of_hours: int = 0, alert_id: str | None = None) → pandas.DataFrame[source]
Return DataFrame of vessels with active silenced alerts of the given type.
- Parameters:
alert_type (str) – Type of alert for which to extract silenced alerts
number_of_hours (int, optional) – Number of hours from current time to extract. Defaults to 0.
- Returns:
Silenced alerts with columns
- Return type:
pd.DataFrame
- pipeline.src.shared_tasks.alerts.extract_active_reportings(alert_type: str) → pandas.DataFrame[source]
Return DataFrame of vessels with active (non archived) reporting originating from alerts of the given type.
- pipeline.src.shared_tasks.alerts.extract_pending_alerts_ids_of_type(alert_type: str) → List[int][source]
Return ids of pending alerts corresponding to alert_type
- pipeline.src.shared_tasks.alerts.extract_non_archived_reportings_ids_of_type(alert_type: str) → List[int][source]
Return ids of reportings corresponding to alert_type
- pipeline.src.shared_tasks.alerts.make_alerts(vessels_in_alert: pandas.DataFrame, alert_type: str, name: str, *, natinf_code: int, threat: str, threat_characterization: str, alert_id: int | None = None, description: str | None = None) → pandas.DataFrame[source]
Generates alerts from the input vessels_in_alert, which must contain the following columns :
cfr
external_immatriculation
ircs
vessel_id
vessel_identifier
vessel_name
facade
dml
flag_state
risk_factor
triggering_behaviour_datetime_utc
and optionally, depth, latitude and longitude
If latitude and longitude are not columns of the input, they are added and filled with null values in the result.
If depth is a column of the input, it is added to the value attributes.
- Parameters:
vessels_in_alert (pd.DataFrame) – DateFrame of vessels for which to create an alert.
alert_type (str) – type to specify in the built alerts.
name (str) – name of the alert.
natinf_code) – natinf code associated with the alert.
threat (str) – threat associated with the alert.
threat_characterization (str) – threat_characterization associated with the alert.
alert_id (str | None) – alert_id to specify in the built alerts, defaults to None.
description (str | None) – description of the alert, defaults to None.
- Returns:
DataFrame of alerts.
- Return type:
pd.DataFrame
- pipeline.src.shared_tasks.alerts.filter_alerts(alerts: pandas.DataFrame, vessels_with_silenced_alerts: pandas.DataFrame, vessels_with_active_reportings: pandas.DataFrame = None) → pandas.DataFrame[source]
Filters alerts to keep only alerts of vessels that are not in vessels_with_silenced_alerts. If vessels_with_active_reportings is provided, alerts of vessels that are in this DataFrame are also removed.
All input DataFrames must have columns :
internal_reference_number
external_reference_number
ircs
In addition, the alerts DataFrame must have columns :
vessel_id
vessel_name
vessel_identifier
flag_state
facade
triggering_behaviour_datetime_utc
creation_date
latitude
longitude
value
alert_config_name
and the silenced_alerts DataFrame must have a silenced_before_date column.
- Parameters:
alerts (pd.DataFrame) – positions alerts.
vessels_with_silenced_alerts (pd.DataFrame) – vessels with silenced alerts.
- Returns:
same as input with some rows removed.
- Return type:
pd.DataFrame
- pipeline.src.shared_tasks.alerts.load_alerts(alerts: pandas.DataFrame, alert_config_name: str)[source]
Updates the pending_alerts that have the specified alert_config_name by:
deleting alerts in the pending_alerts`table of the specified `alert_config_name
inserting alerts of the alerts dataframe into the pending_alerts table
- Parameters:
alerts (pd.DataFrame) – Alerts to load into the pending_alerts table
alert_config_name (str) – Name that uniquely identifies the set of parameters used for the flow run