-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alertes de suspicion de sous-déclaration (#3810)
## Linked issues - Resolve #3647 ## Contexte et critères de déclenchement Cette alerte vient compléter les alertes déjà existantes de FAR manquant et de DEP manquant sur les manquements aux obligations déclaratives en détectant les navires dont les déclarations sont bien présentes mais dans lesquelles les volumes de produits déclarés sont manifestement trop faibles au regard de l'effort de pêche déployé. En analysant les données VMS et déclaratives agrégées par navire sur 7 jours révolus (7 jours devant donc avoir déjà fait l'objet de déclarations FAR), on trouve : ![image](https://github.com/user-attachments/assets/b1d4e6b8-028a-4c89-8879-59a59062e561) En dessous de la droite `poids = 0.015 * effort de pêche` on trouve : - des navires sans aucune déclaration de capture sur 7 jours --> ceux-ci seront identifiés par l'alerte de FAR et / ou DEP manquant s'il n'y a pas de DEP non plus - des navires avec uniquement des FAR sans capture (FAR 0). Il peut arriver qu'un effort de pêche ne donne lieu à aucune capture mais cela reste l'exception. Si on limite aux navires qui ont fait au moins 2 jours de pêche (sur 7 jours glissants), on trouve uniquement des navires qui ne font QUE des FAR 0 et qui sont nécessairement incorrects puisque les déclarations de débarquement associées comportent, elles, des captures --> ceux-ci seront identifiés par l'alerte de suspicion de sous-déclaration - des navires qui font uniquement des déclarations avec des poids non plausibles (1kg sur chaque espèce...) --> ceux-ci seront identifiés par l'alerte de suspicion de sous-déclaration
- Loading branch information
Showing
19 changed files
with
388 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../fr/gouv/cnsp/monitorfish/domain/entities/alerts/type/SuspicionOfUnderDeclarationAlert.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.entities.alerts.type | ||
|
||
class SuspicionOfUnderDeclarationAlert( | ||
override var seaFront: String? = null, | ||
override var dml: String? = null, | ||
var riskFactor: Double? = null, | ||
) : AlertType(AlertTypeMapping.SUSPICION_OF_UNDER_DECLARATION_ALERT, seaFront, dml, 27689) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
datascience/src/pipeline/flows/suspicions_of_under_declaration_alerts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
from prefect import Flow, case, task | ||
from prefect.executors import LocalDaskExecutor | ||
|
||
from src.pipeline.entities.alerts import AlertType | ||
from src.pipeline.generic_tasks import extract | ||
from src.pipeline.shared_tasks.alerts import ( | ||
extract_active_reportings, | ||
extract_silenced_alerts, | ||
filter_alerts, | ||
load_alerts, | ||
make_alerts, | ||
) | ||
from src.pipeline.shared_tasks.control_flow import check_flow_not_running | ||
|
||
|
||
@task(checkpoint=False) | ||
def extract_suspicions_of_under_declaration(): | ||
return extract( | ||
db_name="monitorfish_remote", | ||
query_filepath="monitorfish/suspicions_of_under_declaration.sql", | ||
) | ||
|
||
|
||
with Flow("Suspicions of under-declaration", executor=LocalDaskExecutor()) as flow: | ||
flow_not_running = check_flow_not_running() | ||
with case(flow_not_running, True): | ||
vessels_with_suspicions_of_under_declaration = ( | ||
extract_suspicions_of_under_declaration() | ||
) | ||
|
||
alerts = make_alerts( | ||
vessels_with_suspicions_of_under_declaration, | ||
AlertType.SUSPICION_OF_UNDER_DECLARATION.value, | ||
AlertType.SUSPICION_OF_UNDER_DECLARATION.value, | ||
) | ||
silenced_alerts = extract_silenced_alerts( | ||
AlertType.SUSPICION_OF_UNDER_DECLARATION.value | ||
) | ||
active_reportings = extract_active_reportings( | ||
AlertType.SUSPICION_OF_UNDER_DECLARATION.value | ||
) | ||
filtered_alerts = filter_alerts(alerts, silenced_alerts, active_reportings) | ||
|
||
# Load | ||
load_alerts( | ||
filtered_alerts, | ||
alert_config_name=AlertType.SUSPICION_OF_UNDER_DECLARATION.value, | ||
) | ||
|
||
flow.file_name = Path(__file__).name |
63 changes: 63 additions & 0 deletions
63
datascience/src/pipeline/queries/monitorfish/suspicions_of_under_declaration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
WITH fishing_efforts AS ( | ||
SELECT | ||
p.internal_reference_number AS cfr, | ||
d.dml, | ||
COALESCE(p.flag_state, v.flag_state) AS flag_state, | ||
v.power * EXTRACT(epoch FROM SUM(p.time_since_previous_position)) / 3600 AS fishing_effort_kwh | ||
FROM positions p | ||
LEFT JOIN vessels v | ||
ON v.cfr = p.internal_reference_number | ||
LEFT JOIN districts d | ||
ON d.district_code = v.district_code | ||
WHERE | ||
p.date_time >= DATE_TRUNC('day', CURRENT_TIMESTAMP AT TIME ZONE 'UTC') - INTERVAL '7 days' | ||
AND p.date_time < DATE_TRUNC('day', CURRENT_TIMESTAMP AT TIME ZONE 'UTC') | ||
AND p.internal_reference_number IS NOT NULL | ||
AND p.flag_state = 'FR' | ||
AND v.length >= 12 | ||
AND v.logbook_equipment_status = 'Equipé' | ||
AND p.is_fishing | ||
GROUP BY 1, 2, 3, v.power | ||
-- Minimum number of days with fishing activity | ||
HAVING COUNT(DISTINCT DATE_TRUNC('day', date_time)) >= 2 | ||
), | ||
|
||
catches AS ( | ||
SELECT | ||
lb.cfr, | ||
COALESCE(SUM(weight), 0) AS weight | ||
FROM logbook_reports lb | ||
LEFT JOIN jsonb_array_elements(lb.value->'hauls') haul ON true | ||
LEFT JOIN LATERAL ( | ||
SELECT | ||
SUM((catch->>'weight')::DOUBLE PRECISION) AS weight | ||
FROM jsonb_array_elements(haul->'catches') catch | ||
) catch_weight ON true | ||
WHERE | ||
lb.operation_datetime_utc >= DATE_TRUNC('day', CURRENT_TIMESTAMP AT TIME ZONE 'UTC') - INTERVAL '7 days' | ||
AND lb.activity_datetime_utc >= DATE_TRUNC('day', CURRENT_TIMESTAMP AT TIME ZONE 'UTC') - INTERVAL '7 days' | ||
AND lb.log_type = 'FAR' | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
fe.cfr, | ||
lp.external_immatriculation, | ||
lp.ircs, | ||
lp.vessel_id, | ||
lp.vessel_identifier, | ||
lp.vessel_name, | ||
f.facade, | ||
fe.dml, | ||
fe.flag_state, | ||
lp.risk_factor, | ||
lp.latitude, | ||
lp.longitude | ||
FROM fishing_efforts fe | ||
JOIN catches c | ||
ON fe.cfr = c.cfr | ||
LEFT JOIN last_positions lp | ||
ON lp.cfr = fe.cfr | ||
LEFT JOIN facade_areas_subdivided f | ||
ON ST_Intersects(ST_SetSRID(ST_Point(lp.longitude, lp.latitude), 4326), f.geometry) | ||
WHERE c.weight < 0.015 * COALESCE(fe.fishing_effort_kWh, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ INSERT INTO public.vessels ( | |
declared_fishing_gears, nav_licence_expiration_date, | ||
vessel_emails, vessel_phones, proprietor_name, proprietor_phones, proprietor_emails, operator_name, operator_phones, | ||
under_charter, | ||
operator_mobile_phone, vessel_mobile_phone, vessel_telex, vessel_fax, operator_fax, operator_email | ||
operator_mobile_phone, vessel_mobile_phone, vessel_telex, vessel_fax, operator_fax, operator_email, logbook_equipment_status | ||
) VALUES | ||
( | ||
1, | ||
|
@@ -16,7 +16,7 @@ INSERT INTO public.vessels ( | |
'{GNS,GTR,LLS}', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP + INTERVAL '2 months', | ||
'{}', '{}', NULL, '{}', '{}', 'Le pêcheur de poissons', '{1234567890,"06 06 06 06 06"}', | ||
false, | ||
null, null, null, null, null, '[email protected]' | ||
null, null, null, null, null, '[email protected]', 'Equipé' | ||
), | ||
( | ||
2, | ||
|
@@ -25,7 +25,7 @@ INSERT INTO public.vessels ( | |
'{DRB,PS1}', (NOW() AT TIME ZONE 'UTC')::TIMESTAMP + INTERVAL '3 months', | ||
'{[email protected], [email protected]}', '{}', NULL, '{}', '{}', 'Le pêcheur de crevettes', '{9876543210}', | ||
true, | ||
'0600000000', null, null, '0100000000', '0200000000', '[email protected]' | ||
'0600000000', null, null, '0100000000', '0200000000', '[email protected]', 'Equipé' | ||
), | ||
( | ||
3, | ||
|
@@ -34,7 +34,7 @@ INSERT INTO public.vessels ( | |
'{OTM,OTB,OTT}', NULL, | ||
'{}', '{}', NULL, '{}', '{}', 'Le pêcheur de fonds', '{0000000000}', | ||
false, | ||
null, null, null, null, null, '[email protected]' | ||
null, null, null, null, null, '[email protected]', 'Equipé' | ||
), | ||
( | ||
4, | ||
|
@@ -43,7 +43,7 @@ INSERT INTO public.vessels ( | |
'{OTM,OTB,OTT}', NULL, | ||
'{}', '{}', NULL, '{}', '{}', 'Le pêcheur', '{11111111111}', | ||
false, | ||
null, '0111111111', null, null, null, '[email protected]' | ||
null, '0111111111', null, null, null, '[email protected]', 'Equipé' | ||
), | ||
( | ||
5, | ||
|
@@ -52,7 +52,7 @@ INSERT INTO public.vessels ( | |
'{OTT}', NULL, | ||
'{}', '{}', NULL, '{}', '{}', 'Le pêcheur qui se cache', '{2222222222}', | ||
false, | ||
null, null, null, null, null, '[email protected]' | ||
null, null, null, null, null, '[email protected]', 'Equipé' | ||
), | ||
( | ||
6, | ||
|
@@ -61,7 +61,7 @@ INSERT INTO public.vessels ( | |
'{OTT}', NULL, | ||
'{}', '{}', NULL, '{}', '{}', 'Le pêcheur qui se fait ses 4h reports', '{3333333333}', | ||
false, | ||
null, null, null, null, null, '[email protected]' | ||
null, null, null, null, null, '[email protected]', 'Equipé' | ||
), | ||
( | ||
7, | ||
|
@@ -70,6 +70,6 @@ INSERT INTO public.vessels ( | |
'{LLS}', NULL, | ||
'{}', '{}', NULL, '{}', '{}', 'Pêchou', '{9546458753}', | ||
false, | ||
null, null, null, null, null, 'target@me' | ||
null, null, null, null, null, 'target@me', 'Equipé' | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.