Skip to content

Commit fa6d97f

Browse files
committed
feat: some stats on territory sheet (#540)
1 parent b8a7290 commit fa6d97f

File tree

16 files changed

+290
-23
lines changed

16 files changed

+290
-23
lines changed

atlas/atlasRoutes.py

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
vmMedias,
3232
vmCorTaxonAttribut,
3333
vmTaxonsMostView,
34+
vmStatsStatutTaxonCommRepository,
3435
)
3536

3637

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

294295
listTaxons = vmTaxonsRepository.getTaxonsZones(connection, id_zone)
296+
taxon_pro_patri = vmStatsStatutTaxonCommRepository.get_nb_taxon_pro_pat_zone(
297+
connection, id_zone
298+
)
299+
nb_organism = vmOrganismsRepository.get_nb_organism_on_zone(connection, id_zone)
300+
infosCommune = tZonesRepository.get_infos_zone(connection, id_zone)
295301

296302
zone = tZonesRepository.getZoneFromIdZone(connection, id_zone)
297303
if current_app.config["AFFICHAGE_MAILLE"]:
@@ -319,6 +325,9 @@ def ficheZone(id_zone):
319325
observers=observers,
320326
DISPLAY_EYE_ON_LIST=True,
321327
id_zone=id_zone,
328+
taxonProPatri=taxon_pro_patri,
329+
nb_organism=nb_organism,
330+
infosCommune=infosCommune,
322331
)
323332

324333

atlas/messages.pot

+26-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PROJECT VERSION\n"
1010
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11-
"POT-Creation-Date: 2025-01-08 14:03+0100\n"
11+
"POT-Creation-Date: 2025-01-09 21:50+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -127,7 +127,7 @@ msgstr ""
127127
msgid "atlas.presentation"
128128
msgstr ""
129129

130-
#: atlas/templates/areaSheet/_main.html:55
130+
#: atlas/templates/areaSheet/_main.html:63
131131
msgid "last.obs.zone"
132132
msgstr ""
133133

@@ -274,6 +274,30 @@ msgstr ""
274274
msgid "observer"
275275
msgstr ""
276276

277+
#: atlas/templates/core/statHierarchy.html:23
278+
msgid "sources"
279+
msgstr ""
280+
281+
#: atlas/templates/core/statHierarchy.html:23
282+
msgid "source"
283+
msgstr ""
284+
285+
#: atlas/templates/core/statHierarchy.html:28
286+
msgid "first_observation"
287+
msgstr ""
288+
289+
#: atlas/templates/core/statHierarchy.html:33
290+
msgid "last_observation"
291+
msgstr ""
292+
293+
#: atlas/templates/core/statHierarchy.html:38
294+
msgid "protected_species"
295+
msgstr ""
296+
297+
#: atlas/templates/core/statHierarchy.html:44
298+
msgid "patrimonial_species"
299+
msgstr ""
300+
277301
#: atlas/templates/core/tabTaxons.html:7
278302
msgid "group"
279303
msgstr ""

atlas/modeles/repositories/tZonesRepository.py

