Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
tuneerroy committed Nov 7, 2023
1 parent b8031ae commit f391877
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions backend/laundry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class Ids(APIView):
"""

def get(self, request):
return Response(
LaundryRoomSerializer(LaundryRoom.objects.all(), many=True).data
)
return Response(LaundryRoomSerializer(LaundryRoom.objects.all(), many=True).data)


class HallInfo(APIView):
Expand All @@ -34,13 +32,9 @@ class HallInfo(APIView):

def get(self, request, hall_id):
try:
return Response(
hall_status(get_object_or_404(LaundryRoom, hall_id=hall_id))
)
return Response(hall_status(get_object_or_404(LaundryRoom, hall_id=hall_id)))
except HTTPError:
return Response(
{"error": "The laundry api is currently unavailable."}, status=503
)
return Response({"error": "The laundry api is currently unavailable."}, status=503)


class MultipleHallInfo(APIView):
Expand Down Expand Up @@ -73,17 +67,13 @@ def get_snapshot_info(hall_id):
now = timezone.localtime()

# start is beginning of day, end is 27 hours after start
start = make_aware(
datetime.datetime(year=now.year, month=now.month, day=now.day)
)
start = make_aware(datetime.datetime(year=now.year, month=now.month, day=now.day))
end = start + datetime.timedelta(hours=27)

# filters for LaundrySnapshots within timeframe
room = get_object_or_404(LaundryRoom, hall_id=hall_id)

snapshots = LaundrySnapshot.objects.filter(
room=room, date__gt=start, date__lte=end
)
snapshots = LaundrySnapshot.objects.filter(room=room, date__gt=start, date__lte=end)

# adds all the LaundrySnapshots from the same weekday within the previous 28 days
for week in range(1, 4):
Expand Down Expand Up @@ -142,12 +132,8 @@ def compute_usage(hall_id):
"day_of_week": calendar.day_name[timezone.localtime().weekday()],
"start_date": min_date.date(),
"end_date": max_date.date(),
"washer_data": {
x: HallUsage.safe_division(data[x][0], data[x][2]) for x in range(27)
},
"dryer_data": {
x: HallUsage.safe_division(data[x][1], data[x][2]) for x in range(27)
},
"washer_data": {x: HallUsage.safe_division(data[x][0], data[x][2]) for x in range(27)},
"dryer_data": {x: HallUsage.safe_division(data[x][1], data[x][2]) for x in range(27)},
"total_number_of_washers": room.total_washers,
"total_number_of_dryers": room.total_dryers,
}
Expand Down Expand Up @@ -184,9 +170,7 @@ def post(self, request):
profile = request.user.profile
preferences = profile.laundry_preferences
if "rooms" not in request.data:
return Response(
{"success": False, "error": "No rooms provided"}, status=400
)
return Response({"success": False, "error": "No rooms provided"}, status=400)

halls = [
get_object_or_404(LaundryRoom, hall_id=int(hall_id))
Expand Down

0 comments on commit f391877

Please sign in to comment.