pipeline.src.flows.update_beacon_malfunctions

Functions

extract_last_positions(→ pandas.DataFrame)

Extract the last emission date of each vessel in the last_positions table.

extract_known_malfunctions(→ pandas.DataFrame)

Extract ongoing malfunctions in the beacon_malfunctions table.

extract_vessels_that_should_emit(→ pandas.DataFrame)

Extract vessels from the vessels table that have a beacon associated to them

extract_satellite_operators_statuses(→ pandas.DataFrame)

Extract satellite operators statuses from the satellite_operators_statuses view.

get_last_emissions_of_vessels_that_should_emit(...)

Join vessels_that_should_emit and last_positions using cfr, ircs and

get_new_malfunctions(→ pandas.DataFrame)

get_ended_malfunction_ids(→ Tuple[list, list, list, list])

prepare_new_beacon_malfunctions(→ pandas.DataFrame)

load_new_beacon_malfunctions(new_beacon_malfunctions)

update_beacon_malfunction(beacon_malfunction_id, *[, ...])

Update a beacon_malfunction stage or vessel status.

request_notification(beacon_malfunction_id, ...)

update_beacon_malfunctions_flow([...])

Module Contents

pipeline.src.flows.update_beacon_malfunctions.extract_last_positions() pandas.DataFrame[source]

Extract the last emission date of each vessel in the last_positions table.

pipeline.src.flows.update_beacon_malfunctions.extract_known_malfunctions() pandas.DataFrame[source]

Extract ongoing malfunctions in the beacon_malfunctions table.

pipeline.src.flows.update_beacon_malfunctions.extract_vessels_that_should_emit() pandas.DataFrame[source]

Extract vessels from the vessels table that have a beacon associated to them with a status of ACTIVATED or UNSUPERVISED and with a flag_state that must be monitored.

pipeline.src.flows.update_beacon_malfunctions.extract_satellite_operators_statuses() pandas.DataFrame[source]

Extract satellite operators statuses from the satellite_operators_statuses view. This is intended to be used to filter which beacon malfunction to create and / or : when a satellite operator is down, we do not want to generate malfunctions for all the beacons of this operator, we want to wait until data flows are up again.

pipeline.src.flows.update_beacon_malfunctions.get_last_emissions_of_vessels_that_should_emit(vessels_that_should_emit: pandas.DataFrame, last_positions: pandas.DataFrame) pandas.DataFrame[source]

Join vessels_that_should_emit and last_positions using cfr, ircs and external_immatriculation as join keys, using the join_on_multiple_keys logic.

last_positions of a given vessel that were emitted before the vessel’s beacon logging_datetime_utc are not taken into account : the result therefore only includes each vessel’s last emission with its current beacon. Ths is done to avoid generating beacon malfunctions on a given vessel from emission data of its previous beacon.

Parameters:
  • vessels_that_should_emit (pd.DataFrame) – DataFrame of vessels that should emit

  • last_positions (pd.DataFrame) – DataFrame of last positions

Returns:

last emissions of the input vessels with their current beacon

Return type:

pd.DataFrame

pipeline.src.flows.update_beacon_malfunctions.get_new_malfunctions(last_emissions: pandas.DataFrame, known_malfunctions: pandas.DataFrame, satellite_operators_statuses: pandas.DataFrame, malfunction_datetime_utc_threshold_at_sea: datetime.datetime, malfunction_datetime_utc_threshold_at_port: datetime.datetime) pandas.DataFrame[source]
pipeline.src.flows.update_beacon_malfunctions.get_ended_malfunction_ids(last_emissions_of_vessels_that_should_emit: pandas.DataFrame, known_malfunctions: pandas.DataFrame, malfunction_datetime_utc_threshold_at_sea: datetime.datetime) Tuple[list, list, list, list][source]
pipeline.src.flows.update_beacon_malfunctions.prepare_new_beacon_malfunctions(new_malfunctions: pandas.DataFrame) pandas.DataFrame[source]
pipeline.src.flows.update_beacon_malfunctions.load_new_beacon_malfunctions(new_beacon_malfunctions: pandas.DataFrame)[source]
pipeline.src.flows.update_beacon_malfunctions.update_beacon_malfunction(beacon_malfunction_id: int, *, new_stage: src.entities.beacon_malfunctions.BeaconMalfunctionStage | None = None, new_vessel_status: src.entities.beacon_malfunctions.BeaconMalfunctionVesselStatus | None = None, end_of_malfunction_reason: src.entities.beacon_malfunctions.EndOfMalfunctionReason | None = None)[source]

Update a beacon_malfunction stage or vessel status.

  • Exactly one of new_state or new_vessel_status must be provided

  • end_of_malfunction_reason must be provided if new_stage is provided and is equal to ARCHIVED

  • end_of_malfunction_reason cannot be be provided when new_stage is provided

    and is different from ARCHIVED

  • end_of_malfunction_reason cannot be be provided when new_vessel_status is provided

Parameters:
  • beacon_malfunction_id (int) – id of the beacon_malfunction to update

  • new_stage (beaconMalfunctionStage, optional) – stage to move the beacon malfunction to. Defaults to None.

  • new_vessel_status (beaconMalfunctionVesselStatus, optional) – vessel_status to move the beacon malfunction to. Defaults to None.

  • end_of_malfunction_reason (endOfMalfunctionReason, optional) – reason that led to the archiving of the malfunction. Defaults to None.

Raises:

ValueError

in the following cases :

  • both new_stage and new_vessel_status are provided

  • both new_stage and new_vessel_status are null

  • new_stage is ARCHIVED and no end_of_malfunction_reason is provided

  • an end_of_malfunction_reason is provided along with a new_vessel_status

  • an end_of_malfunction_reason is provided along with a new_stage other than ARCHIVED

pipeline.src.flows.update_beacon_malfunctions.request_notification(beacon_malfunction_id: int, requested_notification: src.entities.beacon_malfunctions.BeaconMalfunctionNotificationType)[source]
pipeline.src.flows.update_beacon_malfunctions.update_beacon_malfunctions_flow(max_hours_without_emission_at_sea: int = BEACONS_MAX_HOURS_WITHOUT_EMISSION_AT_SEA, max_hours_without_emission_at_port: int = BEACONS_MAX_HOURS_WITHOUT_EMISSION_AT_PORT, extract_satellite_operators_statuses_fn: Callable = extract_satellite_operators_statuses)[source]