Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Affichage des organismes #157

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions data/atlas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ create index on atlas.vm_taxref (nom_complet);
create index on atlas.vm_taxref (nom_valide);


--Tous les organismes

--DROP MATERIALIZED VIEW atlas.vm_organismes;
CREATE MATERIALIZED VIEW atlas.vm_organismes AS
SELECT o.id_organisme,
o.nom_organisme
FROM synthese.bib_organismes o;
create unique index on atlas.vm_organismes (id_organisme);



--Toutes les observations

--DROP materialized view atlas.vm_observations;
Expand All @@ -21,6 +32,7 @@ CREATE MATERIALIZED VIEW atlas.vm_observations AS
s.insee,
s.dateobs,
s.observateurs,
s.id_organisme,
s.altitude_retenue,
s.the_geom_point::geometry('POINT',3857),
s.effectif_total,
Expand Down
17 changes: 17 additions & 0 deletions data/atlas_usershub.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Création de la table fille en foreign data wrapper, connectée à la base mère de UsersHub (usershubdbserver)


CREATE FOREIGN TABLE synthese.bib_organismes
( id_organisme integer NOT NULL,
nom_organisme character varying(100) NOT NULL,
adresse_organisme character varying(128),
cp_organisme character varying(5),
ville_organisme character varying(100),
tel_organisme character varying(14),
fax_organisme character varying(14),
email_organisme character varying(100)
)
SERVER usershubdbserver
OPTIONS (schema_name 'utilisateurs', table_name 'bib_organismes');
ALTER TABLE synthese.bib_organismes OWNER TO myuser;
GRANT ALL ON TABLE synthese.bib_organismes TO myuser;
45 changes: 45 additions & 0 deletions install_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ then
sudo -n -u postgres -s psql -d $db_name -c "CREATE USER MAPPING FOR $owner_atlas SERVER geonaturedbserver OPTIONS (user '$atlas_source_user', password '$atlas_source_pass') ;" &>> log/install_db.log
fi

# Si j'utilise UsersHub ($usershub_source = True), alors je créé les connexions en FWD à la BDD UsersHub
if $usershub_source
then
echo "Ajout du FDW et connexion à la BDD mère UsersHub"
sudo -n -u postgres -s psql -d $db_name -c "CREATE EXTENSION IF NOT EXISTS postgres_fdw;" &>> log/install_db.log
sudo -n -u postgres -s psql -d $db_name -c "CREATE SERVER usershubdbserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '$dbusers_source_host', dbname '$dbusers_source_name', port '$dbusers_source_port');" &>> log/install_db.log
sudo -n -u postgres -s psql -d $db_name -c "ALTER SERVER usershubdbserver OWNER TO $owner_atlas;" &>> log/install_db.log
sudo -n -u postgres -s psql -d $db_name -c "CREATE USER MAPPING FOR $owner_atlas SERVER usershubdbserver OPTIONS (user '$atlas_dbusers_source_user', password '$atlas_dbusers_source_pass') ;" &>> log/install_db.log
fi


# Création des schémas de la BDD

sudo -n -u postgres -s psql -d $db_name -c "CREATE SCHEMA atlas AUTHORIZATION "$owner_atlas";" &>> log/install_db.log
Expand Down Expand Up @@ -167,6 +178,40 @@ then
rm -R data/taxonomie

fi

# Si j'utilise UsersHub ($usershub_source = True), alors je crée la table fille en FDW connectée à la BDD de UsersHub
if $usershub_source
then
# Creation des tables filles en FWD
echo "Création de la connexion a GeoNature"
sudo cp data/atlas_usershub.sql /tmp/atlas_usershub.sql
sudo sed -i "s/myuser;$/$owner_atlas;/" /tmp/atlas_usershub.sql
sudo -n -u postgres -s psql -d $db_name -f /tmp/atlas_usershub.sql &>> log/install_db.log
# Sinon je créé une table synthese.bib_organismes avec 3 organismes exemple
else
echo "Création de la table exemple bib_organismes"
sudo -n -u postgres -s psql -d $db_name -c "CREATE TABLE synthese.bib_organismes
(
id_organisme integer PRIMARY KEY,
nom_organisme character varying(100) NOT NULL,
adresse_organisme character varying(128) ,
cp_organisme character varying(5) ,
ville_organisme character varying(100) ,
tel_organisme character varying(14) ,
fax_organisme character varying(14) ,
email_organisme character varying(100)
);
INSERT INTO synthese.bib_organismes
(id_organisme, nom_organisme, adresse_organisme, cp_organisme, ville_organisme, tel_organisme, fax_organisme, email_organisme)
VALUES (1, 'PNF', '', '', 'Montpellier', '', '', '');
INSERT INTO synthese.bib_organismes
(id_organisme, nom_organisme, adresse_organisme, cp_organisme, ville_organisme, tel_organisme, fax_organisme, email_organisme)
VALUES (2, 'Parc National des Ecrins', 'Domaine de Charance', '05000', 'GAP', '04 92 40 20 10', '', '');
INSERT INTO synthese.bib_organismes
(id_organisme, nom_organisme, adresse_organisme, cp_organisme, ville_organisme, tel_organisme, fax_organisme, email_organisme)
VALUES VALUES (99, 'Autre', '', '', '', '', '', '');" &>> log/install_db.log
sudo -n -u postgres -s psql -d $db_name -c "ALTER TABLE synthese.bib_organismes OWNER TO "$owner_atlas";"
fi

