pipeline.src.flows.update_beacon_malfunctions ============================================= .. py:module:: pipeline.src.flows.update_beacon_malfunctions Functions --------- .. autoapisummary:: pipeline.src.flows.update_beacon_malfunctions.extract_last_positions pipeline.src.flows.update_beacon_malfunctions.extract_known_malfunctions pipeline.src.flows.update_beacon_malfunctions.extract_vessels_that_should_emit pipeline.src.flows.update_beacon_malfunctions.extract_satellite_operators_statuses pipeline.src.flows.update_beacon_malfunctions.get_last_emissions_of_vessels_that_should_emit pipeline.src.flows.update_beacon_malfunctions.get_new_malfunctions pipeline.src.flows.update_beacon_malfunctions.get_ended_malfunction_ids pipeline.src.flows.update_beacon_malfunctions.prepare_new_beacon_malfunctions pipeline.src.flows.update_beacon_malfunctions.load_new_beacon_malfunctions pipeline.src.flows.update_beacon_malfunctions.update_beacon_malfunction pipeline.src.flows.update_beacon_malfunctions.request_notification pipeline.src.flows.update_beacon_malfunctions.update_beacon_malfunctions_flow Module Contents --------------- .. py:function:: extract_last_positions() -> pandas.DataFrame Extract the last emission date of each vessel in the `last_positions` table. .. py:function:: extract_known_malfunctions() -> pandas.DataFrame Extract ongoing malfunctions in the `beacon_malfunctions` table. .. py:function:: extract_vessels_that_should_emit() -> pandas.DataFrame 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. .. py:function:: extract_satellite_operators_statuses() -> pandas.DataFrame 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. .. py:function:: get_last_emissions_of_vessels_that_should_emit(vessels_that_should_emit: pandas.DataFrame, last_positions: pandas.DataFrame) -> pandas.DataFrame 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. :param vessels_that_should_emit: DataFrame of vessels that should emit :type vessels_that_should_emit: pd.DataFrame :param last_positions: DataFrame of last positions :type last_positions: pd.DataFrame :returns: last emissions of the input vessels with their current beacon :rtype: pd.DataFrame .. py:function:: 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 .. py:function:: 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] .. py:function:: prepare_new_beacon_malfunctions(new_malfunctions: pandas.DataFrame) -> pandas.DataFrame .. py:function:: load_new_beacon_malfunctions(new_beacon_malfunctions: pandas.DataFrame) .. py:function:: update_beacon_malfunction(beacon_malfunction_id: int, *, new_stage: Optional[src.entities.beacon_malfunctions.BeaconMalfunctionStage] = None, new_vessel_status: Optional[src.entities.beacon_malfunctions.BeaconMalfunctionVesselStatus] = None, end_of_malfunction_reason: Optional[src.entities.beacon_malfunctions.EndOfMalfunctionReason] = None) 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 :param beacon_malfunction_id: id of the beacon_malfunction to update :type beacon_malfunction_id: int :param new_stage: stage to move the beacon malfunction to. Defaults to None. :type new_stage: beaconMalfunctionStage, optional :param new_vessel_status: vessel_status to move the beacon malfunction to. Defaults to None. :type new_vessel_status: beaconMalfunctionVesselStatus, optional :param end_of_malfunction_reason: reason that led to the archiving of the malfunction. Defaults to None. :type end_of_malfunction_reason: endOfMalfunctionReason, optional :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` .. py:function:: request_notification(beacon_malfunction_id: int, requested_notification: src.entities.beacon_malfunctions.BeaconMalfunctionNotificationType) .. py:function:: 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)