diff --git a/alyx/actions/notifications.py b/alyx/actions/notifications.py index 22049846..c0668ce3 100644 --- a/alyx/actions/notifications.py +++ b/alyx/actions/notifications.py @@ -37,11 +37,20 @@ def check_weighed(subject, date=None): # Reinit the water_control instance to make sure the just-added # weighing is taken into account wc = subject.reinit_water_control() - if not wc: + if not wc or not wc.is_water_restricted(date): return + + assert hasattr(date, 'date') + ref_weight = wc.reference_weight(date) + is_restriction_day = wc.water_restriction_at(date).date() == date.date() + # Don't notifiy if a reference weight was entered and subject + # was put on water restriction on the same day + if is_restriction_day and ref_weight: + return + lwb = wc.last_weighing_before(date=date) - if hasattr(date, 'date'): - date = date.date() + date = date.date() + datetime = lwb[0] if lwb else None if not datetime or datetime.date() != date: header = 'ATTENTION' @@ -50,13 +59,30 @@ def check_weighed(subject, date=None): def check_water_administration(subject, date=None): + """ + Check the subject was administered water in the last 24 hours. + + Creates a notification if the subject was not given required water + today. + + Parameters + ---------- + subject : subject.models.Subject + A subject instance. + date : datetime.datetime + The datetime to check, deafults to now. + """ date = date or timezone.now() wc = subject.reinit_water_control() + if not wc or not wc.is_water_restricted(date): + return remaining = wc.remaining_water(date=date) wa = wc.last_water_administration_at(date=date) - if not wa: + # If the subject is not on water restriction, or the restriction + # was created on the same day, water administration is not required + if wc.water_restriction_at(date).date() == date.date(): return - delay = date - wa[0] + delay = date - (wa[0] if wa else wc.current_water_restriction()) # Notification if water needs to be given more than 23h after the last # water administration. if remaining > 0 and delay.total_seconds() >= 23 * 3600 - 10: diff --git a/alyx/actions/tests.py b/alyx/actions/tests.py index c457874c..c4d7ae7b 100644 --- a/alyx/actions/tests.py +++ b/alyx/actions/tests.py @@ -170,7 +170,7 @@ def test_notif_water_1(self): date = timezone.datetime(2018, 6, 3, 16, 0, 0) check_water_administration(self.subject, date=date) notif = Notification.objects.last() - self.assertTrue(notif is None) + self.assertIsNone(notif) def test_notif_water_2(self): # If the last water admin was on June 3 at 12pm, the notification @@ -182,6 +182,14 @@ def test_notif_water_2(self): notif = Notification.objects.last() self.assertTrue((notif is not None) is r) + def test_notif_water_3(self): + # If the subject was place on water restriction on the same day + # there should be no notification + date = timezone.datetime(2018, 6, 2, 22, 30, 0) + check_water_administration(self.subject, date=date) + notif = Notification.objects.last() + self.assertIsNone(notif) + def test_notif_user_change_1(self): self.subject.responsible_user = self.user2 self.subject.save() diff --git a/alyx/alyx/__init__.py b/alyx/alyx/__init__.py index 24525b57..22e5ee6c 100644 --- a/alyx/alyx/__init__.py +++ b/alyx/alyx/__init__.py @@ -1 +1 @@ -VERSION = __version__ = '2.1.1' +VERSION = __version__ = '2.1.2' diff --git a/alyx/data/fixtures/data.datasettype.json b/alyx/data/fixtures/data.datasettype.json index f140166e..85db392e 100644 --- a/alyx/data/fixtures/data.datasettype.json +++ b/alyx/data/fixtures/data.datasettype.json @@ -2294,8 +2294,19 @@ "json": null, "name": "passingSpikes.table", "created_by": null, - "description": "A compressed table containing only the spikes belonging to passing units, to accelarate data loading", - "filename_pattern": "*passingspikes.table*" + "description": "A compressed table containing only the spikes belonging to passing units, to accelerate data loading.", + "filename_pattern": "" + } + }, + { + "model": "data.datasettype", + "pk": "5137d09a-41b6-435f-aba5-c4a7e2b0d240", + "fields": { + "json": null, + "name": "rawImagingData.times", + "created_by": null, + "description": "The raw frame exposure times.", + "filename_pattern": "" } } ] diff --git a/requirements_frozen.txt b/requirements_frozen.txt index b24ff85b..8bd46f77 100644 --- a/requirements_frozen.txt +++ b/requirements_frozen.txt @@ -78,6 +78,6 @@ tqdm==4.66.4 typing_extensions==4.12.2 tzdata==2024.1 uritemplate==4.1.1 -urllib3==1.26.18 +urllib3==1.26.19 webdavclient3==3.14.6 zipp==3.19.2