Skip to content

Commit

Permalink
Add secmar_json_resultats_humain_categorie
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Feb 24, 2024
1 parent 28c17ad commit 37a23e0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
26 changes: 25 additions & 1 deletion airflow/dags/download_secmar_json_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def secmar_json_sql_task(dag, filename):
# Flotteurs
"secmar_json_resultat_flotteur_codes",
"secmar_json_flotteurs_type_flotteur",
# Résultats humain
"secmar_json_resultats_humain_categorie",
]:
task = secmar_json_sql_task(dag, code)
task.set_upstream(start_create_codes_tables)
Expand Down Expand Up @@ -260,7 +262,28 @@ def secmar_json_sql_task(dag, filename):
check_completeness_snosan_json_operative_event.set_downstream(snosan_json_operations)

snosan_json_resultats_humain = secmar_json_sql_task(dag, "snosan_json_resultats_humain")
snosan_json_resultats_humain.set_upstream(insert_snosan_json_unique)
for column in ["categorie"]:
table = "secmar_json_resultats_humain_{column}".format(column=column)
task = PostgresOperator(
task_id="check_completness_resultats_humain_{column}".format(column=column),
sql="""
select count(1) = 0
from (
select distinct personne->>'{column}'
from (
select jsonb_array_elements(data->'personnes') personne
from snosan_json_unique
) _
where personne->>'{column}' not in (select seamis from {table})
) _
""".format(
column=column, table=table
),
postgres_conn_id="postgresql_local",
dag=dag,
)
task.set_upstream(end_create_codes_tables)
task.set_downstream(snosan_json_resultats_humain)

snosan_json_moyens = secmar_json_sql_task(dag, "snosan_json_moyens")
for column in ["autorite", "type", "categorie"]:
Expand Down Expand Up @@ -323,6 +346,7 @@ def secmar_json_sql_task(dag, filename):
snosan_json_flotteurs.set_upstream(check_completness_secmar_json_resultat_flotteur)

snosan_json_evenement = secmar_json_sql_task(dag, "snosan_json_evenement")
snosan_json_evenement.set_upstream(start_create_codes_tables)
check_completeness_count_rows_secmar_json_evenement = CheckOperator(
task_id="check_completeness_count_rows_secmar_json_evenement",
sql="""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
DROP TABLE IF EXISTS secmar_json_resultats_humain_categorie;

CREATE TABLE secmar_json_resultats_humain_categorie (
seamis varchar primary key,
secmar varchar
);

CREATE INDEX ON secmar_json_resultats_humain_categorie(secmar);

INSERT INTO secmar_json_resultats_humain_categorie
(seamis, secmar)
VALUES
('AUTRE', 'Autre'),
('PLAISANCIER', 'Plaisancier français'),
('PRATIQUANT_LOISIRS_NAUTIQUES', 'Pratiquant loisirs nautiques'),
('PROFESSIONNEL', 'Commerce français'),
('MIGRANT', 'Migrant'),
('PECHEUR_PRO', 'Pêcheur français'),
('PECHEUR_AMATEUR', 'Pêcheur amateur')
;
11 changes: 2 additions & 9 deletions opendata/sql/secmar_json/snosan_json_resultats_humain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ create index on snosan_json_resultats_humain(chrono);
insert into snosan_json_resultats_humain (chrono, categorie_personne, resultat_humain, nombre, dont_nombre_blesse)
select
t.chrono chrono,
case
when personne->>'categorie' = 'PLAISANCIER' then 'Plaisancier français'
when personne->>'categorie' = 'PRATIQUANT_LOISIRS_NAUTIQUES' then 'Pratiquant loisirs nautiques'
when personne->>'categorie' = 'PROFESSIONNEL' then 'Commerce français'
when personne->>'categorie' = 'MIGRANT' then 'Migrant'
when personne->>'categorie' = 'PECHEUR_PRO' then 'Pêcheur français'
when personne->>'categorie' = 'PECHEUR_AMATEUR' then 'Pêcheur amateur'
else 'Autre'
end categorie_personne,
coalesce(rhc.secmar, 'Autre') categorie_personne,
case
when personne->'resultat' ? 'DECEDE' then 'Personne décédée'
when personne->'resultat' ? 'DISPARU' then 'Personne disparue'
Expand All @@ -41,4 +33,5 @@ from (
jsonb_array_elements(data->'personnes') personne
from snosan_json_unique
) t
left join secmar_json_resultats_humain_categorie rhc on rhc.seamis = personne->>'categorie'
where personne->>'isInvolved' = 'true' and personne->>'principalImpl' = 'true';

0 comments on commit 37a23e0

Please sign in to comment.