Skip to content

Commit

Permalink
Implement outlier sorting in project Largo UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Jan 12, 2024
1 parent a5b75b4 commit 1715d01
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SortAnnotationsByOutliersController extends Controller
* @apiParam {Number} pid The project ID
* @apiParam {Number} lid The Label ID
* @apiPermission projectMember
* @apiDescription Returns a list of image/video annotation IDs with the outliers first.
* @apiDescription Returns a list of image/video annotation IDs with the outliers first. Image annotation IDs are prefixed with `i` (e.g. `i123`) and video annotation IDs are prefixed with `v` (e.g. `v456`).
*
* @param int $pid Project ID
* @param int $lid Label ID
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=3883a747cf79c488def03032327dd169",
"/assets/scripts/main.js": "/assets/scripts/main.js?id=16cb2b713da212fb07792c1a8a43079b",
"/assets/styles/main.css": "/assets/styles/main.css?id=4bcd521568b8ea929efd8e3f72f7d338"
}
4 changes: 4 additions & 0 deletions src/resources/assets/js/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export default Vue.resource('api/v1/projects{/id}/largo', {}, {
method: 'GET',
url: 'api/v1/projects{/id}/video-annotations/filter/label{/label_id}',
},
sortAnnotationsByOutlier: {
method: 'GET',
url: 'api/v1/projects{/id}/annotations/sort/outliers{/label_id}',
},
});
9 changes: 8 additions & 1 deletion src/resources/assets/js/largoContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ export default {
return VolumesApi.save({id: this.volumeId}, payload);
},
querySortByOutlier(labelId) {
return VolumesApi.sortAnnotationsByOutlier({id: this.volumeId, label_id: labelId});
return VolumesApi.sortAnnotationsByOutlier({id: this.volumeId, label_id: labelId})
.then(function (response) {
// The sorting expects image annotation IDs prefixed with 'i' so it
// can work with mixed image and video annotations.
response.body = response.body.map(id => 'i' + id);
return response;
});
},
},
created() {
Expand Down
10 changes: 8 additions & 2 deletions src/resources/assets/js/mixins/largoContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ export default {
// This will always be missing for the default sorting.
const sequence = this.sortingSequenceCache?.[this.selectedLabel?.id]?.[this.sortingKey];
// TODO Handle mix of image and video annotations.
if (sequence) {
const map = {};
sequence.forEach((id, idx) => map[id] = idx);
annotations.sort((a, b) => map[a.id] - map[b.id]);
// Image annotation IDs are prefixed with 'i', video annotations with
// 'v' to avoid duplicate IDs whe sorting both types of annotations.
annotations.sort((a, b) =>
map[a.type === VIDEO_ANNOTATION ? ('v' + a.id) : ('i' + a.id)] -
map[b.type === VIDEO_ANNOTATION ? ('v' + b.id) : ('i' + b.id)]
);
}
if (this.sortingDirection === SORT_DIRECTION.ASCENDING) {
Expand Down
3 changes: 3 additions & 0 deletions src/resources/assets/js/projectLargoContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export default {
performSave(payload) {
return ProjectsApi.save({id: this.projectId}, payload);
},
querySortByOutlier(labelId) {
return ProjectsApi.sortAnnotationsByOutlier({id: this.projectId, label_id: labelId});
},
},
created() {
this.projectId = biigle.$require('largo.projectId');
Expand Down

0 comments on commit 1715d01

Please sign in to comment.