Skip to content

Commit

Permalink
Add tide data to operations_stats #110
Browse files Browse the repository at this point in the history
* Add tide data to operations_stats

* Add maree_categorie column
  • Loading branch information
AntoineAugusti authored Oct 22, 2018
1 parent 3623e10 commit d26d698
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 8 deletions.
12 changes: 12 additions & 0 deletions airflow/dags/extract_secmar.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def insert_operations_stats_fn(**kwargs):
def insert_moyens_snsm_fn(**kwargs):
return execute_sql_file('moyens_snsm')

def set_tide_data_fn(**kwargs):
return execute_sql_file('compute_tide')


def execute_sql_file(filename):
path = helpers.opendata_sql_path(filename)
Expand Down Expand Up @@ -241,6 +244,15 @@ def embulk_import(dag, table):
set_operations_stats_extra_attributes.set_upstream(insert_operations_stats)
set_operations_stats_extra_attributes.set_downstream(start_checks)

set_tide_data = PythonOperator(
task_id='set_tide_data',
python_callable=set_tide_data_fn,
provide_context=True,
dag=dag
)
set_tide_data.set_upstream(set_operations_stats_extra_attributes)
set_tide_data.set_downstream(start_checks)

# Check consistency of data
queries = {
'operations_operations_stats': '''
Expand Down
4 changes: 3 additions & 1 deletion opendata/config/drop_columns.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"nombre_moyens_aeriens_engages",
"duree_engagement_moyens_nautiques_minutes",
"duree_engagement_moyens_terrestres_minutes",
"duree_engagement_moyens_aeriens_minutes"
"duree_engagement_moyens_aeriens_minutes",
"maree_port",
"maree_coefficient"
],
"resultats_humain":[

Expand Down
19 changes: 19 additions & 0 deletions opendata/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,25 @@ components:
description: Si l'opération se déroule dans une zone d'un dispositif de séparation du trafic, le nom de cette zone.
example: dst-dover
nullable: true
maree_port:
type: string
description: Le nom du port utilisé comme référence pour connaitre le coefficient moyen de marée de la journée de l'opération. Les marées sont renseignées pour les opérations coordonnées par les CROSS en Atlantique et Manche, lorsque l'opération est géolocalisée et que celle-ci se trouve à moins de 20 kilomètres de la plus proche côte.
example: Dieppe
nullable: true
maree_coefficient:
type: integer
format: int32
description: Le coefficient moyen de marée de la journée de l'opération. Les marées sont renseignées pour les opérations coordonnées par les CROSS en Atlantique et Manche, lorsque l'opération est géolocalisée et que celle-ci se trouve à moins de 20 kilomètres de la plus proche côte.
nullable: true
example: 70
minimum: 20
maximum: 120
maree_categorie:
type: string
description: Le nom de la catégorie de la marée pour l'opération.
example: '96-120'
enum: ['20-45', '46-70', '71-95', '96-120']
nullable: true
nombre_personnes_blessees:
type: integer
format: int32
Expand Down
50 changes: 50 additions & 0 deletions opendata/sql/compute_tide.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
update operations_stats set
maree_port = t.maree_port,
maree_coefficient = t.maree_coefficient,
maree_categorie = t.maree_categorie
from (
select
operation_id,
t.port as maree_port,
coefficient as maree_coefficient,
case
when coefficient between 20 and 45 then '20-45'
when coefficient between 46 and 70 then '46-70'
when coefficient between 71 and 95 then '71-95'
when coefficient between 95 and 120 then '96-120'
else null
end maree_categorie
from (
select distinct
operation_id,
date,
first_value(port) over (partition by operation_id order by distance_km asc) port,
first_value(port_code) over (partition by operation_id order by distance_km asc) code
from (
SELECT
op.operation_id,
op.date,
p.code as port_code,
p.name as port,
ST_Distance(
p.point,
op.point
)/1000 distance_km
FROM ports p
join (
select
op.operation_id,
op.point,
stats.date
from operations_points op
join operations_stats stats on stats.operation_id = op.operation_id
join operations o on o.operation_id = op.operation_id
where op.point is not null
and coalesce(stats.distance_cote_metres, 0) < 20000
and o."cross" not in ('Antilles-Guyane', 'Corse', 'Guadeloupe', 'Guyane', 'La Garde', 'La Réunion', 'Martinique', 'Mayotte', 'Nouvelle-Calédonie', 'Polynésie')
) op on true
) t
) t
join tide_data td on td.date = t.date and td.port = t.code
) t
where operations_stats.operation_id = t.operation_id;
2 changes: 2 additions & 0 deletions opendata/sql/insert_operations_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ select
op.nom_stm nom_stm,
op.est_dans_dst est_dans_dst,
op.nom_dst nom_dst,
null maree_port,
null maree_coefficient,
coalesce(rh.nombre_personnes_blessees, 0) nombre_personnes_blessees,
coalesce(rh.nombre_personnes_assistees, 0) nombre_personnes_assistees,
coalesce(rh.nombre_personnes_decedees, 0) nombre_personnes_decedees,
Expand Down
3 changes: 3 additions & 0 deletions opendata/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ CREATE TABLE public.operations_stats (
"nom_stm" varchar(50),
"est_dans_dst" boolean not null,
"nom_dst" varchar(50),
"maree_port" varchar(50),
"maree_coefficient" smallint,
"maree_categorie" varchar(6),
"nombre_personnes_blessees" smallint not null,
"nombre_personnes_assistees" smallint not null,
"nombre_personnes_decedees" smallint not null,
Expand Down
16 changes: 9 additions & 7 deletions opendata/tests/opendata/test_operations_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ def test_columns(self):
self.assertEquals(
OperationsStatsTransformer('/tmp/fake').columns_to_drop(),
[
"concerne_snosan",
"nombre_moyens_nautiques_engages",
"nombre_moyens_terrestres_engages",
"nombre_moyens_aeriens_engages",
"duree_engagement_moyens_nautiques_minutes",
"duree_engagement_moyens_terrestres_minutes",
"duree_engagement_moyens_aeriens_minutes"
"concerne_snosan",
"nombre_moyens_nautiques_engages",
"nombre_moyens_terrestres_engages",
"nombre_moyens_aeriens_engages",
"duree_engagement_moyens_nautiques_minutes",
"duree_engagement_moyens_terrestres_minutes",
"duree_engagement_moyens_aeriens_minutes",
"maree_port",
"maree_coefficient"
]
)

Expand Down

0 comments on commit d26d698

Please sign in to comment.