Skip to content

Commit 3916768

Browse files
committed
Added taxon on photoprediction response
1 parent 7e8a27c commit 3916768

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

api/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@ class Meta:
14291429
photo = SimplePhotoSerializer(read_only=True)
14301430
bbox = BoundingBoxSerializer(source='*')
14311431
scores = PredictionScoreSerializer(source='*')
1432+
taxon = SimpleTaxonSerializer(allow_null=True, read_only=True)
14321433

14331434
class Meta:
14341435
model = PhotoPrediction
@@ -1437,6 +1438,7 @@ class Meta:
14371438
'bbox',
14381439
'insect_confidence',
14391440
'predicted_class',
1441+
'taxon',
14401442
'threshold_deviation',
14411443
'is_decisive',
14421444
'scores',

api/tests/integration/identification_tasks/predictions/create.tavern.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ stages:
9191
y_max: 0.5
9292
insect_confidence: 0.9
9393
predicted_class: 'ae_albopictus'
94+
taxon: !anything
9495
is_decisive: false
9596
threshold_deviation: 0.9
9697
scores:

api/tests/integration/identification_tasks/predictions/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ variables:
1515
y_max: !anyfloat
1616
insect_confidence: !anyfloat
1717
predicted_class: !anystr
18+
taxon: !anything
1819
is_decisive: !anybool
1920
threshold_deviation: !anyfloat
2021
scores:

api/tests/integration/photos/predictions/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ variables:
1515
y_max: !anyfloat
1616
insect_confidence: !anyfloat
1717
predicted_class: !anystr
18+
taxon: !anything
1819
is_decisive: !anybool
1920
threshold_deviation: !anyfloat
2021
scores:

api/tests/test_views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@ def test_is_decisive_False_does_not_set_identification_task(self, api_client, id
217217
assert (identification_task.result_source == IdentificationTask.ResultSource.AI) == is_decisive
218218
assert identification_task.report.published == is_decisive
219219

220+
def test_taxon_is_null(self, api_client, user, identification_task):
221+
photo = identification_task.photo
222+
photo_prediction = create_photo_prediction(photo=photo)
223+
PhotoPrediction.objects.filter(pk=photo_prediction.pk).update(taxon=None)
224+
225+
grant_permission_to_user(type='view', model_class=PhotoPrediction, user=user)
226+
227+
response = api_client.get(
228+
self.build_url(identification_task=identification_task, photo_uuid=photo.uuid),
229+
format='json'
230+
)
231+
assert response.status_code == status.HTTP_200_OK
232+
assert response.data['taxon'] is None
220233

221234
@pytest.mark.django_db
222235
class TestTokenAPI:

api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class PhotoViewSet(
433433
permission_classes=GenericNoMobileViewSet.permission_classes,
434434
parser_classes=GenericViewSet.parser_classes,
435435
serializer_class=PhotoPredictionSerializer,
436-
queryset=PhotoPrediction.objects.all(),
436+
queryset=PhotoPrediction.objects.all().select_related("taxon"),
437437
lookup_field='photo__uuid',
438438
filter_backends=[]
439439
)
@@ -567,7 +567,7 @@ def assign_next(self, request):
567567
]
568568
)
569569
class PhotoPredictionViewSet(IdentificationTaskNestedAttribute, NestedViewSetMixin, CreateModelMixin, RetrieveModelMixin, ListModelMixin, UpdateModelMixin, DestroyModelMixin, GenericNoMobileViewSet):
570-
queryset = PhotoPrediction.objects.all()
570+
queryset = PhotoPrediction.objects.all().select_related("taxon")
571571
permission_classes = (PhotoPredictionPermissions, )
572572

573573
parent_lookup_kwargs = {

0 commit comments

Comments
 (0)