Skip to content

Commit

Permalink
Add new svg annotation generation flags
Browse files Browse the repository at this point in the history
  • Loading branch information
lehecht committed Jan 24, 2024
1 parent 477696c commit a3e3346
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/Console/Commands/GenerateMissing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Biigle\ImageAnnotation;
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationPatch;
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationSVGPatch;
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationPatch;
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationSVGPatch;
use Biigle\VideoAnnotation;
use Carbon\Carbon;
use File;
Expand All @@ -19,7 +21,7 @@ class GenerateMissing extends Command
* @var string
*/
protected $signature = 'largo:generate-missing {--dry-run} {--volume=} {--no-image-annotations} {--no-video-annotations} {--queue=} {--newer-than=}
{--older-than=}';
{--older-than=} {--only-image-svg-annotations} {--only-video-svg-annotations}';

/**
* The console command description.
Expand Down Expand Up @@ -63,6 +65,19 @@ public function handle()
$storage = Storage::disk(config('largo.patch_storage_disk'));
$queue = $this->option('queue') ?: config('largo.generate_annotation_patch_queue');

if ($this->option('only-image-svg-annotations')) {
$onlySVG = true;
$this->handleImageAnnotations($storage, $pushToQueue, $queue, $onlySVG);
return;
}

if ($this->option('only-video-svg-annotations')) {
$onlySVG = true;
$this->handleVideoAnnotations($storage, $pushToQueue, $queue, $onlySVG);
return;

}

if (!$this->option('no-image-annotations')) {
$this->handleImageAnnotations($storage, $pushToQueue, $queue);
}
Expand All @@ -72,6 +87,7 @@ public function handle()
if (!$this->option('no-video-annotations')) {
$this->handleVideoAnnotations($storage, $pushToQueue, $queue);
}

}

/**
Expand All @@ -81,7 +97,7 @@ public function handle()
* @param bool $pushToQueue
* @param string $queue
*/
protected function handleImageAnnotations($storage, $pushToQueue, $queue)
protected function handleImageAnnotations($storage, $pushToQueue, $queue, $onlySVG = false)
{
$annotations = ImageAnnotation::join('images', 'images.id', '=', 'image_annotations.image_id')
->when($this->option('volume'), function ($query) {
Expand All @@ -99,28 +115,35 @@ protected function handleImageAnnotations($storage, $pushToQueue, $queue)
$progress = $this->output->createProgressBar($total);
$this->info("Checking {$total} image annotations...");

$handleAnnotation = function ($annotation) use ($progress, $pushToQueue, $storage, $queue) {
$handleAnnotation = function ($annotation) use ($progress, $pushToQueue, $storage, $queue, $onlySVG) {
$prefix = fragment_uuid_path($annotation->uuid);
if (!$storage->exists("{$prefix}/{$annotation->id}.{$this->format}")) {
$this->count++;
if ($pushToQueue) {
if ($pushToQueue && !$onlySVG) {
GenerateImageAnnotationPatch::dispatch($annotation)
->onQueue($queue);
}
}
if (!$storage->exists("{$prefix}/{$annotation->id}.svg")) {
if ($pushToQueue) {
GenerateImageAnnotationSVGPatch::dispatch($annotation)
->onQueue($queue);
}
}
$progress->advance();
};

$annotations->eachById($handleAnnotation, 10000, 'image_annotations.id', 'id');

$progress->finish();
if($total === 0) {

if ($total === 0) {
$this->info("\n");
return;
}

$percent = round($this->count / $total * 100, 2);

$this->info("\nFound {$this->count} image annotations with missing patches ({$percent} %).");
if ($pushToQueue) {
$this->info("Pushed {$this->count} jobs to queue {$queue}.");
Expand All @@ -134,7 +157,7 @@ protected function handleImageAnnotations($storage, $pushToQueue, $queue)
* @param bool $pushToQueue
* @param string $queue
*/
protected function handleVideoAnnotations($storage, $pushToQueue, $queue)
protected function handleVideoAnnotations($storage, $pushToQueue, $queue, $onlySVG = false)
{
$annotations = VideoAnnotation::join('videos', 'videos.id', '=', 'video_annotations.video_id')
->when($this->option('volume'), function ($query) {
Expand All @@ -149,14 +172,18 @@ protected function handleVideoAnnotations($storage, $pushToQueue, $queue)
$progress = $this->output->createProgressBar($total);
$this->info("Checking {$total} video annotations...");

$handleAnnotation = function ($annotation) use ($progress, $pushToQueue, $storage, $queue) {
$handleAnnotation = function ($annotation) use ($progress, $pushToQueue, $storage, $queue, $onlySVG) {
$prefix = fragment_uuid_path($annotation->uuid);
if (!$storage->exists("{$prefix}/v-{$annotation->id}.{$this->format}")) {
$this->count++;
if ($pushToQueue) {
if ($pushToQueue && !$onlySVG) {
GenerateVideoAnnotationPatch::dispatch($annotation)
->onQueue($queue);
}
if ($pushToQueue) {
GenerateVideoAnnotationSVGPatch::dispatch($annotation)
->onQueue($queue);
}
}
$progress->advance();
};
Expand All @@ -165,7 +192,7 @@ protected function handleVideoAnnotations($storage, $pushToQueue, $queue)

$progress->finish();

if($total === 0) {
if ($total === 0) {
$this->info("\n");
return;
}
Expand Down

0 comments on commit a3e3346

Please sign in to comment.