From 503760886abb69558365099ed83929a8c4594c63 Mon Sep 17 00:00:00 2001 From: "amandine.sahl" Date: Thu, 3 Sep 2020 12:12:59 +0200 Subject: [PATCH] Modification structure, nom de champs --- backend/models/models.py | 4 ++-- backend/utils/repos.py | 7 +++++++ configs.sample/obs_taxon/detail.toml | 6 +++--- configs.sample/obs_taxon/form.toml | 4 ++-- configs.sample/obs_taxon/form_many.toml | 9 ++------- data/data_chiro.sql | 8 ++++---- data/schema_chiro.sql | 10 +++++----- data/view_synthese.sql | 18 +++++++++++++++--- data/views.sql | 2 +- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/backend/models/models.py b/backend/models/models.py index 2d7d68b..2e21ab2 100644 --- a/backend/models/models.py +++ b/backend/models/models.py @@ -111,9 +111,9 @@ class ContactTaxon(DB.Model): cd_nom = DB.Column(DB.Integer) nom_complet = DB.Column(DB.Unicode(250)) espece_incertaine = DB.Column(DB.Boolean, default=False) - id_nomenclature_activite = DB.Column(DB.Integer) - id_nomenclature_preuve_repro = DB.Column(DB.Integer) + id_nomenclature_behaviour = DB.Column(DB.Integer) id_nomenclature_preuve_repro = DB.Column(DB.Integer) + id_nomenclature_bio_condition = DB.Column(DB.Integer) id_nomenclature_observation_status = DB.Column(DB.Integer) indices_cmt = DB.Column(DB.Unicode(250)) commentaire = DB.Column(DB.Unicode(250)) diff --git a/backend/utils/repos.py b/backend/utils/repos.py index 8be702e..0661810 100644 --- a/backend/utils/repos.py +++ b/backend/utils/repos.py @@ -5,6 +5,7 @@ À déplacer à terme dans Geonature/backend/gn_monitoring """ +import logging from flask import current_app from sqlalchemy import and_ @@ -29,6 +30,8 @@ from ..utils.relations import get_updated_relations +# get the root logger +log = logging.getLogger() def process_synthese(schema_name, table_name, field_name, value): @@ -331,6 +334,10 @@ def attach_uuid_to_medium(medium, uuid_attached_row): Fonction permettant de ratacher à posteriori une liste de media à une entité ''' + # Si liste vide aucun traitement + if not medium: + return + for m in medium: m['uuid_attached_row'] = uuid_attached_row mr = TMediaRepository(data=m, id_media=m['id_media']) diff --git a/configs.sample/obs_taxon/detail.toml b/configs.sample/obs_taxon/detail.toml index eee06af..d94dff4 100644 --- a/configs.sample/obs_taxon/detail.toml +++ b/configs.sample/obs_taxon/detail.toml @@ -45,13 +45,13 @@ subSchemaAdd = 3 label = "Description indices" [[groups.fields]] - name = "id_nomenclature_activite" + name = "id_nomenclature_behaviour" thesaurus_code_type = "CHI_ACTIVITE" type = "select" label = "Activité" [[groups.fields]] - name = "id_nomenclature_eta_bio" + name = "id_nomenclature_bio_condition" thesaurus_code_type = "ETA_BIO" type = "select" label = "Etat biologique" @@ -63,7 +63,7 @@ subSchemaAdd = 3 label = "Preuves de reproduction" [[groups.fields]] - name = "id_nomenclature_activite" + name = "id_nomenclature_behaviour" thesaurus_code_type = "STATUT_OBS" type = "select" label = "Statut de l'observation" diff --git a/configs.sample/obs_taxon/form.toml b/configs.sample/obs_taxon/form.toml index 0e6cc82..500a148 100644 --- a/configs.sample/obs_taxon/form.toml +++ b/configs.sample/obs_taxon/form.toml @@ -62,7 +62,7 @@ name = "Informations" [[groups.fields]] thesaurus_code_type = "ETA_BIO" label = "Etat bio" - name = "id_nomenclature_eta_bio" + name = "id_nomenclature_bio_condition" type = "select" regne = "Animalia" group2_inpn = "Mammifères" @@ -73,7 +73,7 @@ name = "Informations" [[groups.fields]] thesaurus_code_type = "CHI_ACTIVITE" label = "Activité" - name = "id_nomenclature_activite" + name = "id_nomenclature_behaviour" type = "select" [groups.fields.options] nullable = true diff --git a/configs.sample/obs_taxon/form_many.toml b/configs.sample/obs_taxon/form_many.toml index c2501be..cc2430b 100644 --- a/configs.sample/obs_taxon/form_many.toml +++ b/configs.sample/obs_taxon/form_many.toml @@ -28,15 +28,10 @@ type = "string" label = "Taxon initial" -[[fields]] - name = "espece_incertaine" - type = "bool" - label = "Espece incertaine" - [[fields]] thesaurus_code_type = "ETA_BIO" label = "Etat bio" - name = "id_nomenclature_eta_bio" + name = "id_nomenclature_bio_condition" type = "select" regne = "Animalia" group2_inpn = "Mammifères" @@ -47,7 +42,7 @@ [[fields]] thesaurus_code_type = "CHI_ACTIVITE" label = "Activité" - name = "id_nomenclature_activite" + name = "id_nomenclature_behaviour" type = "select" [fields.options] nullable = true diff --git a/data/data_chiro.sql b/data/data_chiro.sql index 811f188..120b2fe 100644 --- a/data/data_chiro.sql +++ b/data/data_chiro.sql @@ -68,11 +68,11 @@ VALUES (ref_nomenclatures.get_id_nomenclature_type('CHI_REPRO'),'RC','Reproduction certaine','Reproduction certaine','Reproduction certaine','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE), (ref_nomenclatures.get_id_nomenclature_type('CHI_REPRO'),'RP','Reproduction probable','Reproduction probable','Reproduction probable','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE), (ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'T','Transit','Transit','Transit','monitoring_chiro','Validation en cours',0,'013.001.001',TRUE), -(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'H','Hivernage','Hivernage','Hivernage','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE), -(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'C','Chasse','Chasse','Chasse','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE), -(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'D','Déplacement','Déplacement','Déplacement','monitoring_chiro','Validation en cours',0,'013.001.004',TRUE), +(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'9','Hivernage','Hivernage','Hivernage','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE), +(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'8','ChassAlim','Chasse/alimentation','Chasse/alimentation','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE), +(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'16','Déplacement','Déplacement','Déplacement','monitoring_chiro','Validation en cours',0,'013.001.004',TRUE), (ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'SG','Sortie de gîte','Sortie de gîte','Sortie de gîte','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE), -(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'SW','Swarming','Swarming','Swarming','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE) +(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'7','Swarming','Swarming','Swarming','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE) ON CONFLICT ON CONSTRAINT unique_id_type_cd_nomenclature DO NOTHING; diff --git a/data/schema_chiro.sql b/data/schema_chiro.sql index 4ff9b91..3fa0cf1 100644 --- a/data/schema_chiro.sql +++ b/data/schema_chiro.sql @@ -128,8 +128,8 @@ CREATE TABLE monitoring_chiro.t_visite_contact_taxons ( nom_complet character varying(255), espece_incertaine boolean DEFAULT false NOT NULL, id_nomenclature_preuve_repro integer, - id_nomenclature_activite integer, - id_nomenclature_etat_bio integer, + id_nomenclature_behaviour integer, + id_nomenclature_bio_condition integer, id_nomenclature_observation_status integer, indices_cmt character varying(1000), commentaire character varying(1000), @@ -165,13 +165,13 @@ ALTER TABLE monitoring_chiro.t_contact_taxon_biometries ADD CONSTRAINT check_cor_counting_contact_life_stage CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_life_stage, 'STADE_VIE')) NOT VALID; ALTER TABLE monitoring_chiro.t_visite_contact_taxons - ADD CONSTRAINT check_t_visite_contact_taxons_etat_bio CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_etat_bio, 'ETA_BIO')) NOT VALID; + ADD CONSTRAINT check_t_visite_contact_taxons_bio_condition CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_condition, 'ETA_BIO')) NOT VALID; ALTER TABLE monitoring_chiro.t_visite_contact_taxons ADD CONSTRAINT check_t_visite_contact_taxons_preuve_repro CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_preuve_repro, 'CHI_REPRO')) NOT VALID; ALTER TABLE monitoring_chiro.t_visite_contact_taxons - ADD CONSTRAINT check_t_visite_contact_taxons_activite CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_activite, 'CHI_ACTIVITE')) NOT VALID; + ADD CONSTRAINT check_t_visite_contact_taxons_behaviour CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_behaviour, 'CHI_ACTIVITE')) NOT VALID; ALTER TABLE monitoring_chiro.t_visite_contact_taxons ADD CONSTRAINT check_t_visite_contact_taxons_obs_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_observation_status, 'STATUT_OBS')) NOT VALID; @@ -310,7 +310,7 @@ ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons ADD CONSTRAINT t_visite_contact_taxons_id_digitiser_fkey FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons - ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_activite_fkey FOREIGN KEY (id_nomenclature_activite) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_behaviour_fkey FOREIGN KEY (id_nomenclature_behaviour) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_preuve_repro_fkey FOREIGN KEY (id_nomenclature_preuve_repro) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; diff --git a/data/view_synthese.sql b/data/view_synthese.sql index d766e34..1d34c95 100644 --- a/data/view_synthese.sql +++ b/data/view_synthese.sql @@ -1,8 +1,16 @@ -DROP VIEW monitoring_chiro.v_chiro_gn_synthese ; +DROP VIEW IF EXISTS monitoring_chiro.v_chiro_gn_synthese ; CREATE OR REPLACE VIEW monitoring_chiro.v_chiro_gn_synthese AS WITH source AS ( SELECT id_source FROM gn_synthese.t_sources WHERE name_source = 'SUIVI_CHIRO' +), cor_nom_act_comp AS ( + SELECT ca.id_nomenclature as id_nomenclature_act, co.id_nomenclature as id_nomenclature_comp + FROM ref_nomenclatures.t_nomenclatures ca + JOIN ref_nomenclatures.t_nomenclatures co + ON ca.id_type = ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE') + AND + co.id_type = ref_nomenclatures.get_id_nomenclature_type('OCC_COMPORTEMENT') + AND ca.cd_nomenclature = co.cd_nomenclature ) SELECT ccc.unique_id_sinp as unique_id_sinp, @@ -15,7 +23,7 @@ SELECT v.id_nomenclature_grp_typ as id_nomenclature_grp_typ, -- MISSING FIELD id_nomenclature_obs_meth, -- NOT IN SYNTHESE v.id_nomenclature_tech_collect_campanule as id_nomenclature_tech_collect_campanule, -vct.id_nomenclature_etat_bio as id_nomenclature_bio_condition, +vct.id_nomenclature_bio_condition as id_nomenclature_bio_condition, -- MISSING FIELD id_nomenclature_bio_status, -- MISSING FIELD id_nomenclature_naturalness, -- MISSING FIELD id_nomenclature_exist_proof, @@ -24,10 +32,12 @@ ccc.id_nomenclature_life_stage, ccc.id_nomenclature_sex, ccc.id_nomenclature_obj_count, ccc.id_nomenclature_type_count, +vct.id_nomenclature_observation_status, -- MISSING FIELD id_nomenclature_observation_status, -- MISSING FIELD id_nomenclature_blurring, -- MISSING FIELD id_nomenclature_source_status, -- MISSING FIELD id_nomenclature_info_geo_type, +cnac.id_nomenclature_comp as id_nomenclature_behaviour, ccc.count_min, ccc.count_max, vct.cd_nom as cd_nom, @@ -65,4 +75,6 @@ LEFT OUTER JOIN ( ON vr.id_role = r.id_role GROUP BY id_base_visit ) obs -ON obs.id_base_visit = v.id_base_visit; +ON obs.id_base_visit = v.id_base_visit +LEFT OUTER JOIN cor_nom_act_comp cnac +ON cnac.id_nomenclature_act = vct.id_nomenclature_behaviour ; diff --git a/data/views.sql b/data/views.sql index d942c15..be0e7a2 100644 --- a/data/views.sql +++ b/data/views.sql @@ -127,7 +127,7 @@ ct.cd_nom, ct.nom_complet, ccc.nb_total_min, ccc.nb_total_max - /*espece_incertaine, id_nomenclature_preuve_repro, id_nomenclature_activite, + /*espece_incertaine, id_nomenclature_preuve_repro, id_nomenclature_behaviour, indices_cmt, commentaire, meta_create_date, meta_update_date, id_digitiser, db_suivi_id, app*/ FROM monitoring_chiro.t_visite_contact_taxons ct