-
Notifications
You must be signed in to change notification settings - Fork 103
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
[CONFIG] Taxon sheet and config #3312
Open
edelclaux
wants to merge
7
commits into
PnX-SI:develop
Choose a base branch
from
naturalsolutions:feat/taxon-sheet-and-config
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.
+116
−81
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fc66bb
feat: add 'ENABLE_TAXON_SHEETS' option in 'SYNTHESE'
edelclaux 31d7353
feat: ENABLE_XXX to ENABLE_TAB_XXX for taxon sheet tab
edelclaux a57d0bc
feat: add a relation between 'FRONTEND.ENABLE_PROFILES' and 'SYNTHESE…
edelclaux 9cf9a35
fix: ENABLE_TAB_PROFILES --> ENABLE_TAB_PROFILE
edelclaux ed90d50
lint
edelclaux eafc120
feat(config): profile display config coherence moved to config_schema
jacquesfize 17678ab
Remove obsolete comment
edelclaux 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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -82,6 +82,7 @@ | |||||||
VMTaxrefListForautocomplete, | ||||||||
) | ||||||||
|
||||||||
from geonature import app | ||||||||
|
||||||||
routes = Blueprint("gn_synthese", __name__) | ||||||||
|
||||||||
|
@@ -958,80 +959,88 @@ def general_stats(permissions): | |||||||
return data | ||||||||
|
||||||||
|
||||||||
@routes.route("/taxon_stats/<int:cd_nom>", methods=["GET"]) | ||||||||
@permissions.check_cruved_scope("R", get_scope=True, module_code="SYNTHESE") | ||||||||
@json_resp | ||||||||
def taxon_stats(scope, cd_nom): | ||||||||
"""Return stats for a specific taxon""" | ||||||||
## ############################################################################ | ||||||||
## TAXON SHEET ROUTES | ||||||||
## ############################################################################ | ||||||||
|
||||||||
area_type = request.args.get("area_type") | ||||||||
if app.config["SYNTHESE"]["ENABLE_TAXON_SHEETS"]: | ||||||||
|
||||||||
if not area_type: | ||||||||
raise BadRequest("Missing area_type parameter") | ||||||||
@routes.route("/taxon_stats/<int:cd_nom>", methods=["GET"]) | ||||||||
@permissions.check_cruved_scope("R", get_scope=True, module_code="SYNTHESE") | ||||||||
@json_resp | ||||||||
def taxon_stats(scope, cd_nom): | ||||||||
"""Return stats for a specific taxon""" | ||||||||
|
||||||||
# Ensure area_type is valid | ||||||||
valid_area_types = ( | ||||||||
db.session.query(BibAreasTypes.type_code) | ||||||||
.distinct() | ||||||||
.filter(BibAreasTypes.type_code == area_type) | ||||||||
.scalar() | ||||||||
) | ||||||||
if not valid_area_types: | ||||||||
raise BadRequest("Invalid area_type") | ||||||||
|
||||||||
# Subquery to fetch areas based on area_type | ||||||||
areas_subquery = ( | ||||||||
select([LAreas.id_area]) | ||||||||
.where(LAreas.id_type == BibAreasTypes.id_type) | ||||||||
.where(BibAreasTypes.type_code == area_type) | ||||||||
.alias("areas") | ||||||||
) | ||||||||
cd_ref = db.session.scalar(select(Taxref.cd_ref).where(Taxref.cd_nom == cd_nom)) | ||||||||
taxref_cd_nom_list = db.session.scalars(select(Taxref.cd_nom).where(Taxref.cd_ref == cd_ref)) | ||||||||
area_type = request.args.get("area_type") | ||||||||
|
||||||||
# Main query to fetch stats | ||||||||
query = ( | ||||||||
select( | ||||||||
[ | ||||||||
func.count(distinct(Synthese.id_synthese)).label("observation_count"), | ||||||||
func.count(distinct(Synthese.observers)).label("observer_count"), | ||||||||
func.count(distinct(areas_subquery.c.id_area)).label("area_count"), | ||||||||
func.min(Synthese.altitude_min).label("altitude_min"), | ||||||||
func.max(Synthese.altitude_max).label("altitude_max"), | ||||||||
func.min(Synthese.date_min).label("date_min"), | ||||||||
func.max(Synthese.date_max).label("date_max"), | ||||||||
] | ||||||||
if not area_type: | ||||||||
raise BadRequest("Missing area_type parameter") | ||||||||
|
||||||||
# Ensure area_type is valid | ||||||||
valid_area_types = ( | ||||||||
db.session.query(BibAreasTypes.type_code) | ||||||||
.distinct() | ||||||||
.filter(BibAreasTypes.type_code == area_type) | ||||||||
.scalar() | ||||||||
) | ||||||||
.select_from( | ||||||||
sa.join( | ||||||||
Synthese, | ||||||||
CorAreaSynthese, | ||||||||
Synthese.id_synthese == CorAreaSynthese.id_synthese, | ||||||||
) | ||||||||
.join(areas_subquery, CorAreaSynthese.id_area == areas_subquery.c.id_area) | ||||||||
.join(LAreas, CorAreaSynthese.id_area == LAreas.id_area) | ||||||||
.join(BibAreasTypes, LAreas.id_type == BibAreasTypes.id_type) | ||||||||
if not valid_area_types: | ||||||||
raise BadRequest("Invalid area_type") | ||||||||
|
||||||||
# Subquery to fetch areas based on area_type | ||||||||
areas_subquery = ( | ||||||||
select([LAreas.id_area]) | ||||||||
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.
Suggested change
|
||||||||
.where(LAreas.id_type == BibAreasTypes.id_type) | ||||||||
.where(BibAreasTypes.type_code == area_type) | ||||||||
Comment on lines
+992
to
+993
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.
Suggested change
|
||||||||
.alias("areas") | ||||||||
) | ||||||||
cd_ref = db.session.scalar(select(Taxref.cd_ref).where(Taxref.cd_nom == cd_nom)) | ||||||||
taxref_cd_nom_list = db.session.scalars( | ||||||||
select(Taxref.cd_nom).where(Taxref.cd_ref == cd_ref) | ||||||||
) | ||||||||
.where(Synthese.cd_nom.in_(taxref_cd_nom_list)) | ||||||||
) | ||||||||
|
||||||||
synthese_query_obj = SyntheseQuery(Synthese, query, {}) | ||||||||
synthese_query_obj.filter_query_with_cruved(g.current_user, scope) | ||||||||
result = DB.session.execute(synthese_query_obj.query) | ||||||||
synthese_stats = result.fetchone() | ||||||||
# Main query to fetch stats | ||||||||
query = ( | ||||||||
select( | ||||||||
[ | ||||||||
func.count(distinct(Synthese.id_synthese)).label("observation_count"), | ||||||||
func.count(distinct(Synthese.observers)).label("observer_count"), | ||||||||
func.count(distinct(areas_subquery.c.id_area)).label("area_count"), | ||||||||
func.min(Synthese.altitude_min).label("altitude_min"), | ||||||||
func.max(Synthese.altitude_max).label("altitude_max"), | ||||||||
func.min(Synthese.date_min).label("date_min"), | ||||||||
func.max(Synthese.date_max).label("date_max"), | ||||||||
] | ||||||||
) | ||||||||
.select_from( | ||||||||
sa.join( | ||||||||
Synthese, | ||||||||
CorAreaSynthese, | ||||||||
Synthese.id_synthese == CorAreaSynthese.id_synthese, | ||||||||
) | ||||||||
.join(areas_subquery, CorAreaSynthese.id_area == areas_subquery.c.id_area) | ||||||||
.join(LAreas, CorAreaSynthese.id_area == LAreas.id_area) | ||||||||
.join(BibAreasTypes, LAreas.id_type == BibAreasTypes.id_type) | ||||||||
) | ||||||||
.where(Synthese.cd_nom.in_(taxref_cd_nom_list)) | ||||||||
) | ||||||||
|
||||||||
data = { | ||||||||
"cd_ref": cd_nom, | ||||||||
"observation_count": synthese_stats["observation_count"], | ||||||||
"observer_count": synthese_stats["observer_count"], | ||||||||
"area_count": synthese_stats["area_count"], | ||||||||
"altitude_min": synthese_stats["altitude_min"], | ||||||||
"altitude_max": synthese_stats["altitude_max"], | ||||||||
"date_min": synthese_stats["date_min"], | ||||||||
"date_max": synthese_stats["date_max"], | ||||||||
} | ||||||||
synthese_query_obj = SyntheseQuery(Synthese, query, {}) | ||||||||
synthese_query_obj.filter_query_with_cruved(g.current_user, scope) | ||||||||
result = DB.session.execute(synthese_query_obj.query) | ||||||||
synthese_stats = result.fetchone() | ||||||||
|
||||||||
data = { | ||||||||
"cd_ref": cd_nom, | ||||||||
"observation_count": synthese_stats["observation_count"], | ||||||||
"observer_count": synthese_stats["observer_count"], | ||||||||
"area_count": synthese_stats["area_count"], | ||||||||
"altitude_min": synthese_stats["altitude_min"], | ||||||||
"altitude_max": synthese_stats["altitude_max"], | ||||||||
"date_min": synthese_stats["date_min"], | ||||||||
"date_max": synthese_stats["date_max"], | ||||||||
} | ||||||||
|
||||||||
return data | ||||||||
return data | ||||||||
|
||||||||
|
||||||||
@routes.route("/taxons_tree", methods=["GET"]) | ||||||||
|
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
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.
Souvent, on passe plutôt par le
current_app
deflask