+40
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,43 @@ def getZonesObservationsChilds(connection, cd_ref):
8181
municipality = {"id_zone": r.id_zone, "area_name": r.area_name}
8282
municipalities.append(municipality)
8383
return municipalities
84+
85+
86+
def get_infos_zone(connection, id_zone):
87+
"""
88+
Get zone info:
89+
yearmin: fisrt observation year
90+
yearmax: last observation year
91+
id_parent: id parent zone
92+
area_name: name parent zone
93+
area_type_name: type parent zone
94+
"""
95+
sql = """
96+
SELECT
97+
MIN(extract(YEAR FROM o.dateobs)) AS yearmin,
98+
MAX(extract(YEAR FROM o.dateobs)) AS yearmax,
99+
z.id_parent,
100+
(SELECT area_name FROM atlas.zoning WHERE id_zone = z.id_parent) AS area_parent_name,
101+
(SELECT type.type_name
102+
FROM atlas.zoning AS zone
103+
JOIN ref_geo.bib_areas_types type
104+
ON type.id_type = zone.id_zoning_type
105+
WHERE zone.id_zone = z.id_parent) AS area_parent_type_name
106+
FROM atlas.vm_observations o
107+
JOIN atlas.zoning z ON z.id_zone = o.id_zone
108+
WHERE o.id_zone = :id_zone
109+
GROUP BY z.id_parent
110+
"""
111+
112+
result = connection.execute(text(sql), id_zone=id_zone)
113+
info_zone = dict()
114+
for r in result:
115+
info_zone = {
116+
"yearmin": r.yearmin,
117+
"yearmax": r.yearmax,
118+
"id_parent": r.id_parent,
119+
"parent_name": r.area_parent_name,
120+
"parent_type_name": r.area_parent_type_name,
121+
}
122+
123+
return info_zone

atlas/modeles/repositories/vmOrganismsRepository.py

+13
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,16 @@ def getTaxonRepartitionOrganism(connection, id_organism):
8888
temp = {"group2_inpn": r.group2_inpn, "nb_obs_group": int(r.nb_obs_group)}
8989
ListGroup.append(temp)
9090
return ListGroup
91+
92+
93+
def get_nb_organism_on_zone(connection, id_zone):
94+
sql = """SELECT DISTINCT COUNT(cto.nom_organism) AS nb_organism
95+
FROM atlas.vm_observations o
96+
JOIN atlas.vm_cor_taxon_organism cto ON cto.cd_ref = o.cd_ref
97+
WHERE o.id_zone = :id_zone
98+
"""
99+
res = connection.execute(text(sql), id_zone=id_zone)
100+
result = dict()
101+
for r in res:
102+
result = r.nb_organism
103+
return result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from sqlalchemy.sql import text
4+
5+
6+
# get nombre taxons protégés et nombre taxons patrimoniaux par communes
7+
def get_nb_taxon_pro_pat_zone(connection, id_zone):
8+
sql = """
9+
SELECT
10+
COUNT(t.patrimonial) AS nb_taxon_patrimonial, COUNT(t.protection_stricte) AS nb_taxon_protege
11+
FROM atlas.vm_observations o
12+
JOIN atlas.vm_taxons t ON t.cd_ref=o.cd_ref
13+
JOIN atlas.zoning zone ON st_intersects(o.the_geom_point, zone.the_geom_4326)
14+
WHERE zone.id_zone = :thisIdZone
15+
"""
16+
req = connection.execute(text(sql), thisIdZone=id_zone)
17+
taxonProPatri = dict()
18+
for r in req:
19+
taxonProPatri = {"nbTaxonPro": r.nb_taxon_protege, "nbTaxonPatri": r.nb_taxon_patrimonial}
20+
return taxonProPatri
21+
22+
23+
# # get stats sur les statuts des taxons par communes
24+
# def getStatsStatutsTaxonsCommunes(connection, insee):
25+
# sql = """
26+
# SELECT
27+
# nb_taxon_que_pro,
28+
# nb_taxon_que_patri,
29+
# nb_taxon_pro_et_patri,
30+
# nb_taxon_sans_statut
31+
# FROM atlas.vm_stats_statut_taxon_comm a
32+
# WHERE a.insee = :thisinsee
33+
# """.encode('UTF-8')
34+
#
35+
# mesStatutsTaxons = connection.execute(text(sql), thisinsee=insee)
36+
# for inter in mesStatutsTaxons:
37+
# return [
38+
# {'label': "Taxons protégés", 'y': inter.nb_taxon_que_pro},
39+
# {'label': "Taxons patrimoniaux", 'y': inter.nb_taxon_que_patri},
40+
# {'label': "Taxons protégés et patrimoniaux", 'y': inter.nb_taxon_pro_et_patri},
41+
# {'label': "Autres taxons", 'y': inter.nb_taxon_sans_statut},
42+
# ]
43+
#

