Skip to content

Commit

Permalink
fix: truncate all measurements to second decimal digit when exporting…
Browse files Browse the repository at this point in the history
… CSV files
  • Loading branch information
lucalianas committed Oct 6, 2023
1 parent a4c4a53 commit 1991b74
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions promort/rois_manager/management/commands/get_cores_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
24 changes: 21 additions & 3 deletions promort/rois_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 1991b74

Please sign in to comment.