Skip to content

Commit 3f460f2

Browse files
committed
feat: Add blurring observations
Ce commit intègre tout les changements lié au floutage des données en fonction du niveau de sensiblité d'une observation.
1 parent 6466f38 commit 3f460f2

23 files changed

+1138
-821
lines changed

atlas/atlasRoutes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ def ficheEspece(cd_nom):
233233
altitudes = vmAltitudesRepository.getAltitudesChilds(connection, cd_ref)
234234
months = vmMoisRepository.getMonthlyObservationsChilds(connection, cd_ref)
235235
synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref)
236-
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
236+
if current_app.config["AFFICHAGE_MAILLE"]:
237+
communes = vmCommunesRepository.getCommunesObservationsChildsMailles(connection, cd_ref)
238+
else:
239+
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
237240
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(db_session, cd_ref)
238241
firstPhoto = vmMedias.getFirstPhoto(connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"])
239242
photoCarousel = vmMedias.getPhotoCarousel(
@@ -292,7 +295,6 @@ def ficheCommune(insee):
292295
session = db.session
293296
connection = db.engine.connect()
294297

295-
listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
296298
commune = vmCommunesRepository.getCommuneFromInsee(connection, insee)
297299
if current_app.config["AFFICHAGE_MAILLE"]:
298300
observations = vmObservationsMaillesRepository.lastObservationsCommuneMaille(
@@ -304,7 +306,7 @@ def ficheCommune(insee):
304306
)
305307

306308
surroundingAreas = []
307-
309+
listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
308310
observers = vmObservationsRepository.getObserversCommunes(connection, insee)
309311

310312
session.close()

atlas/configuration/settings.ini.sample

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ metropole=true
108108
# Choisissez alors la taille de vos mailles à utiliser (en km) / Valeurs possibles 1, 5 ou 10
109109
taillemaille=5
110110

111+
# Choisissez alors la taille de vos mailles à utiliser
112+
# Valeurs possibles M1, M5, COM, 10, COM, DEP ou REG
113+
114+
sensibility0="M1" # sensibilité de niveau 0
115+
sensibility1="M1" # sensibilité de niveau 1
116+
sensibility2="COM" # sensibilité de niveau 2
117+
sensibility3="M10" # sensibilité de niveau 3
118+
119+
# A noter que la sensibilité de niveau 4 sera ignoré afin de ne pas afficher les observations correspondant a ces espèces.
120+
111121
# Si 'metropole=false', rajoutez dans le dossier /data/ref un SHP des mailles de votre territoire et renseignez son chemin
112122
chemin_custom_maille=/home/`whoami`/atlas/data/ref/custom_maille.shp
113123

atlas/modeles/entities/vmObservations.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ class VmObservations(Base):
1616
Column("id_observation", Integer, primary_key=True, unique=True),
1717
Column("insee", String(5), index=True),
1818
Column("dateobs", Date, index=True),
19+
Column("type_code", Integer),
1920
Column("observateurs", String(255)),
2021
Column("altitude_retenue", Integer, index=True),
2122
Column("cd_ref", Integer, index=True),
2223
Column("the_geom_point", Geometry(geometry_type="POINT", srid=4326)),
2324
Column("geojson_point", Text),
24-
Column("diffusion_level"),
25+
Column("sensitivity"),
2526
schema="atlas",
2627
autoload=True,
2728
autoload_with=db.engine,

atlas/modeles/repositories/vmCommunesRepository.py

+20
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,23 @@ def getCommunesObservationsChilds(connection, cd_ref):
7878
municipality = {"insee": r.insee, "commune_maj": r.commune_maj}
7979
municipalities.append(municipality)
8080
return municipalities
81+
82+
83+
def getCommunesObservationsChildsMailles(connection, cd_ref):
84+
sql = """
85+
SELECT DISTINCT (com.insee) AS insee, com.commune_maj
86+
FROM atlas.vm_communes com
87+
JOIN atlas.t_mailles_territoire m ON st_intersects(m.the_geom, com.the_geom)
88+
JOIN atlas.vm_observations_mailles obs ON m.id_maille=obs.id_maille
89+
WHERE obs.cd_ref in (
90+
SELECT * from atlas.find_all_taxons_childs(:thiscdref)
91+
)
92+
OR obs.cd_ref = :thiscdref
93+
ORDER BY com.commune_maj ASC
94+
"""
95+
req = connection.execute(text(sql), thiscdref=cd_ref)
96+
listCommunes = list()
97+
for r in req:
98+
temp = {"insee": r.insee, "commune_maj": r.commune_maj}
99+
listCommunes.append(temp)
100+
return listCommunes

atlas/modeles/repositories/vmObservationsMaillesRepository.py

+43-29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
from atlas.modeles.utils import deleteAccent, findPath
99

1010

11+
def format_taxon_name(observation):
12+
if observation.nom_vern:
13+
inter = observation.nom_vern.split(",")
14+
taxon_name_formated = inter[0] + " | <i>" + observation.lb_nom + "</i>"
15+
else:
16+
taxon_name_formated = "<i>" + observation.lb_nom + "</i>"
17+
return taxon_name_formated
18+
19+
1120
def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
1221
"""
1322
Retourne les mailles et le nombre d'observation par maille pour un taxon et ses enfants
@@ -23,6 +32,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
2332
TMaillesTerritoire.geojson_maille,
2433
func.max(VmObservationsMailles.annee).label("last_obs_year"),
2534
func.sum(VmObservationsMailles.nbr).label("obs_nbr"),
35+
VmObservationsMailles.type_code,
2636
)
2737
.join(
2838
TMaillesTerritoire,
@@ -32,6 +42,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
3242
.group_by(
3343
VmObservationsMailles.id_maille,
3444
TMaillesTerritoire.geojson_maille,
45+
VmObservationsMailles.type_code,
3546
)
3647
)
3748
if year_min and year_max:
@@ -44,6 +55,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
4455
geometry=json.loads(o.geojson_maille),
4556
properties={
4657
"id_maille": o.id_maille,
58+
"type_code": o.type_code,
4759
"nb_observations": int(o.obs_nbr),
4860
"last_observation": o.last_obs_year,
4961
},
@@ -60,13 +72,13 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
6072
tax.lb_nom, tax.nom_vern, tax.group2_inpn,
6173
o.dateobs, o.altitude_retenue, o.id_observation,
6274
medias.url, medias.chemin, medias.id_media,
63-
m.geojson_maille
75+
m.geojson_4326 AS geom
6476
FROM atlas.vm_observations_mailles obs
6577
JOIN atlas.vm_taxons tax ON tax.cd_ref = obs.cd_ref
6678
JOIN atlas.vm_observations o ON o.id_observation=ANY(obs.id_observations)
67-
JOIN atlas.t_mailles_territoire m ON m.id_maille=obs.id_maille
79+
JOIN atlas.vm_cor_area_synthese m ON m.id_synthese=o.id_observation AND m.is_blurred_geom IS TRUE
6880
LEFT JOIN atlas.vm_medias medias
69-
ON medias.cd_ref = obs.cd_ref AND medias.id_type = :thisID
81+
ON medias.cd_ref = obs.cd_ref AND medias.id_type = 1
7082
WHERE o.dateobs >= (CURRENT_TIMESTAMP - INTERVAL :thislimit)
7183
ORDER BY o.dateobs DESC
7284
"""
@@ -82,11 +94,12 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
8294
temp = {
8395
"id_observation": o.id_observation,
8496
"id_maille": o.id_maille,
97+
"type_code": o.type_code,
8598
"cd_ref": o.cd_ref,
8699
"dateobs": o.dateobs,
87100
"altitude_retenue": o.altitude_retenue,
88101
"taxon": taxon,
89-
"geojson_maille": json.loads(o.geojson_maille),
102+
"geojson_maille": json.loads(o.geom),
90103
"group2_inpn": deleteAccent(o.group2_inpn),
91104
"pathImg": findPath(o),
92105
"id_media": o.id_media,
@@ -97,38 +110,33 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
97110

98111
def lastObservationsCommuneMaille(connection, obs_limit, insee_code):
99112
sql = """
100-
WITH last_obs AS (
101113
SELECT
102-
obs.id_observation, obs.cd_ref, obs.dateobs,
114+
obs.id_observations, obs.cd_ref, obs.type_code, obs.nbr, c.insee,
103115
COALESCE(t.nom_vern || ' | ', '') || t.lb_nom AS display_name,
104-
obs.the_geom_point AS l_geom
105-
FROM atlas.vm_observations AS obs
116+
m.the_geom AS l_geom,
117+
t.nom_vern, m.the_geom as l_geom,
118+
m.geojson_maille, obs.id_maille
119+
FROM atlas.vm_observations_mailles obs
120+
JOIN atlas.t_mailles_territoire m ON m.id_maille = obs.id_maille
106121
JOIN atlas.vm_communes AS c
107-
ON ST_Intersects(obs.the_geom_point, c.the_geom)
122+
ON ST_Intersects(m.the_geom, c.the_geom) AND NOT ST_Touches(m.the_geom, c.the_geom)
108123
JOIN atlas.vm_taxons AS t
109124
ON obs.cd_ref = t.cd_ref
110125
WHERE c.insee = :inseeCode
111-
ORDER BY obs.dateobs DESC
112126
LIMIT :obsLimit
113-
)
114-
SELECT
115-
l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille
116-
FROM atlas.t_mailles_territoire AS m
117-
JOIN last_obs AS l
118-
ON st_intersects(m.the_geom, l.l_geom)
119-
GROUP BY l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille
120-
ORDER BY l.display_name
121127
"""
122128
results = connection.execute(text(sql), inseeCode=insee_code, obsLimit=obs_limit)
123129
observations = list()
124130
for r in results:
125-
# taxon = (r.nom_vern + " | " + r.lb_nom) if r.nom_vern else r.lb_nom
126131
infos = {
127132
"cd_ref": r.cd_ref,
133+
"insee": r.insee,
128134
"taxon": r.display_name,
129135
"geojson_maille": json.loads(r.geojson_maille),
130136
"id_maille": r.id_maille,
131-
"id_observation": r.id_observation,
137+
"id_observation": r.id_observations,
138+
"nb_observations": r.nbr,
139+
"type_code": r.type_code,
132140
}
133141
observations.append(infos)
134142
return observations
@@ -139,23 +147,29 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref):
139147
sql = """
140148
SELECT
141149
o.cd_ref,
142-
t.id_maille,
143-
t.geojson_maille,
144-
extract(YEAR FROM o.dateobs)::INT AS annee
145-
FROM atlas.vm_observations AS o
146-
JOIN atlas.vm_communes AS c
147-
ON ST_INTERSECTS(o.the_geom_point, c.the_geom)
148-
JOIN atlas.t_mailles_territoire AS t
149-
ON ST_INTERSECTS(t.the_geom, o.the_geom_point)
150+
o.id_maille,
151+
o.type_code,
152+
o.annee,
153+
m.geojson_maille,
154+
m.the_geom,
155+
t.cd_ref,
156+
t.nom_vern,
157+
t.lb_nom
158+
FROM atlas.vm_observations_mailles AS o
159+
JOIN atlas.vm_taxons AS t ON t.cd_ref = o.cd_ref
160+
JOIN atlas.t_mailles_territoire m ON m.id_maille = o.id_maille
161+
JOIN atlas.vm_communes AS c ON c.insee = :thisInsee AND st_intersects(c.the_geom, m.the_geom) AND NOT st_touches(c.the_geom, m.the_geom)
150162
WHERE o.cd_ref = :thiscdref
151-
AND c.insee = :thisInsee
152163
ORDER BY id_maille
153164
"""
154165
observations = connection.execute(text(sql), thisInsee=insee, thiscdref=cd_ref)
155166
tabObs = list()
156167
for o in observations:
157168
temp = {
158169
"id_maille": o.id_maille,
170+
"cd_ref": o.cd_ref,
171+
"taxon": format_taxon_name(o),
172+
"type_code": o.type_code,
159173
"nb_observations": 1,
160174
"annee": o.annee,
161175
"geojson_maille": json.loads(o.geojson_maille),

atlas/modeles/repositories/vmObservationsRepository.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def lastObservations(connection, mylimit, idPhoto):
9696
temp.pop("the_geom_point", None)
9797
temp["geojson_point"] = json.loads(o.geojson_point or "{}")
9898
temp["dateobs"] = o.dateobs
99+
temp["type_code"] = o.type_code
99100
temp["group2_inpn"] = utils.deleteAccent(o.group2_inpn)
100101
temp["pathImg"] = utils.findPath(o)
101102
obsList.append(temp)
@@ -111,9 +112,8 @@ def lastObservationsCommune(connection, mylimit, insee):
111112
'</i>'
112113
) AS taxon
113114
FROM atlas.vm_observations o
114-
JOIN atlas.vm_communes c ON ST_Intersects(o.the_geom_point, c.the_geom)
115115
JOIN atlas.vm_taxons tax ON o.cd_ref = tax.cd_ref
116-
WHERE c.insee = :thisInsee
116+
WHERE o.insee = :thisInsee
117117
ORDER BY o.dateobs DESC
118118
LIMIT 100"""
119119
observations = connection.execute(text(sql), thisInsee=insee)

atlas/static/css/index.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ h3.title-spaced {
366366
}*/
367367

368368
.tabEspece:hover {
369-
background-color: #cccccc;
369+
background-color: rgba(var(--main-color-rgb), 0.2);
370370
}
371371

372372
.tabEspece.current {
373-
background-color: #e6e6e6;
373+
background-color: rgba(var(--main-color-rgb), 0.4);
374374
font-weight: bold;
375375
}
376376

atlas/static/css/listEspeces.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ ul#statHierarchy {
146146
}
147147

148148
tbody tr:hover {
149+
background-color: rgba(var(--main-color-rgb), 0.2) !important;
149150
/*background-color: #cccccc !important;*/
150151
cursor: pointer;
151152
}
152153

153154
tbody tr.current {
154-
background-color: #e6e6e6 !important;
155+
background-color: rgba(var(--main-color-rgb), 0.4) !important;
155156
font-weight: bold;
156157
}
157158

@@ -203,4 +204,4 @@ tbody tr.current {
203204
font-size: 0.8rem;
204205
color: deeppink;
205206
}
206-
}
207+
}

atlas/static/mapAreas.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ var areaLayer = L.geoJson(areaInfos.areaGeoJson, {
1717
weight: 2,
1818
color: areaBorderColor,
1919
// dashArray: "3",
20-
fillOpacity: 0.3
20+
fillOpacity: 0.3,
21+
invert: true
2122
};
2223
}
2324
}).addTo(map);
@@ -93,6 +94,7 @@ function displayObsPreciseBaseUrl(areaCode, cd_ref) {
9394
$("#loaderSpinner").hide();
9495
// $("#loadingGif").hide();
9596
map.removeLayer(currentLayer);
97+
clearOverlays()
9698
if (configuration.AFFICHAGE_MAILLE) {
9799
displayMailleLayerLastObs(observations);
98100
} else {
@@ -129,6 +131,7 @@ function displayObsTaxon(insee, cd_ref) {
129131
}).done(function(observations) {
130132
$("#loadingGif").hide();
131133
map.removeLayer(currentLayer);
134+
clearOverlays()
132135
if (configuration.AFFICHAGE_MAILLE) {
133136
displayMailleLayerLastObs(observations);
134137
} else {
@@ -153,7 +156,9 @@ function displayObsTaxonMaille(areaCode, cd_ref) {
153156
$("#loaderSpinner").hide();
154157
// $("#loadingGif").hide();
155158
map.removeLayer(currentLayer);
156-
displayGridLayerArea(observations);
159+
clearOverlays()
160+
const geojsonMaille = generateGeoJsonMailleLastObs(observations);
161+
displayMailleLayerFicheEspece(geojsonMaille);
157162
});
158163
}
159164

0 commit comments

Comments
 (0)