Skip to content

Commit

Permalink
Refactor code to remove all uses of indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
vcai122 committed Nov 7, 2024
1 parent 85e98f0 commit d4cc7af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
16 changes: 4 additions & 12 deletions backend/dining/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,15 @@ def get_venues(self):
[value.pop(item) for item in remove_items]
for day in value["days"]:
day.pop("message")
removed_dayparts = set()
for i in range(len(day["dayparts"])):
daypart = day["dayparts"][i]
day["dayparts"] = [
daypart for daypart in day["dayparts"] if not daypart["starttime"]
]
for daypart in day["dayparts"]:
[daypart.pop(item) for item in ["id", "hide"]]
if not daypart["starttime"]:
removed_dayparts.add(i)
continue
for time in ["starttime", "endtime"]:
daypart[time] = datetime.datetime.strptime(
day["date"] + "T" + daypart[time], "%Y-%m-%dT%H:%M"
)
# Remove empty dayparts (unavailable meal times)
day["dayparts"] = [
day["dayparts"][i]
for i in range(len(day["dayparts"]))
if i not in removed_dayparts
]
results.append(value)
return results

Expand Down
3 changes: 1 addition & 2 deletions backend/penndata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ def get_usage_on_date(self, room, date, field):
# Set value to None if the last retrieved data was
# over 2 hours old to avoid extrapolation
if hour_date - datetime.timedelta(hours=1) > before_date:
for i in range(hour, 24):
usage[i] = None
usage[hour:24] = [None] * (24 - hour)
break
else:
after_date, after_val = timezone.localtime(), before_val
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/gsr_booking/test_gsr_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def test_group_book_wharton(self):
bookings = list(reservation.gsrbooking_set.all())
bookings.sort(key=lambda x: x.start)
# check bookings cover entire range and enough time
for i in range(len(bookings) - 1):
self.assertEqual(bookings[i].end, bookings[i + 1].start)
for booking, next_booking in zip(bookings, bookings[1:]):
self.assertEqual(booking.end, next_booking.start)
total_time = sum([booking.end - booking.start for booking in bookings], timedelta())
self.assertEqual(total_time, timedelta(hours=2))

Expand Down Expand Up @@ -200,8 +200,8 @@ def test_group_book_libcal(self):
bookings = list(reservation.gsrbooking_set.all())
bookings.sort(key=lambda x: x.start)
# check bookings cover entire range and enough time
for i in range(len(bookings) - 1):
self.assertEqual(bookings[i].end, bookings[i + 1].start)
for booking, next_booking in zip(bookings, bookings[1:]):
self.assertEqual(booking.end, next_booking.start)
total_time = sum([booking.end - booking.start for booking in bookings], timedelta())
self.assertEqual(total_time, timedelta(hours=2))
# check reservation exists
Expand Down

0 comments on commit d4cc7af

Please sign in to comment.