Skip to content

Commit

Permalink
feat: add media count and observer count
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Oct 2, 2024
1 parent fb14823 commit 10df084
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from geonature.core.gn_synthese.models import (
BibReportsTypes,
CorAreaSynthese,
CorObserverSynthese,
DefaultsNomenclaturesValue,
Synthese,
TSources,
Expand All @@ -51,6 +52,13 @@
TReport,
SyntheseLogEntry,
)
from geonature.core.gn_commons.models import (
TMedias
)
from geonature.core.gn_commons.models import (TMedias)

from pypnusershub.db import User

from geonature.core.gn_synthese.synthese_config import MANDATORY_COLUMNS
from geonature.core.gn_synthese.utils.species_sheet import SpeciesSheetUtils

Expand Down Expand Up @@ -1027,16 +1035,20 @@ def species_observers(scope, cd_ref):
page = request.args.get("page", 1, int)

Check warning on line 1035 in backend/geonature/core/gn_synthese/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/core/gn_synthese/routes.py#L1034-L1035

Added lines #L1034 - L1035 were not covered by tests

taxref_cd_nom_list = SpeciesSheetUtils.get_cd_nom_list_from_cd_ref(cd_ref)

Check warning on line 1037 in backend/geonature/core/gn_synthese/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/core/gn_synthese/routes.py#L1037

Added line #L1037 was not covered by tests

query = (

Check warning on line 1039 in backend/geonature/core/gn_synthese/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/core/gn_synthese/routes.py#L1039

Added line #L1039 was not covered by tests
db.session.query(
func.trim(func.unnest(func.string_to_array(Synthese.observers, ","))).label(
"observer"
),
User.id_role.label('id_observer'),
func.concat(User.prenom_role, ' ', User.nom_role).label('observer'),
func.min(Synthese.date_min).label("date_min"),
func.max(Synthese.date_max).label("date_max"),
func.count(Synthese.observers).label("count"),
func.count(Synthese.id_synthese).label("observation_count"),
func.count(TMedias.uuid_attached_row).label("media_count"),
)
.group_by("observer")
.group_by(User.id_role)
.join(CorObserverSynthese, CorObserverSynthese.id_synthese == Synthese.id_synthese)
.join(User, User.id_role == CorObserverSynthese.id_role)
.outerjoin(TMedias, TMedias.uuid_attached_row == Synthese.unique_id_sinp)
.where(Synthese.cd_nom.in_(taxref_cd_nom_list))
)
query = SpeciesSheetUtils.get_synthese_query_with_scope(g.current_user, scope, query)

Check warning on line 1054 in backend/geonature/core/gn_synthese/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/core/gn_synthese/routes.py#L1054

Added line #L1054 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class TabObserversComponent implements OnInit {
{ prop: 'observer', name: 'Observateur' },
{ prop: 'date_min', name: 'Plus ancienne' },
{ prop: 'date_max', name: 'Plus récente' },
{ prop: 'count', name: "Nombre d'observations" },
{ prop: 'observation_count', name: "Nombre d'observations" },
{ prop: 'media_count', name: "Nombre de media" },
];

constructor(
Expand Down

0 comments on commit 10df084

Please sign in to comment.