mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Set group radius to a fixed 30m
This commit is contained in:
parent
ddf91f2e3b
commit
a246a5f24c
2 changed files with 1 additions and 35 deletions
|
@ -71,9 +71,7 @@ class StudyGroupDistanceSerializer(serializers.ModelSerializer):
|
|||
read_only_fields = ['landmark', 'radius', 'students', 'distance']
|
||||
|
||||
def get_distance(self, obj):
|
||||
if hasattr(obj, 'distance'):
|
||||
return obj.distance.km
|
||||
return 0
|
||||
return 30
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
|
|
@ -88,22 +88,6 @@ class StudyGroupListView(generics.ListAPIView):
|
|||
# Now fetch the StudyGroups with the matching Subject models
|
||||
studygroups = StudyGroup.objects.filter(subject__in=user_subjects)
|
||||
|
||||
for group in studygroups:
|
||||
# Get the number of students in a group
|
||||
student_count = group.students.values_list(
|
||||
'user', flat=True).count()
|
||||
# Each student will contribute 10 to the radius
|
||||
radius = student_count * 10
|
||||
|
||||
# If the radius exceeds 50, set it back to 50
|
||||
if (radius > 50):
|
||||
radius = 50
|
||||
# (For debug purposes) If radius is less than 5, set it back to 5
|
||||
elif (radius < 5):
|
||||
radius = 5
|
||||
# Annotate the group with the radius
|
||||
group.radius = radius
|
||||
|
||||
return studygroups
|
||||
|
||||
|
||||
|
@ -135,22 +119,6 @@ class StudyGroupListNearView(generics.ListAPIView):
|
|||
# Now fetch the StudyGroups with the matching Subject models that are within 100m
|
||||
studygroups = StudyGroup.objects.filter(subject__in=user_subjects).annotate(
|
||||
distance=Distance('location', user_location)).filter(distance__lte=100)
|
||||
|
||||
for group in studygroups:
|
||||
# Get the number of students in a group
|
||||
student_count = group.students.values_list(
|
||||
'user', flat=True).count()
|
||||
# Each student will contribute 10 to the radius
|
||||
radius = student_count * 10
|
||||
|
||||
# If the radius exceeds 50, set it back to 50
|
||||
if (radius > 50):
|
||||
radius = 50
|
||||
# (For debug purposes) If radius is less than 5, set it back to 5
|
||||
elif (radius < 5):
|
||||
radius = 5
|
||||
# Annotate the group with the radius
|
||||
group.radius = radius
|
||||
return studygroups
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue