Skip to content

Commit

Permalink
Dev (#848)
Browse files Browse the repository at this point in the history
* Permit later versions of ONE in requirements
* remove to internal method in serialiser
* Include reference_weight_pct and zscore_weight_pct in water restriction serializers
* Min weight plot threshold a constant in lab settings
* Don't commit all changed files in Gihub actions!
---------
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Mayo Faulkner <[email protected]>
Co-authored-by: k1o0 <[email protected]>
  • Loading branch information
k1o0 authored and k1o0 committed Apr 15, 2024
1 parent 0a6fbd8 commit f0d8f47
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ jobs:
run: |
git config user.name github-actions
git config user.email [email protected]
git commit -m "GitHub Actions generated requirements_frozen.txt" -a
git add requirements_frozen.txt
git commit -m "GitHub Actions generated requirements_frozen.txt"
git push
# Docker steps only run when master branch pushed to directly OR when a PR is merged
Expand Down
5 changes: 4 additions & 1 deletion alyx/actions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
5 changes: 4 additions & 1 deletion alyx/actions/water_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
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.0.0'
VERSION = __version__ = '2.1.0'
2 changes: 1 addition & 1 deletion alyx/alyx/settings_lab_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 0 additions & 9 deletions alyx/experiments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ class TrajectoryEstimateSerializer(serializers.ModelSerializer):
queryset=CoordinateSystem.objects.all(),
)

def to_internal_value(self, data):
if data.get('chronic_insertion', None) is None:
data['chronic_insertion'] = None

if data.get('probe_insertion', None) is None:
data['probe_insertion'] = None

return super(TrajectoryEstimateSerializer, self).to_internal_value(data)

class Meta:
model = TrajectoryEstimate
fields = '__all__'
Expand Down
3 changes: 3 additions & 0 deletions alyx/experiments/tests_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def test_create_list_delete_trajectory(self):
# create a trajectory
url = reverse('trajectoryestimate-list')
tdict = {'probe_insertion': alyx_insertion['id'],
'chronic_insertion': None,
'x': -4521.2,
'y': 2415.0,
'z': 0,
Expand Down Expand Up @@ -216,6 +217,7 @@ def test_create_list_delete_channels(self):
# create the probe insertion
pi = self.ar(self.post(reverse('probeinsertion-list'), self.dict_insertion), 201)
tdict = {'probe_insertion': pi['id'],
'chronic_insertion': None,
'x': -4521.2,
'y': 2415.0,
'z': 0,
Expand Down Expand Up @@ -273,6 +275,7 @@ def test_chronic_insertion(self):

# create a trajectory and attach it to the chronic insertion
traj_dict = {'chronic_insertion': ci['id'],
'probe_insertion': None,
'x': -4521.2,
'y': 2415.0,
'z': 0,
Expand Down
10 changes: 10 additions & 0 deletions alyx/subjects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -42,6 +50,8 @@ class Meta:
'remaining_water',
'reference_weight',
'last_water_restriction',
'reference_weight_pct',
'zscore_weight_pct'
)

lookup_field = 'nickname'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ python-magic
pytz
structlog>=21.5.0
webdavclient3
ONE-api~=2.7rc0
ONE-api>=2.7
3 changes: 1 addition & 2 deletions scripts/sync_ucl/prune_cortexlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f0d8f47

Please sign in to comment.