Skip to content

Commit

Permalink
Merge pull request #760 from biigle/ui-object-tracking-limit
Browse files Browse the repository at this point in the history
Disable tracking button if job limit is exceeded
  • Loading branch information
mzur authored Feb 16, 2024
2 parents f0f2aeb + 3f53748 commit b9ae8e0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/VideoAnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function store(StoreVideoAnnotation $request)
$queue = config('videos.track_object_queue');
Queue::pushOn($queue, new TrackObject($annotation, $request->user()));
Cache::increment(TrackObject::getRateLimitCacheKey($request->user()));
$annotation->trackingJobLimitReached = $currentJobs === ($maxJobs - 1);
}

$annotation->load('labels.label', 'labels.user');
Expand Down
13 changes: 11 additions & 2 deletions resources/assets/js/videos/components/videoScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
icon="fa-project-diagram"
title="Finish and track the point annotation"
v-on:click="finishTrackAnnotation"
:disabled="cantFinishTrackAnnotation"
:disabled="cantFinishTrackAnnotation || disableJobTracking"
:loading="disableJobTracking"
></control-button>
</control-button>
<control-button
Expand Down Expand Up @@ -97,7 +98,8 @@
icon="fa-project-diagram"
title="Finish and track the circle annotation"
v-on:click="finishTrackAnnotation"
:disabled="cantFinishTrackAnnotation"
:disabled="cantFinishTrackAnnotation || disableJobTracking"
:loading="disableJobTracking"
></control-button>
</control-button>
<control-button
Expand Down Expand Up @@ -351,6 +353,10 @@ export default {
type: Boolean,
default: false,
},
reachedTrackedAnnotationLimit: {
type: Boolean,
default: false,
}
},
data() {
return {
Expand Down Expand Up @@ -379,6 +385,9 @@ export default {
return '';
},
disableJobTracking() {
return this.reachedTrackedAnnotationLimit;
},
},
methods: {
createMap() {
Expand Down
16 changes: 15 additions & 1 deletion resources/assets/js/videos/videoContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
user: null,
attachingLabel: false,
swappingLabel: false,
disableJobTracking: false,
};
},
computed: {
Expand Down Expand Up @@ -164,6 +165,9 @@ export default {
},
annotationCount() {
return this.annotations.length;
},
reachedTrackedAnnotationLimit() {
return this.disableJobTracking;
}
},
methods: {
Expand Down Expand Up @@ -281,7 +285,15 @@ export default {
delete annotation.shape;
return VideoAnnotationApi.save({id: this.videoId}, annotation)
.then(this.addCreatedAnnotation, handleErrorResponse)
.then((res) => {
if (tmpAnnotation.track) {
this.disableJobTracking = res.body.trackingJobLimitReached;
}
return this.addCreatedAnnotation(res);
}, (res) => {
handleErrorResponse(res);
this.disableJobTracking = res.status === 429;
})
.finally(() => {
let index = this.annotations.indexOf(tmpAnnotation);
if (index !== -1) {
Expand Down Expand Up @@ -620,12 +632,14 @@ export default {
handleSucceededTracking(event) {
let annotation = this.annotations.find(a => a.id === event.annotation.id);
if (annotation) {
this.disableJobTracking = false;
annotation.finishTracking(event.annotation);
}
},
handleFailedTracking(event) {
let annotation = this.annotations.find(a => a.id === event.annotation.id);
if (annotation) {
this.disableJobTracking = false;
annotation.failTracking();
}
},
Expand Down
1 change: 1 addition & 0 deletions resources/views/videos/show/content.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
:show-prev-next="hasSiblingVideos"
:has-error="hasError"
:seeking="seeking"
:reached-tracked-annotation-limit="reachedTrackedAnnotationLimit"
v-on:create-annotation="createAnnotation"
v-on:track-annotation="trackAnnotation"
v-on:split-annotation="splitAnnotation"
Expand Down
30 changes: 30 additions & 0 deletions tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,36 @@ public function testStoreAndTrackRestrictRateLimit()

}

public function testTrackingJobLimit()
{
Queue::fake();
$this->beEditor();
$res = $this
->postJson("/api/v1/videos/{$this->video->id}/annotations", [
'shape_id' => Shape::pointId(),
'label_id' => $this->labelRoot()->id,
'points' => [[10, 11]],
'frames' => [0.0],
'track' => true,
])->assertSuccessful();

$this->assertEquals(1, Cache::get(TrackObject::getRateLimitCacheKey($this->editor())));
$this->assertFalse($res->json()['trackingJobLimitReached']);

Cache::set(TrackObject::getRateLimitCacheKey($this->editor()), 9);
$res = $this
->postJson("/api/v1/videos/{$this->video->id}/annotations", [
'shape_id' => Shape::pointId(),
'label_id' => $this->labelRoot()->id,
'points' => [[10, 11]],
'frames' => [0.0],
'track' => true,
])->assertSuccessful();

$this->assertEquals(10, Cache::get(TrackObject::getRateLimitCacheKey($this->editor())));
$this->assertTrue($res->json()['trackingJobLimitReached']);
}

public function testStoreWholeFrameAnnotation()
{
$this->beEditor();
Expand Down

0 comments on commit b9ae8e0

Please sign in to comment.