コード例 #1
0
    def test_find_free_slots(self):
        shift = Interval(9, 14)
        appointments = [Interval(9, 10), Interval(10, 11), Interval(13, 14)]

        slots = slots_in_interval(1, shift)
        free = [s for s in slots if not interval_overlaps(s, appointments)]

        self.assertEqual(free, [Interval(11, 12), Interval(12, 13)])
コード例 #2
0
 def add_appointment(self, start, end):
     app_interval = Interval(start, end)
     app_id = id(app_interval)
     length = app_interval.end - app_interval.start
     for sid, shift in self._shifts.iteritems():
         interval = shift["interval"]
         appointments = shift["appointments"].values()
         slots = slots_in_interval(length, interval, self._min_length)
         for slot in slots:
             if slot == app_interval and \
                        not interval_overlaps(slot, appointments):
                 self._appointments[app_id] = sid
                 self._shifts[sid]["appointments"][app_id] \
                     = app_interval
                 return app_id
     raise NotAvailableSlotError