def try_order_with_anchor(possible_order, anchor_index):
    """Given a random order with an anchor that his its times filled already, see if the rest of the times would make sense.

    Replace interviewers in the possible order with InterviewSlots, which are interviewers with associated times.
    """
    interview_slots = []
    anchor = possible_order[anchor_index]
    for position, interviewer in enumerate(possible_order):

        if position == anchor_index:
            interview_slots.append(interviewer)
            continue
        if interviewer is None:
            continue

        if position < anchor_index:
            # Go back n slots from start time
            required_slot = lib.time_period_of_length_after_time(
                anchor.start_time,
                MINUTES_OF_INTERVIEW,
                position - anchor_index
            )
        else:
            # Go forward n slots from end time
            required_slot = lib.time_period_of_length_after_time(
                anchor.end_time,
                MINUTES_OF_INTERVIEW,
                position - anchor_index - 1
            )

        if not interviewer.has_availability_during(required_slot):
            # This order won't work, return it as invalid
            return None

        interview_slots.append(
            InterviewSlot(
                interviewer=interviewer.interviewer.address,
                start_time=required_slot.start_time,
                end_time=required_slot.end_time,
            )
        )

    return interview_slots
示例#2
0
    def setUp(self):
        super(SchedulerTestCase, self).setUp()
        now = datetime(2012, 9, 27, 15, 0).replace(tzinfo=pytz.utc).astimezone(pytz.timezone(settings.TIME_ZONE)).replace(second=0, microsecond=0)
        later = now + timedelta(hours=4)
        self.time_period = lib.TimePeriod(now, later)
        self.fifteen_minutes = lib.TimePeriod(self.time_period.start_time, self.time_period.start_time + timedelta(minutes=15))

        self.default_break = lib.time_period_of_length_after_time(self.time_period.start_time, 75, 0)

        self.test_service_client = client.TestServiceClient()
        self.test_service_client.register_busyness(self.captain.address, self.fifteen_minutes.shift_minutes(60))
        self.test_service_client.register_busyness(self.captain.address, self.fifteen_minutes.shift_minutes(75))
        self.test_service_client.register_busyness(self.captain.address, self.fifteen_minutes.shift_minutes(90))
        self.test_service_client.register_busyness(self.captain.address, self.fifteen_minutes.shift_minutes(105))

        self.calendar_client = client.Client(self.test_service_client)