Skip to content

Commit

Permalink
Boolean to indicate whether taxon is in the vision model
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed May 13, 2021
1 parent 11e0d8b commit c3d9352
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/controllers/v1/computervision_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const ComputervisionController = class ComputervisionController {
} );
}

static async modelContainsTaxonID( taxonID ) {
static modelContainsTaxonID( taxonID ) {
return !!TFServingTaxonAncestries[taxonID];
}
};
Expand Down
9 changes: 8 additions & 1 deletion lib/controllers/v1/taxa_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const TaxaController = { };
TaxaController.show = async req => {
const ids = _.filter( req.params.id.split( "," ), _.identity );
const filters = [{ terms: { id: ids } }];
return TaxaController.searchQuery( req, { filters, details: true } );
return TaxaController.searchQuery( req, {
filters,
details: true,
assignVisionInclusion: true
} );
};

TaxaController.exact = async req => {
Expand Down Expand Up @@ -726,6 +730,9 @@ TaxaController.searchQuery = async ( req, options = { } ) => {
await Taxon.assignConservationStatuses( taxa, options );
await Taxon.assignListedTaxa( taxa, options );
await Taxon.assignWikipediaSummary( taxa, wikiOpts );
if ( options.assignVisionInclusion ) {
await Taxon.assignVisionInclusion( taxa );
}
return {
total_results: data.hits.total.value,
page: Number( searchHash.page ),
Expand Down
10 changes: 9 additions & 1 deletion lib/models/taxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const _ = require( "lodash" );
const squel = require( "squel" ).useFlavour( "postgres" );
const PromisePool = require( "es6-promise-pool" );
const util = require( "../util" );
const esClient = require( "../es_client" );
const pgClient = require( "../pg_client" );
const Model = require( "./model" );
const ESModel = require( "./es_model" );
Expand Down Expand Up @@ -426,6 +425,15 @@ const Taxon = class Taxon extends Model {
} );
}

static async assignVisionInclusion( taxa ) {
// eslint-disable-next-line global-require
const ComputervisionController = require( "../controllers/v1/computervision_controller" );
await ComputervisionController.cacheAllTaxonAncestries( );
_.each( _.compact( taxa ), t => {
t.vision = ComputervisionController.modelContainsTaxonID( t.id );
} );
}

static async preloadPhotosInto( taxa, options ) {
options = options || { };
const prepareTaxon = t => t.prepareForResponse( options.localeOpts );
Expand Down

0 comments on commit c3d9352

Please sign in to comment.