adapt script for get infraction
This commit is contained in:
parent
4648ec68af
commit
9ce2809804
@ -14,6 +14,24 @@ WITH photos as (
|
|||||||
FROM police.infraction_rnn
|
FROM police.infraction_rnn
|
||||||
WHERE tablename = 'photos_repeat'
|
WHERE tablename = 'photos_repeat'
|
||||||
group by json_data->>'__Submissions-id'::text
|
group by json_data->>'__Submissions-id'::text
|
||||||
|
), strip_infra as (
|
||||||
|
SELECT
|
||||||
|
inf.json_data->>'__Submissions-id' "__Submissions-id",
|
||||||
|
json_data->>'__id' "__id",
|
||||||
|
json_strip_nulls(inf.json_data) json_data
|
||||||
|
FROM police.infraction_rnn inf
|
||||||
|
WHERE inf.tablename = 'multiple_infract'
|
||||||
|
), key_infra as (
|
||||||
|
select
|
||||||
|
json_data->>'__Submissions-id' "__Submissions-id",
|
||||||
|
json_data->>'__id' "__id",
|
||||||
|
json_object_keys(json_data::json) data_keys
|
||||||
|
from strip_infra
|
||||||
|
), key_infra_agg as (
|
||||||
|
select
|
||||||
|
"__Submissions-id","__id", array_agg(data_keys) data_keys
|
||||||
|
from key_infra
|
||||||
|
group by 2,1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
inf.json_data->>'__id'::text id_infraction,
|
inf.json_data->>'__id'::text id_infraction,
|
||||||
@ -24,9 +42,16 @@ SELECT
|
|||||||
autre_catego_sensi,
|
autre_catego_sensi,
|
||||||
autre_type_sanct,
|
autre_type_sanct,
|
||||||
inf.json_data->>'catego_infract'::text catego_infract,
|
inf.json_data->>'catego_infract'::text catego_infract,
|
||||||
|
inf.json_data->>key_infra_agg.data_keys[1] nature_infra,
|
||||||
|
case when SPLIT_PART(key_infra_agg.data_keys[3],'_',1) = 'natinf'
|
||||||
|
then inf.json_data->>key_infra_agg.data_keys[2]
|
||||||
|
else null
|
||||||
|
end code_catego,
|
||||||
|
case when SPLIT_PART(key_infra_agg.data_keys[3],'_',1) = 'natinf'
|
||||||
|
then inf.json_data->>key_infra_agg.data_keys[3]
|
||||||
|
else inf.json_data->>key_infra_agg.data_keys[2]
|
||||||
|
end code_infra,
|
||||||
inf.json_data->>'descrpt_infract'::text descrpt_infract,
|
inf.json_data->>'descrpt_infract'::text descrpt_infract,
|
||||||
inf.json_data->>'nat_aff_niv_3'::text nat_aff_niv_3,
|
|
||||||
inf.json_data->>'natinf_rn'::text natinf_rn,
|
|
||||||
"Commentaire_remarque_nombre_de_tentes",
|
"Commentaire_remarque_nombre_de_tentes",
|
||||||
"Conformit_du_contr_le",
|
"Conformit_du_contr_le",
|
||||||
"day" "date",
|
"day" "date",
|
||||||
@ -44,12 +69,12 @@ SELECT
|
|||||||
"updatedAt" date_maj,
|
"updatedAt" date_maj,
|
||||||
st_force2d(st_geomfromgeojson(replace(COALESCE(geom,point_carte),'\\','')))::geometry(geometry, 4326) AS geom
|
st_force2d(st_geomfromgeojson(replace(COALESCE(geom,point_carte),'\\','')))::geometry(geometry, 4326) AS geom
|
||||||
FROM police.infraction_rnn_submissions_data AS sub
|
FROM police.infraction_rnn_submissions_data AS sub
|
||||||
JOIN police.infraction_rnn inf ON sub.data_id::text = inf.json_data->>'__Submissions-id'::text
|
JOIN strip_infra inf ON sub.data_id::text = inf."__Submissions-id"::text
|
||||||
and inf.tablename = 'multiple_infract'
|
join key_infra_agg on inf.__id = key_infra_agg.__id
|
||||||
JOIN photos ph ON sub.data_id::text = ph."__Submissions-id"::text
|
JOIN photos ph ON sub.data_id::text = ph."__Submissions-id"::text
|
||||||
ORDER BY 2,1 ;
|
ORDER BY 2,1 ;
|
||||||
|
|
||||||
|
GRANT SELECT ON TABLE police.infraction_rnn TO grp_police;
|
||||||
'''
|
'''
|
||||||
|
|
||||||
with con_odk.begin() as cnx:
|
with con_odk.begin() as cnx:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user