From 1ce7672e9ee5605d989a2cdeba5f1b7f160521de Mon Sep 17 00:00:00 2001 From: k1o0 Date: Tue, 7 May 2024 18:16:25 +0300 Subject: [PATCH 1/4] Resolves #850 --- alyx/actions/notifications.py | 36 ++++++++++++++++++++++++++++++----- alyx/actions/tests.py | 10 +++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/alyx/actions/notifications.py b/alyx/actions/notifications.py index 22049846f..c0668ce39 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 c457874c4..c4d7ae7bb 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() From 4bd65b75485a704a8565b31309c20a84c8dc0a88 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 01:25:58 +0000 Subject: [PATCH 2/4] Bump urllib3 from 1.26.18 to 1.26.19 Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.18 to 1.26.19. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/1.26.19/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.26.18...1.26.19) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements_frozen.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_frozen.txt b/requirements_frozen.txt index b24ff85bf..8bd46f77b 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 From 2ae7b46688b0ea97e0baa11b4c30d5d25a2799c2 Mon Sep 17 00:00:00 2001 From: Miles Wells Date: Wed, 19 Jun 2024 12:49:11 +0300 Subject: [PATCH 3/4] add rawImagingData.times dataset type --- alyx/data/fixtures/data.datasettype.json | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/alyx/data/fixtures/data.datasettype.json b/alyx/data/fixtures/data.datasettype.json index f140166e3..85db392ea 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": "" } } ] From 9e52b0af019d363a165bcb69270b510dfa8c7a02 Mon Sep 17 00:00:00 2001 From: Miles Wells Date: Wed, 19 Jun 2024 12:51:41 +0300 Subject: [PATCH 4/4] bump version --- alyx/alyx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alyx/alyx/__init__.py b/alyx/alyx/__init__.py index 24525b577..22e5ee6c9 100644 --- a/alyx/alyx/__init__.py +++ b/alyx/alyx/__init__.py @@ -1 +1 @@ -VERSION = __version__ = '2.1.1' +VERSION = __version__ = '2.1.2'