-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: Add blurring observations #586
Open
juggler31
wants to merge
3
commits into
PnX-SI:develop
Choose a base branch
from
makinacorpus:test_PR_Floutage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,15 @@ | |
from atlas.modeles.utils import deleteAccent, findPath | ||
|
||
|
||
def format_taxon_name(observation): | ||
if observation.nom_vern: | ||
inter = observation.nom_vern.split(",") | ||
taxon_name_formated = inter[0] + " | <i>" + observation.lb_nom + "</i>" | ||
else: | ||
taxon_name_formated = "<i>" + observation.lb_nom + "</i>" | ||
return taxon_name_formated | ||
|
||
|
||
def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None): | ||
""" | ||
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): | |
TMaillesTerritoire.geojson_maille, | ||
func.max(VmObservationsMailles.annee).label("last_obs_year"), | ||
func.sum(VmObservationsMailles.nbr).label("obs_nbr"), | ||
VmObservationsMailles.type_code, | ||
) | ||
.join( | ||
TMaillesTerritoire, | ||
|
@@ -32,6 +42,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None): | |
.group_by( | ||
VmObservationsMailles.id_maille, | ||
TMaillesTerritoire.geojson_maille, | ||
VmObservationsMailles.type_code, | ||
) | ||
) | ||
if year_min and year_max: | ||
|
@@ -44,6 +55,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None): | |
geometry=json.loads(o.geojson_maille), | ||
properties={ | ||
"id_maille": o.id_maille, | ||
"type_code": o.type_code, | ||
"nb_observations": int(o.obs_nbr), | ||
"last_observation": o.last_obs_year, | ||
}, | ||
|
@@ -60,13 +72,13 @@ def lastObservationsMailles(connection, mylimit, idPhoto): | |
tax.lb_nom, tax.nom_vern, tax.group2_inpn, | ||
o.dateobs, o.altitude_retenue, o.id_observation, | ||
medias.url, medias.chemin, medias.id_media, | ||
m.geojson_maille | ||
m.geojson_4326 AS geom | ||
FROM atlas.vm_observations_mailles obs | ||
JOIN atlas.vm_taxons tax ON tax.cd_ref = obs.cd_ref | ||
JOIN atlas.vm_observations o ON o.id_observation=ANY(obs.id_observations) | ||
JOIN atlas.t_mailles_territoire m ON m.id_maille=obs.id_maille | ||
JOIN atlas.vm_cor_area_synthese m ON m.id_synthese=o.id_observation AND m.is_blurred_geom IS TRUE | ||
LEFT JOIN atlas.vm_medias medias | ||
ON medias.cd_ref = obs.cd_ref AND medias.id_type = :thisID | ||
ON medias.cd_ref = obs.cd_ref AND medias.id_type = 1 | ||
WHERE o.dateobs >= (CURRENT_TIMESTAMP - INTERVAL :thislimit) | ||
ORDER BY o.dateobs DESC | ||
""" | ||
|
@@ -82,11 +94,12 @@ def lastObservationsMailles(connection, mylimit, idPhoto): | |
temp = { | ||
"id_observation": o.id_observation, | ||
"id_maille": o.id_maille, | ||
"type_code": o.type_code, | ||
"cd_ref": o.cd_ref, | ||
"dateobs": o.dateobs, | ||
"altitude_retenue": o.altitude_retenue, | ||
"taxon": taxon, | ||
"geojson_maille": json.loads(o.geojson_maille), | ||
"geojson_maille": json.loads(o.geom), | ||
"group2_inpn": deleteAccent(o.group2_inpn), | ||
"pathImg": findPath(o), | ||
"id_media": o.id_media, | ||
|
@@ -97,38 +110,33 @@ def lastObservationsMailles(connection, mylimit, idPhoto): | |
|
||
def lastObservationsCommuneMaille(connection, obs_limit, insee_code): | ||
sql = """ | ||
WITH last_obs AS ( | ||
SELECT | ||
obs.id_observation, obs.cd_ref, obs.dateobs, | ||
obs.id_observations, obs.cd_ref, obs.type_code, obs.nbr, c.insee, | ||
COALESCE(t.nom_vern || ' | ', '') || t.lb_nom AS display_name, | ||
obs.the_geom_point AS l_geom | ||
FROM atlas.vm_observations AS obs | ||
m.the_geom AS l_geom, | ||
t.nom_vern, m.the_geom as l_geom, | ||
m.geojson_maille, obs.id_maille | ||
FROM atlas.vm_observations_mailles obs | ||
JOIN atlas.t_mailles_territoire m ON m.id_maille = obs.id_maille | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ne plus utiliser t_mailles_territoire |
||
JOIN atlas.vm_communes AS c | ||
ON ST_Intersects(obs.the_geom_point, c.the_geom) | ||
ON ST_Intersects(m.the_geom, c.the_geom) AND NOT ST_Touches(m.the_geom, c.the_geom) | ||
JOIN atlas.vm_taxons AS t | ||
ON obs.cd_ref = t.cd_ref | ||
WHERE c.insee = :inseeCode | ||
ORDER BY obs.dateobs DESC | ||
LIMIT :obsLimit | ||
) | ||
SELECT | ||
l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille | ||
FROM atlas.t_mailles_territoire AS m | ||
JOIN last_obs AS l | ||
ON st_intersects(m.the_geom, l.l_geom) | ||
GROUP BY l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille | ||
ORDER BY l.display_name | ||
""" | ||
results = connection.execute(text(sql), inseeCode=insee_code, obsLimit=obs_limit) | ||
observations = list() | ||
for r in results: | ||
# taxon = (r.nom_vern + " | " + r.lb_nom) if r.nom_vern else r.lb_nom | ||
infos = { | ||
"cd_ref": r.cd_ref, | ||
"insee": r.insee, | ||
"taxon": r.display_name, | ||
"geojson_maille": json.loads(r.geojson_maille), | ||
"id_maille": r.id_maille, | ||
"id_observation": r.id_observation, | ||
"id_observation": r.id_observations, | ||
"nb_observations": r.nbr, | ||
"type_code": r.type_code, | ||
} | ||
observations.append(infos) | ||
return observations | ||
|
@@ -139,23 +147,29 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref): | |
sql = """ | ||
SELECT | ||
o.cd_ref, | ||
t.id_maille, | ||
t.geojson_maille, | ||
extract(YEAR FROM o.dateobs)::INT AS annee | ||
FROM atlas.vm_observations AS o | ||
JOIN atlas.vm_communes AS c | ||
ON ST_INTERSECTS(o.the_geom_point, c.the_geom) | ||
JOIN atlas.t_mailles_territoire AS t | ||
ON ST_INTERSECTS(t.the_geom, o.the_geom_point) | ||
o.id_maille, | ||
o.type_code, | ||
o.annee, | ||
m.geojson_maille, | ||
m.the_geom, | ||
t.cd_ref, | ||
t.nom_vern, | ||
t.lb_nom | ||
FROM atlas.vm_observations_mailles AS o | ||
JOIN atlas.vm_taxons AS t ON t.cd_ref = o.cd_ref | ||
JOIN atlas.t_mailles_territoire m ON m.id_maille = o.id_maille | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem : utilisation de t_mailles_territoire |
||
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) | ||
WHERE o.cd_ref = :thiscdref | ||
AND c.insee = :thisInsee | ||
ORDER BY id_maille | ||
""" | ||
observations = connection.execute(text(sql), thisInsee=insee, thiscdref=cd_ref) | ||
tabObs = list() | ||
for o in observations: | ||
temp = { | ||
"id_maille": o.id_maille, | ||
"cd_ref": o.cd_ref, | ||
"taxon": format_taxon_name(o), | ||
"type_code": o.type_code, | ||
"nb_observations": 1, | ||
"annee": o.annee, | ||
"geojson_maille": json.loads(o.geojson_maille), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ne plus utiliser t_maille_territoire.