From a3e334602959da37e0ecf848c92d10f049eae885 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Wed, 24 Jan 2024 07:47:50 +0100 Subject: [PATCH] Add new svg annotation generation flags --- src/Console/Commands/GenerateMissing.php | 47 +++++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Console/Commands/GenerateMissing.php b/src/Console/Commands/GenerateMissing.php index 30083bc7..db853475 100644 --- a/src/Console/Commands/GenerateMissing.php +++ b/src/Console/Commands/GenerateMissing.php @@ -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; @@ -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. @@ -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); } @@ -72,6 +87,7 @@ public function handle() if (!$this->option('no-video-annotations')) { $this->handleVideoAnnotations($storage, $pushToQueue, $queue); } + } /** @@ -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) { @@ -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}."); @@ -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) { @@ -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(); }; @@ -165,7 +192,7 @@ protected function handleVideoAnnotations($storage, $pushToQueue, $queue) $progress->finish(); - if($total === 0) { + if ($total === 0) { $this->info("\n"); return; }