Skip to content

Commit

Permalink
Merge pull request #158 from biigle/patch-1
Browse files Browse the repository at this point in the history
Fix filtering in process novelty/object detected image jobs
  • Loading branch information
mzur committed Feb 14, 2024
2 parents c77e573 + 384f753 commit 6020a3f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Jobs/ProcessNoveltyDetectedImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(
protected function getAnnotationQuery(VolumeFile $file): Builder
{
return TrainingProposal::where('image_id', $file->id)
->where('job_id', $this->maiaJob->id);
->where('job_id', $this->maiaJob->id)
->when(!empty($this->only), fn ($q) => $q->whereIn('id', $this->only));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Jobs/ProcessObjectDetectedImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(
protected function getAnnotationQuery(VolumeFile $file): Builder
{
return AnnotationCandidate::where('image_id', $file->id)
->where('job_id', $this->maiaJob->id);
->where('job_id', $this->maiaJob->id)
->when(!empty($this->only), fn ($q) => $q->whereIn('id', $this->only));
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/Jobs/ProcessNoveltyDetectedImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ public function testGenerateFeatureVector()
$this->assertEquals(range(0, 383), $vectors[0]->vector->toArray());
}

public function testOnly()
{
$disk = Storage::fake('test');
$image = $this->getImageMock();
$proposal = TrainingProposal::factory()->create([
'points' => [200, 200, 10],
]);
$proposal2 = TrainingProposal::factory()->create([
'points' => [200, 200, 10],
'image_id' => $proposal->image_id,
'job_id' => $proposal->job_id,
]);
$job = new ProcessNoveltyDetectedImageStub($proposal->image, $proposal->job,
targetDisk: 'test', only: [$proposal->id]
);
$job->mock = $image;

$image->shouldReceive('crop')->once()->andReturn($image);
$image->shouldReceive('writeToBuffer')->andReturn('abc123');

$job->handleFile($proposal->image, 'abc');
}

protected function getImageMock($times = 1)
{
$image = Mockery::mock();
Expand Down
23 changes: 23 additions & 0 deletions tests/Jobs/ProcessObjectDetectedImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ public function testGenerateFeatureVector()
$this->assertEquals(range(0, 383), $vectors[0]->vector->toArray());
}

public function testOnly()
{
$disk = Storage::fake('test');
$image = $this->getImageMock();
$candidate = AnnotationCandidate::factory()->create([
'points' => [200, 200, 10],
]);
$candidate2 = AnnotationCandidate::factory()->create([
'points' => [200, 200, 10],
'image_id' => $candidate->image_id,
'job_id' => $candidate->job_id,
]);
$job = new ProcessObjectDetectedImageStub($candidate->image, $candidate->job,
targetDisk: 'test', only: [$candidate->id]
);
$job->mock = $image;

$image->shouldReceive('crop')->once()->andReturn($image);
$image->shouldReceive('writeToBuffer')->andReturn('abc123');

$job->handleFile($candidate->image, 'abc');
}

protected function getImageMock($times = 1)
{
$image = Mockery::mock();
Expand Down

0 comments on commit 6020a3f

Please sign in to comment.