From c8c009ea5f2004c15fa45cda2e34786fd8c39086 Mon Sep 17 00:00:00 2001 From: Jon Van Oast Date: Tue, 24 Oct 2023 13:05:09 -0600 Subject: [PATCH] add number individuals --- app/modules/sightings/models.py | 3 +++ app/modules/sightings/schemas.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/modules/sightings/models.py b/app/modules/sightings/models.py index 6c20229c0..ec21216b1 100644 --- a/app/modules/sightings/models.py +++ b/app/modules/sightings/models.py @@ -949,6 +949,9 @@ def individuals(self): indivs.add(enc.individual) return indivs + def get_number_individuals(self): + return len(self.individuals) + def get_individual_names(self): names = set() for indiv in self.individuals: diff --git a/app/modules/sightings/schemas.py b/app/modules/sightings/schemas.py index aa0d47a0b..4ce94d9d6 100644 --- a/app/modules/sightings/schemas.py +++ b/app/modules/sightings/schemas.py @@ -80,6 +80,7 @@ class ElasticsearchSightingSchema(BaseSightingSchema): encounters = base_fields.Function(lambda s: s.get_encounters_elasticsearch()) numberImages = base_fields.Function(lambda s: s.get_number_assets()) numberAnnotations = base_fields.Function(lambda s: s.get_number_annotations()) + numberIndividuals = base_fields.Function(lambda s: s.get_number_individuals()) # apparently sets do NOT work well, so we need to name-sets to lists here individualNames = base_fields.Function(lambda s: list(s.get_individual_names())) individualNamesWithContexts = base_fields.Function( @@ -116,6 +117,7 @@ class Meta: 'encounters', 'numberImages', 'numberAnnotations', + 'numberIndividuals', 'individualNames', 'individualNamesWithContexts', )