Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Jan 8, 2025
1 parent 76671dc commit 022289d
Show file tree
Hide file tree
Showing 60 changed files with 329 additions and 658 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/ProjectReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ProjectReportController extends Controller
* @apiParam (Optional arguments) {Boolean} aggregate_child_labels If `true`, add the abundance of child labels to the abundance of their parent labels and omit the child labels. This is only valid for the abundance report. Labels that are excluded with `only_labels` are not counted.
* @apiParam (Optional arguments) {Boolean} disable_notifications If `true`, suppress notification to the user on report completion.
* @apiParam (Optional arguments) {Boolean} strip_ifdo If `true`, remove annotation information from the original iFDO file before it is populated with BIIGLE annotations. Only available for the iFDO report.
*
*
* @apiPermission projectMember
*
* @param StoreProjectReport $request
* @param int $id Project ID
*
*
* @return mixed
*/
public function store(StoreProjectReport $request, $id)
Expand Down
10 changes: 3 additions & 7 deletions app/Http/Controllers/Views/Projects/ProjectReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Biigle\Http\Controllers\Views\Controller;
use Biigle\Modules\MetadataIfdo\IfdoParser;
use Biigle\ReportType;
use Biigle\Project;
use Biigle\ReportType;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

Expand Down Expand Up @@ -38,12 +38,8 @@ protected function show(Request $request, $id)
->wherePivot('pinned', true)
->count();

$types = ReportType::when($hasImageVolume, function ($query) {
$query->where('name', 'like', 'Image%');
})
->when($hasVideoVolume, function ($query) {
$query->orWhere('name', 'like', 'Video%');
})
$types = ReportType::when($hasImageVolume, fn ($q) => $q->where('name', 'like', 'Image%'))
->when($hasVideoVolume, fn ($q) => $q->orWhere('name', 'like', 'Video%'))
->orderBy('name', 'asc')
->get();

Expand Down
41 changes: 21 additions & 20 deletions app/Http/Controllers/Views/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,26 +367,27 @@ public function searchReports(User $user, $query, $type)
if ($query) {
$queryBuilder = $queryBuilder
->where(function ($q) use ($query) {
$q->where(function ($q) use ($query) {
$q->where('reports.source_type', Volume::class)
->whereExists(function ($q) use ($query) {
$q->select(DB::raw(1))
->from('volumes')
->whereRaw('reports.source_id = volumes.id')
->where('volumes.name', 'ilike', "%{$query}%");
});
})
->orWhere(function ($q) use ($query) {
$q->where('reports.source_type', Project::class)
->whereExists(function ($q) use ($query) {
$q->select(DB::raw(1))
->from('projects')
->whereRaw('reports.source_id = projects.id')
->where('projects.name', 'ilike', "%{$query}%");
});
})
// Kept for backwards compatibility of single video reports.
->orWhere('reports.source_name', 'ilike', "%{$query}%");
$q
->where(function ($q) use ($query) {
$q->where('reports.source_type', Volume::class)
->whereExists(function ($q) use ($query) {
$q->select(DB::raw(1))
->from('volumes')
->whereRaw('reports.source_id = volumes.id')
->where('volumes.name', 'ilike', "%{$query}%");
});
})
->orWhere(function ($q) use ($query) {
$q->where('reports.source_type', Project::class)
->whereExists(function ($q) use ($query) {
$q->select(DB::raw(1))
->from('projects')
->whereRaw('reports.source_id = projects.id')
->where('projects.name', 'ilike', "%{$query}%");
});
})
// Kept for backwards compatibility of single video reports.
->orWhere('reports.source_name', 'ilike', "%{$query}%");
});
}

Expand Down
11 changes: 3 additions & 8 deletions app/Http/Controllers/Views/Volumes/VolumeReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use Biigle\Http\Controllers\Views\Controller;
use Biigle\LabelTree;
use Biigle\Modules\MetadataIfdo\IfdoParser;
use Biigle\ReportType;
use Biigle\Project;
use Biigle\Role;
use Biigle\ReportType;
use Biigle\Volume;
use Illuminate\Http\Request;

Expand All @@ -25,12 +24,8 @@ public function show(Request $request, $id)
$volume = Volume::findOrFail($id);
$this->authorize('access', $volume);
$sessions = $volume->annotationSessions()->orderBy('starts_at', 'desc')->get();
$types = ReportType::when($volume->isImageVolume(), function ($query) {
$query->where('name', 'like', 'Image%');
})
->when($volume->isVideoVolume(), function ($query) {
$query->where('name', 'like', 'Video%');
})
$types = ReportType::when($volume->isImageVolume(), fn ($q) => $q->where('name', 'like', 'Image%'))
->when($volume->isVideoVolume(), fn ($q) => $q->where('name', 'like', 'Video%'))
->orderBy('name', 'asc')
->get();

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Requests/StoreProjectReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Biigle\Modules\MetadataIfdo\IfdoParser;
use Biigle\Project;
use Biigle\ReportType;
use Illuminate\Validation\Rule;

