diff --git a/alyx/actions/views.py b/alyx/actions/views.py index bec3461f6..2ecd72875 100644 --- a/alyx/actions/views.py +++ b/alyx/actions/views.py @@ -457,7 +457,10 @@ def get(self, request, format=None, nickname=None): end_date = request.query_params.get('end_date', None) subject = Subject.objects.get(nickname=nickname) records = subject.water_control.to_jsonable(start_date=start_date, end_date=end_date) - data = {'subject': nickname, 'implant_weight': subject.implant_weight, 'records': records} + data = {'subject': nickname, 'implant_weight': subject.implant_weight, + 'reference_weight_pct': subject.water_control.reference_weight_pct, + 'zscore_weight_pct': subject.water_control.zscore_weight_pct, + 'records': records} return Response(data) diff --git a/alyx/actions/water_control.py b/alyx/actions/water_control.py index b27cc2fd9..ef6ad6852 100644 --- a/alyx/actions/water_control.py +++ b/alyx/actions/water_control.py @@ -8,6 +8,7 @@ from operator import attrgetter, itemgetter import os.path as op +from django.conf import settings from django.urls import reverse from django.utils.html import format_html from django.http import HttpResponse @@ -563,7 +564,9 @@ def water_control(subject): implant_weight=subject.implant_weight ) wc.add_threshold(percentage=rw_pct + zw_pct, bgcolor=PALETTE['orange'], fgcolor='#FFC28E') - wc.add_threshold(percentage=.7, bgcolor=PALETTE['red'], fgcolor='#F08699', line_style='--') + if absolute_min := settings.WEIGHT_THRESHOLD: + wc.add_threshold( + percentage=absolute_min, bgcolor=PALETTE['red'], fgcolor='#F08699', line_style='--') # Water restrictions. wrs = sorted(list(subject.actions_waterrestrictions.all()), key=attrgetter('start_time')) # Reference weight. diff --git a/alyx/alyx/settings_lab_template.py b/alyx/alyx/settings_lab_template.py index 8d3bfc494..da96bc8d1 100644 --- a/alyx/alyx/settings_lab_template.py +++ b/alyx/alyx/settings_lab_template.py @@ -10,7 +10,7 @@ DEFAULT_PROTOCOL = '1' SUPERUSERS = ('root',) STOCK_MANAGERS = ('root',) -WEIGHT_THRESHOLD = 0.75 +WEIGHT_THRESHOLD = 0.8 # Absolute minimum weight threshold (red line in plots) DEFAULT_LAB_NAME = 'defaultlab' WATER_RESTRICTIONS_EDITABLE = False # if set to True, all users can edit water restrictions DEFAULT_LAB_PK = '4027da48-7be3-43ec-a222-f75dffe36872' diff --git a/alyx/subjects/serializers.py b/alyx/subjects/serializers.py index b6a2877d9..e9f954bfa 100644 --- a/alyx/subjects/serializers.py +++ b/alyx/subjects/serializers.py @@ -28,10 +28,18 @@ def get_reference_weight(self, obj): def get_last_water_restriction(self, obj): return obj.water_control.water_restriction_at() + def get_reference_weight_pct(self, obj): + return obj.water_control.reference_weight_pct + + def get_zscore_weight_pct(self, obj): + return obj.water_control.zscore_weight_pct + expected_water = serializers.SerializerMethodField() remaining_water = serializers.SerializerMethodField() reference_weight = serializers.SerializerMethodField() last_water_restriction = serializers.SerializerMethodField() + reference_weight_pct = serializers.SerializerMethodField() + zscore_weight_pct = serializers.SerializerMethodField() class WaterRestrictedSubjectListSerializer(_WaterRestrictionBaseSerializer): @@ -42,6 +50,8 @@ class Meta: 'remaining_water', 'reference_weight', 'last_water_restriction', + 'reference_weight_pct', + 'zscore_weight_pct' ) lookup_field = 'nickname' diff --git a/scripts/sync_ucl/prune_cortexlab.py b/scripts/sync_ucl/prune_cortexlab.py index 1e04db2eb..3f24ee2e4 100755 --- a/scripts/sync_ucl/prune_cortexlab.py +++ b/scripts/sync_ucl/prune_cortexlab.py @@ -45,8 +45,7 @@ # the sessions should also have the cortexlab lab field properly labeled before import if Lab.objects.using('cortexlab').filter(name='cortexlab').count() == 0: - lab_dict = {'pk': CORTEX_LAB_PK, - 'name': 'cortexlab'} + lab_dict = {'pk': CORTEX_LAB_PK, 'name': 'cortexlab'} lab = Lab.objects.using('cortexlab').create(**lab_dict) lab.save() else: