Skip to content

Commit

Permalink
feat: some stats on territory sheet (PnX-SI#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
juggler31 committed Jan 9, 2025
1 parent b8a7290 commit fa6d97f
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 23 deletions.
9 changes: 9 additions & 0 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
vmMedias,
vmCorTaxonAttribut,
vmTaxonsMostView,
vmStatsStatutTaxonCommRepository,
)


Expand Down Expand Up @@ -292,6 +293,11 @@ def ficheZone(id_zone):
connection = db.engine.connect()

listTaxons = vmTaxonsRepository.getTaxonsZones(connection, id_zone)
taxon_pro_patri = vmStatsStatutTaxonCommRepository.get_nb_taxon_pro_pat_zone(
connection, id_zone
)
nb_organism = vmOrganismsRepository.get_nb_organism_on_zone(connection, id_zone)
infosCommune = tZonesRepository.get_infos_zone(connection, id_zone)

zone = tZonesRepository.getZoneFromIdZone(connection, id_zone)
if current_app.config["AFFICHAGE_MAILLE"]:
Expand Down Expand Up @@ -319,6 +325,9 @@ def ficheZone(id_zone):
observers=observers,
DISPLAY_EYE_ON_LIST=True,
id_zone=id_zone,
taxonProPatri=taxon_pro_patri,
nb_organism=nb_organism,
infosCommune=infosCommune,
)


Expand Down
28 changes: 26 additions & 2 deletions atlas/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-01-08 14:03+0100\n"
"POT-Creation-Date: 2025-01-09 21:50+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -127,7 +127,7 @@ msgstr ""
msgid "atlas.presentation"
msgstr ""

#: atlas/templates/areaSheet/_main.html:55
#: atlas/templates/areaSheet/_main.html:63
msgid "last.obs.zone"
msgstr ""

Expand Down Expand Up @@ -274,6 +274,30 @@ msgstr ""
msgid "observer"
msgstr ""

#: atlas/templates/core/statHierarchy.html:23
msgid "sources"
msgstr ""

#: atlas/templates/core/statHierarchy.html:23
msgid "source"
msgstr ""

#: atlas/templates/core/statHierarchy.html:28
msgid "first_observation"
msgstr ""

#: atlas/templates/core/statHierarchy.html:33
msgid "last_observation"
msgstr ""

#: atlas/templates/core/statHierarchy.html:38
msgid "protected_species"
msgstr ""

#: atlas/templates/core/statHierarchy.html:44
msgid "patrimonial_species"
msgstr ""

#: atlas/templates/core/tabTaxons.html:7
msgid "group"
msgstr ""
Expand Down
40 changes: 40 additions & 0 deletions atlas/modeles/repositories/tZonesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,43 @@ def getZonesObservationsChilds(connection, cd_ref):
municipality = {"id_zone": r.id_zone, "area_name": r.area_name}
municipalities.append(municipality)
return municipalities


def get_infos_zone(connection, id_zone):
"""
Get zone info:
yearmin: fisrt observation year
yearmax: last observation year
id_parent: id parent zone
area_name: name parent zone
area_type_name: type parent zone
"""
sql = """
SELECT
MIN(extract(YEAR FROM o.dateobs)) AS yearmin,
MAX(extract(YEAR FROM o.dateobs)) AS yearmax,
z.id_parent,
(SELECT area_name FROM atlas.zoning WHERE id_zone = z.id_parent) AS area_parent_name,
(SELECT type.type_name
FROM atlas.zoning AS zone
JOIN ref_geo.bib_areas_types type
ON type.id_type = zone.id_zoning_type
WHERE zone.id_zone = z.id_parent) AS area_parent_type_name
FROM atlas.vm_observations o
JOIN atlas.zoning z ON z.id_zone = o.id_zone
WHERE o.id_zone = :id_zone
GROUP BY z.id_parent
"""

result = connection.execute(text(sql), id_zone=id_zone)
info_zone = dict()
for r in result:
info_zone = {
"yearmin": r.yearmin,
"yearmax": r.yearmax,
"id_parent": r.id_parent,
"parent_name": r.area_parent_name,
"parent_type_name": r.area_parent_type_name,
}

return info_zone
13 changes: 13 additions & 0 deletions atlas/modeles/repositories/vmOrganismsRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,16 @@ def getTaxonRepartitionOrganism(connection, id_organism):
temp = {"group2_inpn": r.group2_inpn, "nb_obs_group": int(r.nb_obs_group)}
ListGroup.append(temp)
return ListGroup


def get_nb_organism_on_zone(connection, id_zone):
sql = """SELECT DISTINCT COUNT(cto.nom_organism) AS nb_organism
FROM atlas.vm_observations o
JOIN atlas.vm_cor_taxon_organism cto ON cto.cd_ref = o.cd_ref
WHERE o.id_zone = :id_zone
"""
res = connection.execute(text(sql), id_zone=id_zone)
result = dict()
for r in res:
result = r.nb_organism
return result
43 changes: 43 additions & 0 deletions atlas/modeles/repositories/vmStatsStatutTaxonCommRepository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding:utf-8 -*-

from sqlalchemy.sql import text


# get nombre taxons protégés et nombre taxons patrimoniaux par communes
def get_nb_taxon_pro_pat_zone(connection, id_zone):
sql = """
SELECT
COUNT(t.patrimonial) AS nb_taxon_patrimonial, COUNT(t.protection_stricte) AS nb_taxon_protege
FROM atlas.vm_observations o
JOIN atlas.vm_taxons t ON t.cd_ref=o.cd_ref
JOIN atlas.zoning zone ON st_intersects(o.the_geom_point, zone.the_geom_4326)
WHERE zone.id_zone = :thisIdZone
"""
req = connection.execute(text(sql), thisIdZone=id_zone)
taxonProPatri = dict()
for r in req:
taxonProPatri = {"nbTaxonPro": r.nb_taxon_protege, "nbTaxonPatri": r.nb_taxon_patrimonial}
return taxonProPatri


# # get stats sur les statuts des taxons par communes
# def getStatsStatutsTaxonsCommunes(connection, insee):
# sql = """
# SELECT
# nb_taxon_que_pro,
# nb_taxon_que_patri,
# nb_taxon_pro_et_patri,
# nb_taxon_sans_statut
# FROM atlas.vm_stats_statut_taxon_comm a
# WHERE a.insee = :thisinsee
# """.encode('UTF-8')
#
# mesStatutsTaxons = connection.execute(text(sql), thisinsee=insee)
# for inter in mesStatutsTaxons:
# return [
# {'label': "Taxons protégés", 'y': inter.nb_taxon_que_pro},
# {'label': "Taxons patrimoniaux", 'y': inter.nb_taxon_que_patri},
# {'label': "Taxons protégés et patrimoniaux", 'y': inter.nb_taxon_pro_et_patri},
# {'label': "Autres taxons", 'y': inter.nb_taxon_sans_statut},
# ]
#
20 changes: 20 additions & 0 deletions atlas/static/css/territorySheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
img.patrimonial_img {
width: 1rem;
}

.info_zone_card {
width: 100%;
justify-items: center;
padding: 1rem;
}

.specie_list_map_block {
display: flex;
height: 100%;
}

.stats_block {
display: flex;
flex-direction: column;
height: 100%;
}
Binary file added atlas/static/custom/images/logo_protection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 24 additions & 15 deletions atlas/templates/areaSheet/_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<link rel="stylesheet" href="{{ url_for('static', filename='node_modules/datatables.net-bs4/css/dataTables.bootstrap4.css') }}"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/listEspeces.css') }}"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/icones.css') }}"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/territorySheet.css') }}" />
{% endblock %}


Expand All @@ -39,26 +40,34 @@

