Skip to content

Commit

Permalink
Drop computable Rankings.percentage and provide func
Browse files Browse the repository at this point in the history
At model instance .save() time, we were calculating the value of one column
using two others.

Since the type of that column is an IntegerField but elsewhere on the site we
round to one digit after decimal, a reader complained about the inconsistency
(really that it was a floor() operation).

Instead, this is the first part of the whole fix, but someone else can
"makemigrations" to discard the db column at leisure.

Closes ebmdatalab#184
  • Loading branch information
chadmiller committed Mar 27, 2019
1 parent 5540bfa commit 782ff5f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions clinicaltrials/frontend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ class Ranking(models.Model):
reported = models.IntegerField()
reported_late = models.IntegerField()
reported_on_time = models.IntegerField()
percentage = models.IntegerField(null=True)

@property
def percentage(self):
if not self.due:
return None
return round(100.0*self.reported/self.due, 1)

def __str__(self):
return "{}: {} at {}% on {}".format(self.rank, self.sponsor, self.percentage, self.date)

def save(self, *args, **kwargs):
if self.due:
self.percentage = float(self.reported)/self.due * 100
super(Ranking, self).save(*args, **kwargs)

class Meta:
unique_together = ('sponsor', 'date',)
ordering = ('date', 'rank', 'sponsor__name',)

0 comments on commit 782ff5f

Please sign in to comment.