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

Add home territory #587

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion atlas/atlasAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def getObservationsGenericApi(cd_ref: int):
[type]: [description]
"""
session = db.session
if current_app.config["AFFICHAGE_MAILLE"]:
if current_app.config["AFFICHAGE_TERRITOIRE_OBS"]:
observations = vmObservationsMaillesRepository.getObservationsMaillesTerritorySpecies(
session,
cd_ref,
)
elif current_app.config["AFFICHAGE_MAILLE"]:
observations = vmObservationsMaillesRepository.getObservationsMaillesChilds(
session,
cd_ref,
Expand Down
19 changes: 16 additions & 3 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def indexMedias(image):
)


def get_territory_mailles_obs(connection):
current_app.logger.debug("start AFFICHAGE_TERRITORY")
observations = vmObservationsMaillesRepository.territoryObservationsMailles(connection)
current_app.logger.debug("end AFFICHAGE_TERRITORY")
return observations


@main.route("/", methods=["GET", "POST"])
def index():
session = db.session
Expand All @@ -180,6 +187,8 @@ def index():
current_app.config["ATTR_MAIN_PHOTO"],
)
current_app.logger.debug("end AFFICHAGE_PRECIS")
elif current_app.config["AFFICHAGE_TERRITOIRE_OBS"]:
observations = get_territory_mailles_obs(connection)
else:
observations = []

Expand All @@ -204,11 +213,13 @@ def index():
else:
lastDiscoveries = []

listTaxons = vmTaxonsRepository.getTaxonsTerritory(connection)
connection.close()
session.close()

return render_template(
"templates/home/_main.html",
listTaxons=listTaxons,
observations=observations,
mostViewTaxon=mostViewTaxon,
customStatMedias=customStatMedias,
Expand All @@ -233,7 +244,10 @@ def ficheEspece(cd_nom):
altitudes = vmAltitudesRepository.getAltitudesChilds(connection, cd_ref)
months = vmMoisRepository.getMonthlyObservationsChilds(connection, cd_ref)
synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref)
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
if current_app.config["AFFICHAGE_MAILLE"]:
communes = vmCommunesRepository.getCommunesObservationsChildsMailles(connection, cd_ref)
else:
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(db_session, cd_ref)
firstPhoto = vmMedias.getFirstPhoto(connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"])
photoCarousel = vmMedias.getPhotoCarousel(
Expand Down Expand Up @@ -292,7 +306,6 @@ def ficheCommune(insee):
session = db.session
connection = db.engine.connect()

listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
commune = vmCommunesRepository.getCommuneFromInsee(connection, insee)
if current_app.config["AFFICHAGE_MAILLE"]:
observations = vmObservationsMaillesRepository.lastObservationsCommuneMaille(
Expand All @@ -304,7 +317,7 @@ def ficheCommune(insee):
)

surroundingAreas = []

listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
observers = vmObservationsRepository.getObserversCommunes(connection, insee)

session.close()
Expand Down
1 change: 1 addition & 0 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Meta:
AFFICHAGE_RGPD = fields.Boolean(load_default=True)
AFFICHAGE_STAT_GLOBALES = fields.Boolean(load_default=True)
AFFICHAGE_DERNIERES_OBS = fields.Boolean(load_default=True)
AFFICHAGE_TERRITOIRE_OBS = fields.Boolean(load_default=False)
AFFICHAGE_EN_CE_MOMENT = fields.Boolean(load_default=True)
AFFICHAGE_RANG_STAT = fields.Boolean(load_default=True)
AFFICHAGE_NOUVELLES_ESPECES = fields.Boolean(load_default=True)
Expand Down
10 changes: 10 additions & 0 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ metropole=true
# Choisissez alors la taille de vos mailles à utiliser (en km) / Valeurs possibles 1, 5 ou 10
taillemaille=5

# Choisissez alors la taille de vos mailles à utiliser
# Valeurs possibles M1, M5, COM, 10, COM, DEP ou REG

sensibility0="M1" # sensibilité de niveau 0
sensibility1="M1" # sensibilité de niveau 1
sensibility2="COM" # sensibilité de niveau 2
sensibility3="M10" # sensibilité de niveau 3

# A noter que la sensibilité de niveau 4 sera ignoré afin de ne pas afficher les observations correspondant a ces espèces.

# Si 'metropole=false', rajoutez dans le dossier /data/ref un SHP des mailles de votre territoire et renseignez son chemin
chemin_custom_maille=/home/`whoami`/atlas/data/ref/custom_maille.shp

Expand Down
3 changes: 2 additions & 1 deletion atlas/modeles/entities/vmObservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class VmObservations(Base):
Column("id_observation", Integer, primary_key=True, unique=True),
Column("insee", String(5), index=True),
Column("dateobs", Date, index=True),
Column("type_code", Integer),
Column("observateurs", String(255)),
Column("altitude_retenue", Integer, index=True),
Column("cd_ref", Integer, index=True),
Column("the_geom_point", Geometry(geometry_type="POINT", srid=4326)),
Column("geojson_point", Text),
Column("diffusion_level"),
Column("sensitivity"),
schema="atlas",
autoload=True,
autoload_with=db.engine,
Expand Down
20 changes: 20 additions & 0 deletions atlas/modeles/repositories/vmCommunesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ def getCommunesObservationsChilds(connection, cd_ref):
municipality = {"insee": r.insee, "commune_maj": r.commune_maj}
municipalities.append(municipality)
return municipalities


def getCommunesObservationsChildsMailles(connection, cd_ref):
sql = """
SELECT DISTINCT (com.insee) AS insee, com.commune_maj
FROM atlas.vm_communes com
JOIN atlas.t_mailles_territoire m ON st_intersects(m.the_geom, com.the_geom)
JOIN atlas.vm_observations_mailles obs ON m.id_maille=obs.id_maille
WHERE obs.cd_ref in (
SELECT * from atlas.find_all_taxons_childs(:thiscdref)
)
OR obs.cd_ref = :thiscdref
ORDER BY com.commune_maj ASC
"""
req = connection.execute(text(sql), thiscdref=cd_ref)
listCommunes = list()
for r in req:
temp = {"insee": r.insee, "commune_maj": r.commune_maj}
listCommunes.append(temp)
return listCommunes
Loading
Loading