{% block content %}
{# Ajoutez ici coeur de la page #}
<div class="row h-100 flex-grow-1 p-0 m-0 border-bottom">
<div class="col-12 col-xl-4 col-lg-5 col-md-6 d-flex flex-column m-0 p-0">
<div class="bg-light text-center border-bottom border-right p-2">
{% if configuration.EXTENDED_AREAS %}
{% include 'templates/areaSheet/surrounding_areas.html' %}
{% endif %}
<div class="stats_block">

<div class="row p-0 m-0 border-bottom">
<div class="info_zone_card">
<h4><b>{{ areaInfos.typeName }} - {{ areaInfos.areaName }}</b></h4>
{% include 'templates/core/statHierarchy.html' %}
</div>
{% include 'templates/core/listTaxons.html' %}
</div>
<div class="col-12 col-xl-8 col-lg-7 col-md-6 d-flex flex-column m-0 p-0">
<div class="bg-light p-2">
<h5 id="titleMap"><i class="fa fa-map"></i> {{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }}
<i>{{ areaInfos.areaName }}</i></h5>
<div class="specie_list_map_block">

<div class="col-12 col-xl-4 col-lg-5 col-md-6 d-flex flex-column m-0 p-0">
<div class="bg-light text-center border-bottom border-right p-2">
{% if configuration.EXTENDED_AREAS %}
{% include 'templates/areaSheet/surrounding_areas.html' %}
{% endif %}
</div>
{% include 'templates/core/listTaxons.html' %}
</div>
<div class="d-flex align-content-stretch bg-warning flex-grow-1">
<div class="d-flex flex-grow-1">
{% include 'templates/core/loaderSpinner.html' %}
<div id="map" style="height: unset;flex:1;"></div>
<div class="col-12 col-xl-8 col-lg-7 col-md-6 d-flex flex-column m-0 p-0">
<div class="bg-light p-2">
<h5 id="titleMap"><i class="fa fa-map"></i> {{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }}
<i>{{ areaInfos.areaName }}</i></h5>
</div>
<div class="d-flex align-content-stretch bg-warning flex-grow-1">
<div class="d-flex flex-grow-1">
{% include 'templates/core/loaderSpinner.html' %}
<div id="map" style="height: unset;flex:1;"></div>
</div>
</div>
</div>
</div>
Expand Down
36 changes: 36 additions & 0 deletions atlas/templates/core/statHierarchy.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@
<br><strong>{{ observers | length | pretty }}</strong>
<br>{{ _('observers')|lower if observers|length > 1 else _('observer')|lower }}
</div>

<div class="col-sm center">
<i class="fa fa-project-diagram"></i>
<br><strong>{{ nb_organism }}</strong>
<br>{{ _('sources')|lower if nb_organism > 1 else _('source')|lower }}
</div>
<div class="col-sm center">
<i class="fa fa-search"></i>
<br><strong>{{ infosCommune.yearmin }}</strong>
<br>{{ _('first_observation')|lower }}
</div>
<div class="col-sm center">
<i class="fa fa-search"></i>
<br><strong>{{ infosCommune.yearmax}}</strong>
<br>{{ _('last_observation')|lower }}
</div>
<div class="col-sm center">
<img class="patrimonial_img" src="{{ url_for('static', filename=configuration.PATRIMONIALITE.config.taxon.patrimonial.icon) }}"/>
<br><strong>{{ taxonProPatri.nbTaxonPatri }}</strong>
<br>{{ _('protected_species')|lower }}
</div>
{% if configuration.DISPLAY_PATRIMONIALITE %}
<div class="col-sm center">
<i class="fa fa-paw"></i>
<br><strong>{{ taxonProPatri.nbTaxonPro }}</strong>
<br>{{ _('patrimonial_species')|lower }}
</div>
{% endif %}

{% if infosCommune.id_parent %}
<div class="col-sm center">
<i class="fa fa-city"></i>
<br>{{ infosCommune.parent_type_name }}
<br><strong><a href="/zone/{{ infosCommune.id_parent }}">{{ infosCommune.parent_name }}</a></strong>
</div>
{% endif %}
</div>
</div>
{% endblock %}
Binary file modified atlas/translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
28 changes: 26 additions & 2 deletions atlas/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2025-01-08 14:03+0100\n"
"POT-Creation-Date: 2025-01-09 21:50+0100\n"
"PO-Revision-Date: 2021-07-12 12:12+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -134,7 +134,7 @@ msgstr "Search by area"
msgid "atlas.presentation"
msgstr "Atlas presentation"

#: atlas/templates/areaSheet/_main.html:55
#: atlas/templates/areaSheet/_main.html:63
msgid "last.obs.zone"
msgstr "Latest observations in the zone"

Expand Down Expand Up @@ -284,6 +284,30 @@ msgstr "Observers"
msgid "observer"
msgstr "Observer"

#: atlas/templates/core/statHierarchy.html:23
msgid "sources"
msgstr "sources"

#: atlas/templates/core/statHierarchy.html:23
msgid "source"
msgstr "source"

#: atlas/templates/core/statHierarchy.html:28
msgid "first_observation"
msgstr "first observation"

#: atlas/templates/core/statHierarchy.html:33
msgid "last_observation"
msgstr "last observation"

#: atlas/templates/core/statHierarchy.html:38
msgid "protected_species"
msgstr "protected species"

#: atlas/templates/core/statHierarchy.html:44
msgid "patrimonial_species"
msgstr "patrimonial species"

#: atlas/templates/core/tabTaxons.html:7
msgid "group"
msgstr "Group"
Expand Down
Binary file modified atlas/translations/fr/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit fa6d97f

Please sign in to comment.