Skip to content

Commit

Permalink
feat(ca) add dataset detail to acquisiton framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Narcisi committed Jan 8, 2025
1 parent 04f5b02 commit 9cad741
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
21 changes: 21 additions & 0 deletions backend/geonature/core/gn_meta/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ def user_actors(self):
def organism_actors(self):
return [actor.organism for actor in self.cor_dataset_actor if actor.organism is not None]

@hybrid_property
def obs_count(self):
from geonature.core.gn_synthese.models import Synthese

return db.session.scalar(
select(func.count(Synthese.id_synthese))
.select_from(Synthese)
.where(Synthese.id_dataset == self.id_dataset)
)

@hybrid_property
def hab_count(self):
from gn_module_occhab.models import OccurenceHabitat, Station

return db.session.scalar(
select(func.count(OccurenceHabitat.id_habitat))
.select_from(OccurenceHabitat)
.where(Station.id_station == OccurenceHabitat.id_station)
.where(Station.id_dataset == self.id_dataset)
)

def is_deletable(self):
return not DB.session.execute(self.synthese_records.exists().select()).scalar()

Expand Down
16 changes: 0 additions & 16 deletions backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,22 +618,6 @@ def get_export_pdf_acquisition_frameworks(id_acquisition_framework):
dataset_ids = [d.id_dataset for d in af.datasets]
nb_data = len(dataset_ids)

# Add count of Synthese observations for each dataset
for dataset in acquisition_framework["datasets"]:
dataset_obs_count_query = (
select(func.count(Synthese.id_synthese))
.select_from(Synthese)
.where(Synthese.id_dataset == dataset["id_dataset"])
)
dataset_hab_count_query = (
select(func.count(OccurenceHabitat.id_habitat))
.select_from(OccurenceHabitat)
.where(Station.id_station == OccurenceHabitat.id_station)
.where(Station.id_dataset == dataset["id_dataset"])
)
dataset["count_synthese_observations"] = DB.session.scalar(dataset_obs_count_query)
dataset["count_habitats"] = DB.session.scalar(dataset_hab_count_query)

query = (
select(func.count(Synthese.cd_nom))
.select_from(Synthese)
Expand Down
2 changes: 2 additions & 0 deletions backend/geonature/core/gn_meta/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Meta:
cor_territories = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE)
acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", dump_only=True)
sources = MA.Nested(SourceSchema, many=True, dump_only=True)
obs_count = fields.Int(dump_only=True)
hab_count = fields.Int(dump_only=True)

@post_dump(pass_many=False, pass_original=True)
def module_input(self, item, original, many, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@
{{ dataset['dataset_name'] }}
{% endif %}
<br>
{% if dataset['count_synthese_observations']: %}
Nombre d'observations dans la Synthèse : {{ dataset['count_synthese_observations'] }}
{% if dataset['obs_count'] > 0: %}
Nombre d'observations dans la Synthèse : {{ dataset['obs_count'] }}
{% endif %}
<br>
{% if dataset['count_habitats']: %}
Nombre d'habitats dans occhab : {{ dataset['count_habitats'] }}
{% if dataset['hab_count'] > 0: %}
Nombre d'habitats dans occhab : {{ dataset['hab_count'] }}
{% endif %}
</p>
</div>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/metadataModule/af/af-card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ <h5>Jeux de données associés</h5>
<div>
<small>{{ dataset.unique_dataset_id }}</small>
</div>
<div *ngIf="dataset['obs_count'] > 0">
<small>Nombre d'observations dans la Synthèse : {{ dataset['obs_count'] }}</small>
</div>
<div *ngIf="dataset['hab_count']">
<small>Nombre d'habitats dans occhab : {{ dataset['hab_count'] }}</small>
</div>
</td>
</tr>
</table>
Expand Down

0 comments on commit 9cad741

Please sign in to comment.