From 56d19e07d9cb34a8766d1ee9405abdf2957acdd2 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 23 Dec 2014 09:26:03 +0100 Subject: [PATCH] Add Duck.dpx() method --- booking/models.py | 9 +++++++++ booking/tests.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/booking/models.py b/booking/models.py index 4f6aa6d..f03e5e7 100644 --- a/booking/models.py +++ b/booking/models.py @@ -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""" diff --git a/booking/tests.py b/booking/tests.py index 968c351..828a226 100644 --- a/booking/tests.py +++ b/booking/tests.py @@ -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)