# Creation des Vues Matérialisées (et remplacement éventuel des valeurs en dur par les paramètres)
echo "Création des vues materialisées"
Expand Down
13 changes: 12 additions & 1 deletion main/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ def ficheEspece(cd_ref):
config.ATTR_MILIEU, config.ATTR_CHOROLOGIE
)
observers = vmObservationsRepository.getObservers(connection, cd_ref)
orgas = vmObservationsRepository.getOrgasObservations(connection, cd_ref)

configuration = base_configuration.copy()
configuration.update({
'LIMIT_FICHE_LISTE_HIERARCHY': config.LIMIT_FICHE_LISTE_HIERARCHY,
'PATRIMONIALITE': config.PATRIMONIALITE,
'PROTECTION': config.PROTECTION,
'AFFICHAGE_ORGAS_OBS_FICHEESP': config.AFFICHAGE_ORGAS_OBS_FICHEESP,
'GLOSSAIRE': config.GLOSSAIRE,
'AFFICHAGE_MAILLE': config.AFFICHAGE_MAILLE,
'ZOOM_LEVEL_POINT': config.ZOOM_LEVEL_POINT,
Expand Down Expand Up @@ -187,6 +189,7 @@ def ficheEspece(cd_ref):
articles=articles,
taxonDescription=taxonDescription,
observers=observers,
orgas=orgas,
configuration=configuration
)

Expand All @@ -207,7 +210,7 @@ def ficheCommune(insee):
observations = vmObservationsRepository.lastObservationsCommune(
connection, config.NB_LAST_OBS, insee
)

orgas = vmObservationsRepository.getOrgasCommunes(connection, insee)
observers = vmObservationsRepository.getObserversCommunes(
connection, insee
)
Expand All @@ -216,6 +219,7 @@ def ficheCommune(insee):
configuration.update({
'NB_LAST_OBS': config.NB_LAST_OBS,
'AFFICHAGE_MAILLE': config.AFFICHAGE_MAILLE,
'AFFICHAGE_ORGAS_OBS_FICHECOMM': config.AFFICHAGE_ORGAS_OBS_FICHECOMM,
'MAP': config.MAP,
'MYTYPE': 1,
'PATRIMONIALITE': config.PATRIMONIALITE,
Expand All @@ -232,6 +236,7 @@ def ficheCommune(insee):
communesSearch=communesSearch,
observations=observations,
observers=observers,
orgas=orgas,
configuration=configuration
)

Expand All @@ -246,6 +251,7 @@ def ficheRangTaxonomie(cd_ref):
communesSearch = vmCommunesRepository.getAllCommunes(session)
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(session, cd_ref)
observers = vmObservationsRepository.getObservers(connection, cd_ref)
orgas = vmObservationsRepository.getOrgasObservations(connection, cd_ref)

connection.close()
session.close()
Expand All @@ -254,6 +260,7 @@ def ficheRangTaxonomie(cd_ref):
configuration.update({
'LIMIT_FICHE_LISTE_HIERARCHY': config.LIMIT_FICHE_LISTE_HIERARCHY,
'MYTYPE': 0,
'AFFICHAGE_ORGAS_OBS_FICHETAXO': config.AFFICHAGE_ORGAS_OBS_FICHETAXO,
'PATRIMONIALITE': config.PATRIMONIALITE,
'PROTECTION': config.PROTECTION,
})
Expand All @@ -265,6 +272,7 @@ def ficheRangTaxonomie(cd_ref):
communesSearch=communesSearch,
taxonomyHierarchy=taxonomyHierarchy,
observers=observers,
orgas=orgas,
configuration=configuration
)

Expand All @@ -278,6 +286,7 @@ def ficheGroupe(groupe):
listTaxons = vmTaxonsRepository.getTaxonsGroup(connection, groupe)
communesSearch = vmCommunesRepository.getAllCommunes(session)
observers = vmObservationsRepository.getGroupeObservers(connection, groupe)
orgas = vmObservationsRepository.getGroupeOrgas(connection, groupe)

session.close()
connection.close()
Expand All @@ -286,6 +295,7 @@ def ficheGroupe(groupe):
configuration.update({
'LIMIT_FICHE_LISTE_HIERARCHY': config.LIMIT_FICHE_LISTE_HIERARCHY,
'MYTYPE': 0,
'AFFICHAGE_ORGAS_OBS_FICHEGROUPE': config.AFFICHAGE_ORGAS_OBS_FICHEGROUPE,
'PATRIMONIALITE': config.PATRIMONIALITE,
'PROTECTION': config.PROTECTION
})
Expand All @@ -297,6 +307,7 @@ def ficheGroupe(groupe):
referenciel=groupe,
groups=groups,
observers=observers,
orgas=orgas,
configuration=configuration
)

