Skip to content

Commit

Permalink
Include reference_weight_pct and zscore_weight_pct in water restricti…
Browse files Browse the repository at this point in the history
…on serializers
  • Loading branch information
k1o0 authored and k1o0 committed Apr 15, 2024
1 parent a5cf217 commit 3fe2d90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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
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

0 comments on commit 3fe2d90

Please sign in to comment.