Skip to content

Commit

Permalink
fix(metadata): fix count of distinct taxon in the acquisition framewo…
Browse files Browse the repository at this point in the history
…rk page (#3290)

* fix(metadata): fix count of distinct taxon in the af page
* fix(test, metadata): fix af taxon stats test
  • Loading branch information
jacquesfize authored Dec 18, 2024
1 parent df951cd commit e0ca4d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,9 @@ def get_acquisition_framework_stats(id_acquisition_framework):
nb_datasets = len(dataset_ids)

nb_taxons = db.session.execute(
select(func.count(Synthese.cd_nom)).where(Synthese.id_dataset.in_(dataset_ids)).distinct()
select(func.count(func.distinct(Synthese.cd_nom))).where(
Synthese.id_dataset.in_(dataset_ids)
)
).scalar_one()

nb_observations = db.session.execute(
Expand Down
12 changes: 12 additions & 0 deletions backend/geonature/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,18 @@ def synthese_data(app, users, datasets, source, sources_modules):
altitude_2,
altitude_3,
),
(
"obs4",
212,
point3,
datasets["own_dataset"],
"obs3",
sources_modules[1],
date_2,
date_3,
altitude_2,
altitude_3,
),
(
"p1_af1",
713776,
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/tests/test_gn_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def test_get_acquisition_framework_stats(
# For each entry, take the max between count_min and count_max. And if
# not provided: count_min and/or count_max is 1. Since one entry in
# synthese is at least 1 taxon
assert data["nb_taxons"] == sum(max(s.count_min or 1, s.count_max or 1) for s in obs)
assert data["nb_taxons"] == len(set([s.cd_nom for s in obs]))

def test_get_acquisition_framework_bbox(self, users, acquisition_frameworks, synthese_data):
# this AF contains at least 2 obs at different locations
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def test_get_observations_for_web_filter_id_source(self, users, synthese_data, s

@pytest.mark.parametrize(
"module_label_to_filter,expected_length",
[(["MODULE_TEST_1"], 2), (["MODULE_TEST_2"], 4), (["MODULE_TEST_1", "MODULE_TEST_2"], 6)],
[(["MODULE_TEST_1"], 2), (["MODULE_TEST_2"], 5), (["MODULE_TEST_1", "MODULE_TEST_2"], 7)],
)
def test_get_observations_for_web_filter_source_by_id_module(
self,
Expand Down

0 comments on commit e0ca4d0

Please sign in to comment.