Expand Down
17 changes: 17 additions & 0 deletions main/configuration/config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ ATTR_YOUTUBE = 7
ATTR_DAILYMOTION = 8
ATTR_VIMEO = 9

# Afficher les organismes ayant fourni les données sur fiche espece. Affichage True/False
AFFICHAGE_ORGAS_OBS_FICHEESP = True

############################################
#### FICHE COMMUNE ET RANG TAXONOMIQUE #####
############################################
Expand All @@ -178,6 +181,20 @@ PATRIMONIALITE = {
}
}


# Afficher les organismes ayant fourni les données sur fiche commune. Affichage True/False
AFFICHAGE_ORGAS_OBS_FICHECOMM = True

# Afficher les organismes ayant fourni les données sur fiche rang taxonomique. Affichage True/False
AFFICHAGE_ORGAS_OBS_FICHETAXO = True

#######################
#### FICHE GROUPE #####
#######################

# Afficher les organismes ayant fourni les données sur fiche groupe. Affichage True/False
AFFICHAGE_ORGAS_OBS_FICHEGROUPE = True

#############################
#### Pages statistiques #####
#############################
Expand Down
24 changes: 24 additions & 0 deletions main/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ taxhub_release=1.3.2
# GeoNature-atlas est-il connecté à une BDD GeoNature ?
geonature_source=true

# GeoNature-atlas est-il connecté à une BDD UsersHub ?
usershub_source=true

################################################
##### CONNEXION A LA BDD USERSHUB SOURCE ######
################################################
# Necessaire uniquement si on veut se connecter à la BDD source UsersHub en foreign data wrapper

# Host de la BDD UsersHub source
dbusers_source_host=localhost

# Port de la BDD UsersHub source
dbusers_source_port=5432

# Nom de la BDD UsersHub source
dbusers_source_name=usershubdb

# Nom de l'utilisateur atlas dans la BDD UsersHub source (lecture seule)
atlas_dbusers_source_user=geonatuser

# Pass de l'utilisateur atlas dans la BDD UsersHub source (lecture seule)
atlas_dbusers_source_pass=monpassachanger


################################################
##### CONNEXION A LA BDD GEONATURE SOURCE ######
################################################
Expand Down
20 changes: 20 additions & 0 deletions main/modeles/entities/vmOrganismes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding: utf-8
#from sqlalchemy import Column, Integer, MetaData, String, Table
#from geoalchemy2.types import Geometry
#from sqlalchemy.sql.sqltypes import NullType
#from sqlalchemy.orm import mapper
#from sqlalchemy.ext.declarative import declarative_base
#from ...utils import engine

#metadata = MetaData()
#Base = declarative_base()

class VmMois(Base):
__table__ = Table(
'vm_organismes', metadata,
Column('id_organisme', Integer, primary_key=True, unique=True),
Column('nom_organisme', String(250)),
schema='atlas', autoload=True, autoload_with=engine
)


9 changes: 8 additions & 1 deletion main/modeles/repositories/vmObservationsMaillesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ def getObservationsMaillesChilds(connection, cd_ref):
sql = """SELECT
obs.id_maille,
obs.geojson_maille,
a.nom_organisme AS orgaobs,
o.dateobs,
extract(YEAR FROM o.dateobs) as annee
FROM atlas.vm_observations_mailles obs
JOIN atlas.vm_observations o ON o.id_observation = obs.id_observation
LEFT JOIN atlas.vm_organismes a ON a.id_organisme = o.id_organisme
WHERE obs.cd_ref in (
SELECT * FROM atlas.find_all_taxons_childs(:thiscdref)
)
Expand All @@ -27,6 +29,7 @@ def getObservationsMaillesChilds(connection, cd_ref):
'nb_observations': 1,
'annee': o.annee,
'dateobs': str(o.dateobs),
'orga_obs': o.orgaobs,
'geojson_maille': ast.literal_eval(o.geojson_maille)
}
tabObs.append(temp)
Expand Down Expand Up @@ -122,12 +125,15 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref):
sql = """
SELECT
o.cd_ref, t.id_maille, t.geojson_maille,
extract(YEAR FROM o.dateobs) as annee
extract(YEAR FROM o.dateobs) as annee,
a.nom_organisme AS orgaobs
FROM atlas.vm_observations o
JOIN atlas.vm_communes c
ON ST_INTERSECTS(o.the_geom_point, c.the_geom)
JOIN atlas.t_mailles_territoire t
ON ST_INTERSECTS(t.the_geom, o.the_geom_point)
LEFT JOIN atlas.vm_organismes a
ON a.id_organisme = o.id_organisme
WHERE o.cd_ref = :thiscdref AND c.insee = :thisInsee
ORDER BY id_maille
"""
Expand All @@ -140,6 +146,7 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref):
'id_maille': o.id_maille,
'nb_observations': 1,
'annee': o.annee,
'orga_obs': o.orgaobs,
'geojson_maille': ast.literal_eval(o.geojson_maille)
}
tabObs.append(temp)
Expand Down
Loading