atlas/static/css/territorySheet.css

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
img.patrimonial_img {
2+
width: 1rem;
3+
}
4+
5+
.info_zone_card {
6+
width: 100%;
7+
justify-items: center;
8+
padding: 1rem;
9+
}
10+
11+
.specie_list_map_block {
12+
display: flex;
13+
height: 100%;
14+
}
15+
16+
.stats_block {
17+
display: flex;
18+
flex-direction: column;
19+
height: 100%;
20+
}
3.28 KB
Loading

atlas/templates/areaSheet/_main.html

+24-15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<link rel="stylesheet" href="{{ url_for('static', filename='node_modules/datatables.net-bs4/css/dataTables.bootstrap4.css') }}"/>
1919
<link rel="stylesheet" href="{{ url_for('static', filename='css/listEspeces.css') }}"/>
2020
<link rel="stylesheet" href="{{ url_for('static', filename='css/icones.css') }}"/>
21+
<link rel="stylesheet" href="{{ url_for('static', filename='css/territorySheet.css') }}" />
2122
{% endblock %}
2223

2324

@@ -39,26 +40,34 @@
3940

4041
{% block content %}
4142
{# Ajoutez ici coeur de la page #}
42-
<div class="row h-100 flex-grow-1 p-0 m-0 border-bottom">
43-
<div class="col-12 col-xl-4 col-lg-5 col-md-6 d-flex flex-column m-0 p-0">
44-
<div class="bg-light text-center border-bottom border-right p-2">
45-
{% if configuration.EXTENDED_AREAS %}
46-
{% include 'templates/areaSheet/surrounding_areas.html' %}
47-
{% endif %}
43+
<div class="stats_block">
44+
45+
<div class="row p-0 m-0 border-bottom">
46+
<div class="info_zone_card">
4847
<h4><b>{{ areaInfos.typeName }} - {{ areaInfos.areaName }}</b></h4>
4948
{% include 'templates/core/statHierarchy.html' %}
5049
</div>
51-
{% include 'templates/core/listTaxons.html' %}
5250
</div>
53-
<div class="col-12 col-xl-8 col-lg-7 col-md-6 d-flex flex-column m-0 p-0">
54-
<div class="bg-light p-2">
55-
<h5 id="titleMap"><i class="fa fa-map"></i> {{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }}
56-
<i>{{ areaInfos.areaName }}</i></h5>
51+
<div class="specie_list_map_block">
52+
53+
<div class="col-12 col-xl-4 col-lg-5 col-md-6 d-flex flex-column m-0 p-0">
54+
<div class="bg-light text-center border-bottom border-right p-2">
55+
{% if configuration.EXTENDED_AREAS %}
56+
{% include 'templates/areaSheet/surrounding_areas.html' %}
57+
{% endif %}
58+
</div>
59+
{% include 'templates/core/listTaxons.html' %}
5760
</div>
58-
<div class="d-flex align-content-stretch bg-warning flex-grow-1">
59-
<div class="d-flex flex-grow-1">
60-
{% include 'templates/core/loaderSpinner.html' %}
61-
<div id="map" style="height: unset;flex:1;"></div>
61+
<div class="col-12 col-xl-8 col-lg-7 col-md-6 d-flex flex-column m-0 p-0">
62+
<div class="bg-light p-2">
63+
<h5 id="titleMap"><i class="fa fa-map"></i> {{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }}
64+
<i>{{ areaInfos.areaName }}</i></h5>
65+
</div>
66+
<div class="d-flex align-content-stretch bg-warning flex-grow-1">
67+
<div class="d-flex flex-grow-1">
68+
{% include 'templates/core/loaderSpinner.html' %}
69+
<div id="map" style="height: unset;flex:1;"></div>
70+
</div>
6271
</div>
6372
</div>
6473
</div>

atlas/templates/core/statHierarchy.html

+36
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,42 @@
1616
<br><strong>{{ observers | length | pretty }}</strong>
1717
<br>{{ _('observers')|lower if observers|length > 1 else _('observer')|lower }}
1818
</div>
19+
20+
<div class="col-sm center">
21+
<i class="fa fa-project-diagram"></i>
22+
<br><strong>{{ nb_organism }}</strong>
23+
<br>{{ _('sources')|lower if nb_organism > 1 else _('source')|lower }}
24+
</div>
25+
<div class="col-sm center">
26+
<i class="fa fa-search"></i>
27+
<br><strong>{{ infosCommune.yearmin }}</strong>
28+
<br>{{ _('first_observation')|lower }}
29+
</div>
30+
<div class="col-sm center">
31+
<i class="fa fa-search"></i>
32+
<br><strong>{{ infosCommune.yearmax}}</strong>
33+
<br>{{ _('last_observation')|lower }}
34+
</div>
35+
<div class="col-sm center">
36+
<img class="patrimonial_img" src="{{ url_for('static', filename=configuration.PATRIMONIALITE.config.taxon.patrimonial.icon) }}"/>
37+
<br><strong>{{ taxonProPatri.nbTaxonPatri }}</strong>
38+
<br>{{ _('protected_species')|lower }}
39+
</div>
40+
{% if configuration.DISPLAY_PATRIMONIALITE %}
41+
<div class="col-sm center">
42+
<i class="fa fa-paw"></i>
43+
<br><strong>{{ taxonProPatri.nbTaxonPro }}</strong>
44+
<br>{{ _('patrimonial_species')|lower }}
45+
</div>
46+
{% endif %}
47+
48+
{% if infosCommune.id_parent %}
49+
<div class="col-sm center">
50+
<i class="fa fa-city"></i>
51+
<br>{{ infosCommune.parent_type_name }}
52+
<br><strong><a href="/zone/{{ infosCommune.id_parent }}">{{ infosCommune.parent_name }}</a></strong>
53+
</div>
54+
{% endif %}
1955
</div>
2056
</div>
2157
{% endblock %}
272 Bytes
Binary file not shown.

atlas/translations/en/LC_MESSAGES/messages.po

+26-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PROJECT VERSION\n"
99
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2025-01-08 14:03+0100\n"
10+
"POT-Creation-Date: 2025-01-09 21:50+0100\n"
1111
"PO-Revision-Date: 2021-07-12 12:12+0200\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: en\n"
@@ -134,7 +134,7 @@ msgstr "Search by area"
134134
msgid "atlas.presentation"
135135
msgstr "Atlas presentation"
136136

137-
#: atlas/templates/areaSheet/_main.html:55
137+
#: atlas/templates/areaSheet/_main.html:63
138138
msgid "last.obs.zone"
139139
msgstr "Latest observations in the zone"
140140

@@ -284,6 +284,30 @@ msgstr "Observers"
284284
msgid "observer"
285285
msgstr "Observer"
286286

287+
#: atlas/templates/core/statHierarchy.html:23
288+
msgid "sources"
289+
msgstr "sources"
290+
291+
#: atlas/templates/core/statHierarchy.html:23
292+
msgid "source"
293+
msgstr "source"
294+
295+
#: atlas/templates/core/statHierarchy.html:28
296+
msgid "first_observation"
297+
msgstr "first observation"
298+
299+
#: atlas/templates/core/statHierarchy.html:33
300+
msgid "last_observation"
301+
msgstr "last observation"
302+
303+
#: atlas/templates/core/statHierarchy.html:38
304+
msgid "protected_species"
305+
msgstr "protected species"
306+
307+
#: atlas/templates/core/statHierarchy.html:44
308+
msgid "patrimonial_species"
309+
msgstr "patrimonial species"
310+
287311
#: atlas/templates/core/tabTaxons.html:7
288312
msgid "group"
289313
msgstr "Group"
289 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)