Skip to content

Commit

Permalink
representative photos require parameter, included as separate attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Dec 24, 2024
1 parent f319554 commit e1df4d1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/controllers/v1/computervision_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ const ComputervisionController = class ComputervisionController {
return;
}
const taxonIDsToLookup = _.map( _.filter(
results, result => result.rank_level < 30
), "taxon_id" );
results, result => result?.taxon?.rank_level < 30
), result => result?.taxon?.id );
if ( _.isEmpty( taxonIDsToLookup ) ) {
return;
}
Expand All @@ -285,10 +285,10 @@ const ComputervisionController = class ComputervisionController {
knn: {
field: "embedding",
query_vector: embedding,
k: 10,
num_candidates: 500
k: 500,
num_candidates: 5000
},
size: 10000,
size: 500,
_source: [
"id",
"taxon_id",
Expand All @@ -300,7 +300,7 @@ const ComputervisionController = class ComputervisionController {
const embeddingsHits = _.map( embeddingsResponse.hits.hits, "_source" );
// TODO: remove this once the ancestor_ids data in the index has been fixed
_.each( embeddingsHits, hit => {
hit.ancestor_ids = _.remove( hit.ancestor_ids, ancestorID => ancestorID === hit.id );
hit.ancestor_ids = _.filter( hit.ancestor_ids, ancestorID => ancestorID !== hit.id );
hit.ancestor_ids.push( hit.taxon_id );
} );
const representativeTaxonPhotos = [];
Expand All @@ -321,9 +321,7 @@ const ComputervisionController = class ComputervisionController {
await ObservationPreload.assignObservationPhotoPhotos( representativeTaxonPhotos );
_.each( representativeTaxonPhotos, taxonPhoto => {
if ( taxonPhoto?.photo?.url ) {
taxonPhoto.taxon.default_photo.url = taxonPhoto.photo.url.replace( "medium", "square" );
taxonPhoto.taxon.default_photo.medium_url = taxonPhoto.photo.url;
taxonPhoto.taxon.default_photo.square_url = taxonPhoto.photo.url.replace( "medium", "square" );
taxonPhoto.taxon.representative_photo = taxonPhoto.photo;
}
} );
}
Expand Down Expand Up @@ -386,10 +384,14 @@ const ComputervisionController = class ComputervisionController {
} );
}

await ComputervisionController.addRepresentativePhotos(
withTaxa,
visionApiResponse.embedding
);
if ( req.userSession?.isAdmin && (
req.body.include_representative_photos || req.query.include_representative_photos
) ) {
await ComputervisionController.addRepresentativePhotos(
withTaxa,
visionApiResponse.embedding
);
}

// remove attributes of common_ancestor that should not be in the response
if ( response.common_ancestor ) {
Expand Down

0 comments on commit e1df4d1

Please sign in to comment.