From 1991b7481927681aa009b6724b897be66a0a991f Mon Sep 17 00:00:00 2001 From: Luca Lianas Date: Fri, 6 Oct 2023 17:17:34 +0200 Subject: [PATCH] fix: truncate all measurements to second decimal digit when exporting CSV files --- .../management/commands/get_cores_data.py | 6 ++--- .../commands/get_focus_regions_data.py | 4 ++-- promort/rois_manager/models.py | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/promort/rois_manager/management/commands/get_cores_data.py b/promort/rois_manager/management/commands/get_cores_data.py index b01835a..e76d241 100644 --- a/promort/rois_manager/management/commands/get_cores_data.py +++ b/promort/rois_manager/management/commands/get_cores_data.py @@ -76,9 +76,9 @@ def _dump_row(self, core, csv_writer): 'action_complete_time': action_complete_time, 'creation_date': core.creation_date.strftime('%Y-%m-%d %H:%M:%S'), 'reviewer': core.author.username, - 'length': core.length, - 'area': core.area, - 'tumor_length': core.tumor_length, + 'length': core.get_length(), + 'area': core.get_area(), + 'tumor_length': core.get_tumor_length(), 'positive_core': core.is_positive(), 'normal_tissue_percentage': core.get_normal_tissue_percentage(), 'total_tumor_area': core.get_total_tumor_area() diff --git a/promort/rois_manager/management/commands/get_focus_regions_data.py b/promort/rois_manager/management/commands/get_focus_regions_data.py index 1104598..900fe6d 100644 --- a/promort/rois_manager/management/commands/get_focus_regions_data.py +++ b/promort/rois_manager/management/commands/get_focus_regions_data.py @@ -77,8 +77,8 @@ def _dump_row(self, focus_region, csv_writer): 'action_complete_time': action_complete_time, 'creation_date': focus_region.creation_date.strftime('%Y-%m-%d %H:%M:%S'), 'reviewer': focus_region.author.username, - 'length': focus_region.length, - 'area': focus_region.area, + 'length': focus_region.get_length(), + 'area': focus_region.get_area(), 'tissue_status': self._get_region_tissue_status(focus_region), 'core_coverage_percentage': focus_region.get_core_coverage_percentage() } diff --git a/promort/rois_manager/models.py b/promort/rois_manager/models.py index f68d42a..b916b02 100644 --- a/promort/rois_manager/models.py +++ b/promort/rois_manager/models.py @@ -84,12 +84,24 @@ def get_total_tumor_area(self): total_cancerous_area = 0.0 for focus_region in self.focus_regions.all(): if focus_region.is_cancerous_region(): - total_cancerous_area += focus_region.area + total_cancerous_area += focus_region.get_area() return total_cancerous_area + def get_length(self): + return round(self.length, 2) + + def get_area(self): + return round(self.area, 2) + + def get_tumor_length(self): + if not self.tumor_length is None: + return round(self.tumor_length, 2) + else: + return None + def get_normal_tissue_percentage(self): total_cancerous_area = self.get_total_tumor_area() - return ((self.area - total_cancerous_area) / self.area) * 100.0 + return ((self.get_area() - total_cancerous_area) / self.get_area()) * 100.0 def is_positive(self): for fr in self.focus_regions.all(): @@ -129,8 +141,14 @@ class FocusRegion(models.Model): class Meta: unique_together = ('label', 'core') + def get_length(self): + return round(self.length, 2) + + def get_area(self): + return round(self.area, 2) + def get_core_coverage_percentage(self): - return (self.area / self.core.area) * 100.0 + return (self.get_area() / self.core.get_area()) * 100.0 def is_cancerous_region(self): return self.tissue_status == 'TUMOR'