Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.1.2 #864

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions alyx/actions/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion alyx/actions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion alyx/alyx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = __version__ = '2.1.1'
VERSION = __version__ = '2.1.2'
15 changes: 13 additions & 2 deletions alyx/data/fixtures/data.datasettype.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
]
2 changes: 1 addition & 1 deletion requirements_frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading