Skip to content

Commit

Permalink
feat(api): add condition not to filter out on size
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Vergez committed Nov 6, 2023
1 parent 39ccf05 commit 6e5535d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,22 @@ def get_observations_for_web(permissions):
if output_format == "grouped_geom_by_areas":
# SQLAlchemy 1.4: replace column by add_columns
obs_query = obs_query.column(VSyntheseForWebApp.id_synthese)
area_type_where_clause = (
BibAreasTypes.type_code == current_app.config["SYNTHESE"]["AREA_AGGREGATION_TYPE"]
)
# Need to select the size_hierarchy to use is after (only if blurring permissions are found)
if blurring_permissions:
obs_query = obs_query.column(allowed_geom_cte.c.size_hierarchy.label("size_hierarchy"))
area_type_where_clause = sa.and_(
area_type_where_clause,
# Do not select cells which size_hierarchy is bigger than AREA_AGGREGATION_TYPE
# It means that we do not aggregate obs that have a blurring geometry greater in
# size than the aggregation area
sa.or_(
obs_query.c.size_hierarchy.is_(None),
obs_query.c.size_hierarchy <= BibAreasTypes.size_hierarchy,
),
)
obs_query = obs_query.cte("OBS")
agg_areas = (
select([CorAreaSynthese.id_synthese, LAreas.id_area])
Expand All @@ -418,19 +431,7 @@ def get_observations_for_web(permissions):
),
)
.where(CorAreaSynthese.id_synthese == VSyntheseForWebApp.id_synthese)
.where(
sa.and_(
BibAreasTypes.type_code
== current_app.config["SYNTHESE"]["AREA_AGGREGATION_TYPE"],
# Do not select cells which size_hierarchy is bigger than AREA_AGGREGATION_TYPE
# It means that we do not aggregate obs that have a blurring geometry greater in
# size than the aggregation area
sa.or_(
obs_query.c.size_hierarchy.is_(None),
obs_query.c.size_hierarchy <= BibAreasTypes.size_hierarchy,
),
)
)
.where(area_type_where_clause)
.lateral("agg_areas")
)
obs_query = (
Expand Down

0 comments on commit 6e5535d

Please sign in to comment.