From 82f654b42ea2e09e0b0b63401251dd9a7bac3458 Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Thu, 30 Jan 2025 12:37:16 +0100 Subject: [PATCH] Fix issue with report CSV line count There was a regression where putCsv() was replaced by put() but the latter did not add a line break. This got noticed when an abundance report was requested for a volume with a single image. Since the volume title was not separated by the column titles with a newline, the CSV ended up with only two rows. The Python script assumed it to be empty. See: https://github.com/biigle/core/commit/9f2f3957d302ccd4bc0e10bbf79b8ea26e4011e7 --- app/Services/Reports/File.php | 2 +- .../AnnotationLocationReportGenerator.php | 2 +- .../ImageLocationReportGenerator.php | 2 +- .../ImageLabels/ImageLocationReportGenerator.php | 2 +- .../AnnotationLocationReportGeneratorTest.php | 16 ++++++++-------- .../ImageLocationReportGeneratorTest.php | 10 +++++----- .../ImageLocationReportGeneratorTest.php | 10 +++++----- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/Services/Reports/File.php b/app/Services/Reports/File.php index c02ca398a..8d4a673f4 100644 --- a/app/Services/Reports/File.php +++ b/app/Services/Reports/File.php @@ -94,7 +94,7 @@ public function getPath() public function put($content) { if (is_string($content)) { - return fwrite($this->handle, $content); + return fwrite($this->handle, $content."\n"); } } } diff --git a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php index 861e23f6a..375b0401c 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php @@ -143,7 +143,7 @@ protected function createNdJSON($items) $geometry = $this->estimateAnnotationPosition($item); $feature = new Feature($geometry, $properties); - $file->put(json_encode($feature)."\n"); + $file->put(json_encode($feature)); }); $file->close(); diff --git a/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php index fd7908ba5..65bfb308a 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php @@ -138,7 +138,7 @@ protected function createNdJSON($query, $usedLabels, $labels) } $feature = new Feature(new Point([$image->lng, $image->lat]), $properties); - $file->put(json_encode($feature)."\n"); + $file->put(json_encode($feature)); }); $file->close(); diff --git a/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php index d12069d61..75692b9f2 100644 --- a/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php @@ -151,7 +151,7 @@ protected function createNdJSON($query, $usedImageLabels, $imageLabels) } $feature = new Feature(new Point([$image->lng, $image->lat]), $properties); - $file->put(json_encode($feature)."\n"); + $file->put(json_encode($feature)); }); $file->close(); diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php index 7d0a4414d..e9b7ce4d9 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php @@ -89,7 +89,7 @@ public function testGenerateReport() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -175,7 +175,7 @@ public function testGenerateReportCircle() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -263,7 +263,7 @@ public function testGenerateReportLineString() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -353,7 +353,7 @@ public function testGenerateReportPolygon() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -473,7 +473,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent['properties']['_id'] = $al2->id; $jsonContent['properties']['_label_name'] = $label2->name; @@ -481,7 +481,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice(); @@ -577,7 +577,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent['properties']['_id'] = $al2->id; $jsonContent['properties']['_label_name'] = $al2->label->name; @@ -585,7 +585,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice(); diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php index cde1f5b7d..f9e507a90 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php @@ -73,7 +73,7 @@ public function testGenerateReport() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -180,7 +180,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent = [ 'type' => 'Feature', @@ -197,7 +197,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice(); @@ -280,7 +280,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent = [ 'type' => 'Feature', @@ -298,7 +298,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice(); diff --git a/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php index c28a1e204..4d7b7a0c0 100644 --- a/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php @@ -66,7 +66,7 @@ public function testGenerateReport() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->once(); @@ -171,7 +171,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent = [ 'type' => 'Feature', @@ -188,7 +188,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice(); @@ -267,7 +267,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $jsonContent = [ 'type' => 'Feature', @@ -285,7 +285,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('put') ->once() - ->with(json_encode($jsonContent)."\n"); + ->with(json_encode($jsonContent)); $mock->shouldReceive('close') ->twice();