56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
from pycen import con_odk
|
|
|
|
sql = '''
|
|
DROP VIEW IF EXISTS police.v_infraction_rnn;
|
|
|
|
CREATE VIEW police.v_infraction_rnn AS
|
|
WITH photos as (
|
|
SELECT
|
|
json_data->>'__Submissions-id'::text "__Submissions-id",
|
|
json_agg('https://odk2.cen-isere.fr/v1/projects/6/forms/infraction_rnn/submissions/'||(json_data->>'__Submissions-id'::text)||'/attachments/'||(json_data->>'photos')::text) photos
|
|
FROM police.infraction_rnn
|
|
WHERE tablename = 'photos_repeat'
|
|
group by json_data->>'__Submissions-id'::text
|
|
)
|
|
SELECT
|
|
inf.json_data->>'__id'::text id_infraction,
|
|
split_part(sub.data_id,':',2)::uuid id_submission,
|
|
"submitterName" digitiser,
|
|
catego_controle,
|
|
catego_sensibil,
|
|
autre_catego_sensi,
|
|
autre_type_sanct,
|
|
inf.json_data->>'catego_infract'::text catego_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",
|
|
"Conformit_du_contr_le",
|
|
"day" "date",
|
|
"heure",
|
|
infract_nb,
|
|
nat_operation,
|
|
nature_pers,
|
|
nb_pers_control,
|
|
nb_pers_sensibil,
|
|
nb_verb,
|
|
nom_agent,
|
|
type_sanct,
|
|
ph.photos,
|
|
"submissionDate" date_saisie,
|
|
"updatedAt" date_maj,
|
|
st_force2d(st_geomfromgeojson(replace(COALESCE(geom,point_carte),'\\','')))::geometry(geometry, 4326) AS geom
|
|
FROM police.infraction_rnn_submissions_data AS sub
|
|
JOIN police.infraction_rnn inf ON sub.data_id::text = inf.json_data->>'__Submissions-id'::text
|
|
and inf.tablename = 'multiple_infract'
|
|
JOIN photos ph ON sub.data_id::text = ph."__Submissions-id"::text
|
|
ORDER BY 2,1 ;
|
|
|
|
|
|
'''
|
|
|
|
with con_odk.begin() as cnx:
|
|
cnx.execute(sql) |