Skip to content

Commit

Permalink
Implement error handling on missing feature vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Oct 12, 2023
1 parent 67612e4 commit db1e698
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
21 changes: 12 additions & 9 deletions src/Http/Controllers/Api/AnnotationCandidateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Biigle\Modules\Maia\Http\Requests\UpdateAnnotationCandidate;
use Biigle\Modules\Maia\Jobs\ConvertAnnotationCandidates;
use Biigle\Modules\Maia\MaiaJob;
use Illuminate\Http\Response;
use Pgvector\Laravel\Distance;
use Queue;

Expand Down Expand Up @@ -89,17 +90,19 @@ public function indexSimilar($id, $id2)
->pluck('id');

$count = $ids->count();
if ($count === 0 || $count === ($job->annotationCandidates()->count() - 1)) {
return $ids;
if ($count === 0) {
abort(Response::HTTP_NOT_FOUND);
}

// Add IDs of candidates without feature vectors at the end.
$ids = $ids->concat(
$job->annotationCandidates()
->whereNotIn('id', $ids)
->whereNot('id', $id2)
->pluck('id')
);
if ($count !== ($job->annotationCandidates()->count() - 1)) {
// Add IDs of candidates without feature vectors at the end.
$ids = $ids->concat(
$job->annotationCandidates()
->whereNotIn('id', $ids)
->whereNot('id', $id2)
->pluck('id')
);
}

return $ids;
}
Expand Down
21 changes: 12 additions & 9 deletions src/Http/Controllers/Api/TrainingProposalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Biigle\Modules\Maia\MaiaJob;
use Biigle\Modules\Maia\MaiaJobState as State;
use Biigle\Modules\Maia\TrainingProposalFeatureVector;
use Illuminate\Http\Response;
use Pgvector\Laravel\Distance;

class TrainingProposalController extends Controller
Expand Down Expand Up @@ -84,17 +85,19 @@ public function indexSimilar($id, $id2)
->pluck('id');

$count = $ids->count();
if ($count === 0 || $count === ($job->trainingProposals()->count() - 1)) {
return $ids;
if ($count === 0) {
abort(Response::HTTP_NOT_FOUND);
}

// Add IDs of proposals without feature vectors at the end.
$ids = $ids->concat(
$job->trainingProposals()
->whereNotIn('id', $ids)
->whereNot('id', $id2)
->pluck('id')
);
if ($count !== ($job->trainingProposals()->count() - 1)) {
// Add IDs of proposals without feature vectors at the end.
$ids = $ids->concat(
$job->trainingProposals()
->whereNotIn('id', $ids)
->whereNot('id', $id2)
->pluck('id')
);
}

return $ids;
}
Expand Down
2 changes: 1 addition & 1 deletion src/public/assets/scripts/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/assets/scripts/main.js": "/assets/scripts/main.js?id=ecb0f7851fd2d188adb2dd39958beede",
"/assets/scripts/main.js": "/assets/scripts/main.js?id=31c5246aff0d21b65b9891658d0fa065",
"/assets/styles/main.css": "/assets/styles/main.css?id=d9c4dfc8488700b3e69f86ede1183aac"
}
8 changes: 7 additions & 1 deletion src/resources/assets/js/show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,13 @@ export default {
.then((response) => {
this.sortedIdsForReferenceCandidate = response.body;
this.referenceCandidate = candidate;
}, handleErrorResponse)
}, (response) => {
if (response.status === 404) {
Messages.warning('No sorting information available yet. Please try again later.');
} else {
handleErrorResponse(response);
}
})
.finally(this.finishLoading);
},
fetchCandidateAnnotations(id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public function testIndexSimilarityEmpty()

$this->beEditor();
$this->getJson("/api/v1/maia-jobs/{$id}/annotation-candidates/similar-to/{$ac1->id}")
->assertStatus(200)
->assertExactJson([]);
->assertStatus(404);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ public function testIndexSimilarityEmpty()

$this->beEditor();
$this->getJson("/api/v1/maia-jobs/{$id}/training-proposals/similar-to/{$tp1->id}")
->assertStatus(200)
->assertExactJson([]);
->assertStatus(404);
}
}

0 comments on commit db1e698

Please sign in to comment.