class StoreProjectReport extends StoreReport
{
Expand Down Expand Up @@ -112,9 +111,7 @@ protected function validateGeoInfo($validator)
$hasGeoInfo = $this->project->imageVolumes()
->select('id')
->get()
->reduce(function ($carry, $volume) {
return $carry && $volume->hasGeoInfo();
}, true);
->reduce(fn ($carry, $volume) => $carry && $volume->hasGeoInfo(), true);

if (!$hasGeoInfo) {
$validator->errors()->add('id', 'No volume has images with geo coordinates.');
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Requests/StoreReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace Biigle\Http\Requests;

use Biigle\MediaType;
use Biigle\Project;
use Biigle\ReportType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreReport extends FormRequest
{
Expand Down
2 changes: 0 additions & 2 deletions app/Jobs/GenerateReportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Biigle\Jobs;

use Biigle\Jobs\Job;
use Biigle\Notifications\ReportReady;
use Biigle\Report;
use Biigle\User;
use Carbon\Carbon;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
Expand Down
4 changes: 1 addition & 3 deletions app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class UserObserver
public function deleting($user)
{
Report::where('user_id', $user->id)
->eachById(function ($report) {
return $report->deleteFile();
});
->eachById(fn ($report) => $report->deleteFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Biigle\Services\Reports\Projects\VideoAnnotations;

use Biigle\Services\Reports\File;
use Biigle\Services\Reports\Projects\ProjectVideoReportGenerator;
use Biigle\Services\Reports\Volumes\VideoAnnotations\CsvReportGenerator as ReportGenerator;

Expand Down
9 changes: 2 additions & 7 deletions app/Services/Reports/Volumes/IfdoReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
use Biigle\LabelSource;
use Biigle\Modules\MetadataIfdo\IfdoParser;
use Biigle\Shape;
use Biigle\Video;
use Biigle\Volume;
use DB;
use Exception;
use File;
use Storage;
Expand Down Expand Up @@ -95,8 +93,7 @@ public function generateReport($path)
}, $this->imageAnnotationCreators);

if ($this->options->get('stripIfdo', false)) {
unset($ifdo['image-set-header']['image-annotation-creators']);
unset($ifdo['image-set-header']['image-annotation-labels']);
unset($ifdo['image-set-header']['image-annotation-creators'], $ifdo['image-set-header']['image-annotation-labels']);
if (array_key_exists('image-set-items', $ifdo)) {
foreach ($ifdo['image-set-items'] as &$item) {
if ($this->isArrayItem($item)) {
Expand Down Expand Up @@ -246,9 +243,7 @@ protected function getWormsUrn($label)
*/
protected function isArrayItem($item)
{
return !empty($item) && array_reduce(array_keys($item), function ($carry, $key) {
return $carry && is_numeric($key);
}, true);
return !empty($item) && array_reduce(array_keys($item), fn ($carry, $key) => $carry && is_numeric($key), true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ protected function aggregateChildLabels($rows, $labels)
return in_array($value, $onlyLabels) ? $value : null;
});
})
->reject(function ($value) {
return is_null($value);
});
->reject(fn ($value) => is_null($value));

// Determine the highest parent label for all child labels.
do {
Expand Down Expand Up @@ -213,16 +211,12 @@ protected function aggregateChildLabels($rows, $labels)

// Remove rows of child labels so they are not counted twice.
$rows[$filename] = $annotations->values()
->reject(function ($annotation) use ($parentIdMap) {
return $parentIdMap->has($annotation->label_id);
});
->reject(fn ($annotation) => $parentIdMap->has($annotation->label_id));
}

// Remove all labels that did not occur (as parent) in the rows.
$presentLabels = $presentLabels->unique()->flip();
$labels = $labels->filter(function ($label) use ($presentLabels) {
return $presentLabels->has($label->id);
});
$labels = $labels->filter(fn ($label) => $presentLabels->has($label->id));

return [$rows, $labels];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Biigle\Services\Reports\Volumes\ImageAnnotations;

use Biigle\ImageAnnotationLabel;
use Biigle\LabelTree;
use Biigle\Services\Reports\File;
use Biigle\Services\Reports\MakesZipArchives;
use Biigle\Shape;
use Biigle\User;
use DB;
use GeoJson\Feature\Feature;
use GeoJson\Feature\FeatureCollection;
use GeoJson\Geometry\LineString;
use GeoJson\Geometry\Point;
use GeoJson\Geometry\Polygon;
Expand Down Expand Up @@ -95,28 +93,29 @@ public function generateReport($path)
*/
public function query()
{
return $this->initQuery([
'image_annotation_labels.id as annotation_label_id',
'image_annotation_labels.label_id',
'image_annotations.image_id',
'image_annotations.shape_id',
'images.filename',
'images.attrs->metadata->yaw as yaw',
'images.attrs->metadata->distance_to_ground as distance_to_ground',
'images.attrs->width as width',
'images.attrs->height as height',
'images.lat',
'images.lng',
'image_annotations.points',
'image_annotation_labels.id as annotation_label_id',
'labels.name as label_name',
])
->whereNotNull('images.lat')
->whereNotNull('images.lng')
->whereNotNull('images.attrs->width')
->whereNotNull('images.attrs->height')
->whereNotNull('images.attrs->metadata->distance_to_ground')
->whereNotNull('images.attrs->metadata->yaw');
return $this
->initQuery([
'image_annotation_labels.id as annotation_label_id',
'image_annotation_labels.label_id',
'image_annotations.image_id',
'image_annotations.shape_id',
'images.filename',
'images.attrs->metadata->yaw as yaw',
'images.attrs->metadata->distance_to_ground as distance_to_ground',
'images.attrs->width as width',
'images.attrs->height as height',
'images.lat',
'images.lng',
'image_annotations.points',
'image_annotation_labels.id as annotation_label_id',
'labels.name as label_name',
])
->whereNotNull('images.lat')
->whereNotNull('images.lng')
->whereNotNull('images.attrs->width')
->whereNotNull('images.attrs->height')
->whereNotNull('images.attrs->metadata->distance_to_ground')
->whereNotNull('images.attrs->metadata->yaw');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ public function initQuery($columns = [])
->where('images.volume_id', $this->source->id)
->when($this->isRestrictedToExportArea(), [$this, 'restrictToExportAreaQuery'])
->when($this->isRestrictedToAnnotationSession(), [$this, 'restrictToAnnotationSessionQuery'])
->when($this->isRestrictedToNewestLabel(), function ($query) {
return $this->restrictToNewestLabelQuery($query, $this->source);
})
->when($this->isRestrictedToLabels(), function ($query) {
return $this->restrictToLabelsQuery($query, 'image_annotation_labels');
})
->when($this->isRestrictedToNewestLabel(), fn ($query) => $this->restrictToNewestLabelQuery($query, $this->source))
->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_annotation_labels'))
->select($columns);

if ($this->shouldSeparateLabelTrees()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function generateReport($path)
*/
protected function query()
{
$query = $this->initQuery([
$query = $this
->initQuery([
'image_annotations.id as annotation_id',
'shapes.id as shape_id',
'shapes.name as shape_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

use Biigle\LabelTree;
use Biigle\Services\Reports\CsvFile;
use Biigle\User;

use Biigle\Services\Reports\MakesZipArchives;
use Biigle\User;
use DB;

class CocoReportGenerator extends AnnotationReportGenerator
Expand Down Expand Up @@ -68,18 +67,19 @@ public function generateReport($path)
$this->tmpFiles[] = $csv;
$toZip[$csv->getPath()] = $this->sanitizeFilename("{$this->source->id}-{$this->source->name}", 'json');
}
$this->executeScript('to_coco',''); // the temporary csv files are overwritten with the respective json files therefore the argument is not needed
$this->executeScript('to_coco', ''); // the temporary csv files are overwritten with the respective json files therefore the argument is not needed
$this->makeZip($toZip, $path);
}

/**
/**
* Assemble a new DB query for the volume of this report.
*
* @return \Illuminate\Database\Query\Builder
*/
protected function query()
{
$query = $this->initQuery([
$query = $this
->initQuery([
'image_annotation_labels.id as annotation_label_id',
'image_annotation_labels.label_id',
'labels.name as label_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function generateReport($path)
*/
protected function query()
{
$query = $this->initQuery([
$query = $this
->initQuery([
'image_annotation_labels.id as annotation_label_id',
'image_annotation_labels.label_id',
'labels.name as label_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function generateReport($path)
*/
protected function query()
{
$query = $this->initQuery([
$query = $this
->initQuery([
'images.filename',
'image_annotations.id as annotation_id',
'image_annotation_labels.label_id',
Expand Down
Loading

0 comments on commit 022289d

Please sign in to comment.