Ejemplo n.º 1
0
def get_sorted_schedule_timeslots(provider, request_timeslot):
    '''
        Get a provider's timeslots ordered by proximity to the requested time
        This method is limited to the day of the request for now. Eventually expand to multi-day search
    '''

    # returns day of week (0=monday, 1=tuesday, etc.)
    request_day = request_timeslot.start.weekday()

    # map the number to the actual day
    request_day_key = get_days_of_the_week()[request_day][0]

    request_date = request_timeslot.start.date()
    scheduleQuery = Schedule.query(Schedule.provider == provider.key,
                                   Schedule.day == request_day_key)
    logging.debug('schedules count for %s is %s' %
                  (request_day_key, scheduleQuery.count()))
    timeslots = []
    for s in scheduleQuery:
        ts = create_one_hour_timeslots_over_range(request_date, s.start_time,
                                                  s.end_time)
        timeslots = timeslots + ts
    # sort
    sorted_timeslots = sorted(
        timeslots, key=lambda t: timeslot_distance(t, request_timeslot))
    return sorted_timeslots
Ejemplo n.º 2
0
 def test_schedule_double_merge(self):
     s1 = Schedule(day='monday', start_time=8, end_time=11)
     s1.put()
     s2 = Schedule(day='monday', start_time=14, end_time=18)
     s2.put()
     # check - no merge
     self.assertEquals(s2.start_time, 14)
     self.assertEquals(s2.end_time, 18)
     s3 = Schedule(day='monday', start_time=10, end_time=14)
     s3.put()
     # check that merge was done
     self.assertEquals(s3.start_time, 8)
     self.assertEquals(s3.end_time, 18)
     
     schedules = Schedule.query(Schedule.day=='monday').fetch()
     self.assertEquals(len(schedules), 1, 'Should only be one schedule stored')
     self.assertEquals(schedules[0].start_time, 8)
     self.assertEquals(schedules[0].end_time, 18)
     self.assertEquals(schedules[0].day, 'monday')
Ejemplo n.º 3
0
    def test_schedule_double_merge(self):
        s1 = Schedule(day='monday', start_time=8, end_time=11)
        s1.put()
        s2 = Schedule(day='monday', start_time=14, end_time=18)
        s2.put()
        # check - no merge
        self.assertEquals(s2.start_time, 14)
        self.assertEquals(s2.end_time, 18)
        s3 = Schedule(day='monday', start_time=10, end_time=14)
        s3.put()
        # check that merge was done
        self.assertEquals(s3.start_time, 8)
        self.assertEquals(s3.end_time, 18)

        schedules = Schedule.query(Schedule.day == 'monday').fetch()
        self.assertEquals(len(schedules), 1,
                          'Should only be one schedule stored')
        self.assertEquals(schedules[0].start_time, 8)
        self.assertEquals(schedules[0].end_time, 18)
        self.assertEquals(schedules[0].day, 'monday')
Ejemplo n.º 4
0
def get_sorted_schedule_timeslots(provider, request_timeslot):
    '''
        Get a provider's timeslots ordered by proximity to the requested time
        This method is limited to the day of the request for now. Eventually expand to multi-day search
    '''
    
    # returns day of week (0=monday, 1=tuesday, etc.)
    request_day = request_timeslot.start.weekday()
    
    # map the number to the actual day
    request_day_key = get_days_of_the_week()[request_day][0]
    
    request_date = request_timeslot.start.date()
    scheduleQuery = Schedule.query(Schedule.provider==provider.key, Schedule.day==request_day_key)
    logging.debug('schedules count for %s is %s' % (request_day_key, scheduleQuery.count()))
    timeslots = []
    for s in scheduleQuery:
        ts = create_one_hour_timeslots_over_range(request_date, s.start_time, s.end_time)
        timeslots = timeslots + ts
    # sort
    sorted_timeslots = sorted(timeslots, key=lambda t: timeslot_distance(t, request_timeslot))
    return sorted_timeslots