diff --git a/alyx/actions/tests.py b/alyx/actions/tests.py index 989a2743..92b5711b 100644 --- a/alyx/actions/tests.py +++ b/alyx/actions/tests.py @@ -80,8 +80,10 @@ def test_water_control_thresholds(self): self.sub.save() wc = self.sub.reinit_water_control() wc.expected_weight() - self.assertAlmostEqual(self.wei[self.rwind], wc.reference_weight()) - self.assertAlmostEqual(self.wei[self.rwind], wc.expected_weight()) + # expected weight should be different to reference weight as the implant weight changes + expected = self.wei[self.rwind] + (wc.implant_weights[1][1] - wc.implant_weights[0][1]) + self.assertAlmostEqual(expected, wc.reference_weight()) + self.assertAlmostEqual(expected, wc.expected_weight()) # test implant weight values self.assertEqual([4.56, 7.0], [x[1] for x in wc.implant_weights]) self.assertEqual(7.0, wc.implant_weight()) @@ -91,23 +93,23 @@ def test_water_control_thresholds(self): self.sub.lab = Lab.objects.get(name='zscore') self.sub.save() wc = self.sub.reinit_water_control() - wc.expected_weight() - self.assertAlmostEqual(self.wei[self.rwind], wc.reference_weight()) zscore = wc.zscore_weight() + self.assertAlmostEqual(zscore, 38.049183673469386) + self.assertEqual(zscore, wc.expected_weight()) # test computation on mixed lab self.sub.lab = Lab.objects.get(name='mixed') self.sub.save() wc = self.sub.reinit_water_control() - self.assertAlmostEqual(self.wei[self.rwind], wc.reference_weight()) + self.assertAlmostEqual(expected, wc.reference_weight()) self.assertAlmostEqual(wc.expected_weight(), (wc.reference_weight() + zscore) / 2) # test that the thresholds are all above 70% - self.assertTrue(all([thrsh[0] > 0.4 for thrsh in wc.thresholds])) + self.assertTrue(all(thrsh[0] > 0.4 for thrsh in wc.thresholds)) # if we change the reference weight of the water restriction, this should change in wc too - self.assertAlmostEqual(wc.reference_weight(), self.wr.reference_weight) + self.assertAlmostEqual(expected, wc.reference_weight()) self.wr.reference_weight = self.wr.reference_weight + 1 self.wr.save() wc = self.sub.reinit_water_control() - self.assertAlmostEqual(wc.reference_weight(), self.wr.reference_weight) + self.assertAlmostEqual(expected + 1, wc.reference_weight()) class NotificationTests(TestCase): diff --git a/alyx/actions/water_control.py b/alyx/actions/water_control.py index cffe70e7..326412da 100644 --- a/alyx/actions/water_control.py +++ b/alyx/actions/water_control.py @@ -253,7 +253,10 @@ def reference_implant_weight_at(self, date=None, return_date=False): return self.last_implant_weight_before(wr or date, return_date) def reference_weighing_at(self, date=None): - """Return a tuple (date, weight) the reference weighing at the specified date, or today.""" + """Return a tuple (date, weight) the reference weighing at the specified date, or today. + + NB: this does not account for changes in implant weight. + """ if self.reference_weighing and (date is None or date >= self.reference_weighing[0]): return self.reference_weighing date = date or self.today() @@ -271,10 +274,16 @@ def reference_weighing_at(self, date=None): return ref_weight def reference_weight(self, date=None): - """Return the reference weight at a given date.""" + """Return the reference weight at a given date. + + NB: Unlike `reference_weighing_at` this accounts for changes in implant + weight. + """ rw = self.reference_weighing_at(date=date) if rw: - return rw[1] + ref_iw = self.reference_implant_weight_at(date) or 0. + iw = self.last_implant_weight_before(date) or 0. + return (rw[1] - ref_iw) + iw return 0. def last_implant_weight_before(self, date=None, return_date=False): @@ -414,7 +423,10 @@ def expected_water(self, date=None): weight = self.last_weighing_before(date=date) weight = weight[1] if weight else 0. expected_weight = self.expected_weight(date=date) or 0. - return 0.05 * (weight - iw) if weight < 0.8 * expected_weight else 0.04 * (weight - iw) + pct_sum = (self.reference_weight_pct + self.zscore_weight_pct) + # Increase required water by 0.01mL/g if weight below pct reference + pct_weight = (pct_sum * expected_weight) + return 0.05 * (weight - iw) if weight < pct_weight else 0.04 * (weight - iw) def given_water(self, date=None, has_session=None): """Return the amount of water given at a specified date.""" diff --git a/alyx/alyx/settings_lab_template.py b/alyx/alyx/settings_lab_template.py index 29c2e836..9c10fabb 100644 --- a/alyx/alyx/settings_lab_template.py +++ b/alyx/alyx/settings_lab_template.py @@ -3,7 +3,7 @@ # ALYX-SPECIFIC ALLOWED_HOSTS = ['localhost', '127.0.0.1'] LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'Europe/London' +TIME_ZONE = 'Europe/London' # NB: Changing the timezone here requires migrations GLOBUS_CLIENT_ID = '525cc543-8ccb-4d11-8036-af332da5eafd' SUBJECT_REQUEST_EMAIL_FROM = 'alyx@internationalbrainlab.org' DEFAULT_SOURCE = 'IBL'