Skip to content

Commit fc6f5f4

Browse files
committed
improve signature of is_busy
1 parent cf169b5 commit fc6f5f4

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/pycamp_bot/commands/wizard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def define_wizards_schedule(pycamp):
8383
for slot in slots_list:
8484
wizard = wizards_list[idx%n_wizards]
8585
n_iter = 0 # railguard
86-
while wizard.is_busy(slot):
86+
while wizard.is_busy(*slot):
8787
logger.info('Magx {} con conflicto en el slot {}. Pruebo otro.'.format(wizard.username, slot))
8888
if n_iter == n_wizards:
8989
logger.warning('Queda el magx {} con conflicto en el slot {}'.format(wizard, slot))

src/pycamp_bot/models.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ def __str__(self):
4040
rv_str += 'Admin' if self.admin else 'Commoner'
4141
return rv_str
4242

43-
def is_busy(self, moment):
44-
"""`moment` is a tuple (start, end) with two datetime objects."""
45-
target_period_start, target_period_end = moment
43+
def is_busy(self, from_time, to_time):
44+
"""`from_time, to_time` are two datetime objects."""
4645
project_presentation_slots = Slot.select().where(Slot.current_wizard == self)
4746
for slot in project_presentation_slots:
4847
# https://stackoverflow.com/a/13403827/1161156
49-
latest_start = max(target_period_start, slot.start)
50-
earliest_end = min(target_period_end, slot.get_end_time())
48+
latest_start = max(from_time, slot.start)
49+
earliest_end = min(to_time, slot.get_end_time())
5150
if latest_start <= earliest_end: # Overlap
5251
return True
5352
return False

test/test_pycampista.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def test_return_true_if_assigned_in_slot_equal_to_target_period(self):
3131
pycamper = Pycampista.create(username="pepe")
3232
slot = Slot.create(code = "A1", start=datetime.now(), current_wizard=pycamper)
3333
period = (slot.start, slot.get_end_time())
34-
assert pycamper.is_busy(period)
34+
assert pycamper.is_busy(*period)
3535

3636
@use_test_database
3737
def test_return_true_if_assigned_in_slot_starting_at_target_period(self):
3838
pycamper = Pycampista.create(username="pepe")
3939
slot_start = datetime.now()
4040
Slot.create(code = "A1", start=slot_start, current_wizard=pycamper)
4141
period = (slot_start, slot_start + timedelta(minutes=5))
42-
assert pycamper.is_busy(period)
42+
assert pycamper.is_busy(*period)
4343

4444
@use_test_database
4545
def test_return_true_if_assigned_in_slot_around_target_period(self):
@@ -48,7 +48,7 @@ def test_return_true_if_assigned_in_slot_around_target_period(self):
4848
Slot.create(code = "A1", start=slot_start, current_wizard=pycamper)
4949
period_start = slot_start + timedelta(minutes=5)
5050
period = (period_start, period_start + timedelta(minutes=10))
51-
assert pycamper.is_busy(period)
51+
assert pycamper.is_busy(*period)
5252

5353
@use_test_database
5454
def test_return_true_if_assigned_in_slot_ending_after_target_period_starts(self):
@@ -58,7 +58,7 @@ def test_return_true_if_assigned_in_slot_ending_after_target_period_starts(self)
5858
slot.start + timedelta(minutes=5),
5959
slot.get_end_time() + timedelta(minutes=5),
6060
)
61-
assert pycamper.is_busy(period)
61+
assert pycamper.is_busy(*period)
6262

6363
@use_test_database
6464
def test_return_true_if_assigned_in_slot_starting_before_target_period_ends(self):
@@ -68,7 +68,7 @@ def test_return_true_if_assigned_in_slot_starting_before_target_period_ends(self
6868
slot.start - timedelta(minutes=5),
6969
slot.start + timedelta(minutes=5),
7070
)
71-
assert pycamper.is_busy(period)
71+
assert pycamper.is_busy(*period)
7272

7373
@use_test_database
7474
def test_return_false_if_assigned_in_slot_ending_before_target_period_starts(self):
@@ -78,7 +78,7 @@ def test_return_false_if_assigned_in_slot_ending_before_target_period_starts(sel
7878
slot.get_end_time() + timedelta(seconds=1),
7979
slot.get_end_time() + timedelta(seconds=10),
8080
)
81-
assert not pycamper.is_busy(period)
81+
assert not pycamper.is_busy(*period)
8282

8383
@use_test_database
8484
def test_return_false_if_assigned_in_slot_start_after_target_period_ends(self):
@@ -88,4 +88,4 @@ def test_return_false_if_assigned_in_slot_start_after_target_period_ends(self):
8888
slot.start - timedelta(seconds=10),
8989
slot.start - timedelta(seconds=1),
9090
)
91-
assert not pycamper.is_busy(period)
91+
assert not pycamper.is_busy(*period)

0 commit comments

Comments
 (0)