Add Duck.dpx() method

This commit is contained in:
Gergely Polonkai 2014-12-23 09:26:03 +01:00 committed by Gergely Polonkai
parent e12019723d
commit 56d19e07d9
2 changed files with 13 additions and 0 deletions

View File

@ -62,6 +62,15 @@ class Duck(models.Model):
return seconds
def dpx(self):
all_time = Booking.total_booking_time()
duck_time = Booking.duck_booking_time(self)
if (all_time == None) or (duck_time == None):
return 0
return Booking.duck_booking_time(self) / Booking.total_booking_time()
class DuckName(models.Model):
"""Model to hold name suggestions for Ducks"""

View File

@ -188,3 +188,7 @@ class BookingTimeTest(TestCase):
def test_duck_booking_time(self):
self.assertEqual(Booking.duck_booking_time(self.duck1), 86400)
self.assertEqual(Booking.duck_booking_time(self.duck2), 172800)
def test_dpx(self):
self.assertEqual(self.duck1.dpx(), 1/3)
self.assertEqual(self.duck2.dpx(), 2/3)