Skip to content

Commit

Permalink
Sort gate slots in get_free_slots method to better handle also pauses
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Oct 11, 2023
1 parent ac71dd0 commit 7b7b2fd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
2.1.1 (unreleased)
------------------

- Nothing changed yet.
- Sort gate slots in get_free_slots method to better handle also pauses.
[cekk]


2.1.0 (2023-10-11)
Expand Down
1 change: 0 additions & 1 deletion src/redturtle/prenotazioni/adapters/slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def __sub__(self, value):
"""Subtract something from this"""
if isinstance(value, Interval):
value = [value]

# We filter not overlapping intervals
good_intervals = [x for x in value if x.overlaps(self)]
points = slots_to_points(good_intervals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def get_free_slots(self, booking_date, period="day"):
gate_slots.append(slot)
for interval in intervals:
if interval:
availability[gate].extend(interval - gate_slots)
availability[gate].extend(interval - sorted(gate_slots))
return availability

def get_freebusy_slots(self, booking_date, period="day"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,64 @@ def test_get_free_slots_skip_bookigs_inside_pause_range(self):
self.assertEqual(view.get_free_slots(today)["Gate A"][0].stop(), "08:00")
self.assertEqual(view.get_free_slots(today)["Gate A"][1].start(), "11:00")
self.assertEqual(view.get_free_slots(today)["Gate A"][1].stop(), "13:00")

def test_get_free_slots_handle_pauses_correctly(self):
booker = IBooker(self.folder_prenotazioni)

today = date.today()
# need this just to have the day container
aq_parent(
booker.create(
{
"booking_date": datetime(
today.year, today.month, today.day, 10, 30
),
"booking_type": "Type A",
"title": "foo",
}
)
)
for hour in [7, 8, 9, 11, 12]:
aq_parent(
booker.create(
{
"booking_date": datetime(
today.year, today.month, today.day, hour, 00
),
"booking_type": "Type A",
"title": "foo",
}
)
)

aq_parent(
booker.create(
{
"booking_date": datetime(
today.year, today.month, today.day, hour, 30
),
"booking_type": "Type A",
"title": "foo",
}
)
)

self.folder_prenotazioni.pause_table = [
{"day": "0", "pause_end": "1030", "pause_start": "1000"},
{"day": "1", "pause_end": "1030", "pause_start": "1000"},
{"day": "2", "pause_end": "1030", "pause_start": "1000"},
{"day": "3", "pause_end": "1030", "pause_start": "1000"},
{"day": "4", "pause_end": "1030", "pause_start": "1000"},
{"day": "5", "pause_end": "1030", "pause_start": "1000"},
{"day": "6", "pause_end": "1030", "pause_start": "1000"},
{"day": "7", "pause_end": "1030", "pause_start": "1000"},
]

view = api.content.get_view(
context=self.folder_prenotazioni,
request=self.request,
name="prenotazioni_context_state",
)
res = view.get_free_slots(today)
# there are no free slots because are all taken by bookings or pause
self.assertEqual(len(res["Gate A"]), 0)

0 comments on commit 7b7b2fd

Please sign in to comment.