Skip to content

Commit

Permalink
merge #517
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed May 22, 2024
2 parents 551ec5a + c3c1c6c commit fbe3ef7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
33 changes: 19 additions & 14 deletions atlas/modeles/repositories/vmCommunesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,25 @@ def getCommuneFromInsee(connection, insee):


def getCommunesObservationsChilds(connection, cd_ref):
sql = "SELECT * FROM atlas.find_all_taxons_childs(:thiscdref) AS taxon_childs(cd_nom)"
results = connection.execute(text(sql), thiscdref=cd_ref)
taxons = [cd_ref]
for r in results:
taxons.append(r.cd_nom)

sql = """
SELECT DISTINCT (com.insee) AS insee, com.commune_maj
FROM atlas.vm_communes com
JOIN atlas.vm_observations obs
ON obs.insee = com.insee
WHERE obs.cd_ref IN (
SELECT * FROM atlas.find_all_taxons_childs(:thiscdref)
)
OR obs.cd_ref = :thiscdref
SELECT DISTINCT
com.commune_maj,
com.insee
FROM atlas.vm_observations AS obs
JOIN atlas.vm_communes AS com
ON obs.insee = com.insee
WHERE obs.cd_ref = ANY(:taxonsList)
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
results = connection.execute(text(sql), taxonsList=taxons)
municipalities = list()
for r in results:
municipality = {"insee": r.insee, "commune_maj": r.commune_maj}
municipalities.append(municipality)
return municipalities
19 changes: 11 additions & 8 deletions atlas/modeles/repositories/vmObservationsRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ def observersParser(req):


def getObservers(connection, cd_ref):
sql = "SELECT * FROM atlas.find_all_taxons_childs(:thiscdref) AS taxon_childs(cd_nom)"
results = connection.execute(text(sql), thiscdref=cd_ref)
taxons = [cd_ref]
for r in results:
taxons.append(r.cd_nom)

sql = """
SELECT DISTINCT observateurs
FROM atlas.vm_observations
WHERE cd_ref IN (
SELECT * FROM atlas.find_all_taxons_childs(:thiscdref)
)
OR cd_ref = :thiscdref
SELECT DISTINCT observateurs
FROM atlas.vm_observations
WHERE cd_ref = ANY(:taxonsList)
"""
req = connection.execute(text(sql), thiscdref=cd_ref)
return observersParser(req)
results = connection.execute(text(sql), taxonsList=taxons)
return observersParser(results)


def getGroupeObservers(connection, groupe):
Expand Down

0 comments on commit fbe3ef7

Please sign in to comment.