Beispiel #1
0
 def test_schedule_simple_merge(self):
     s1 = Schedule(day='monday', start_time=9, end_time=15)
     s1.put()
     s2 = Schedule(day='monday', start_time=13, end_time=18)
     s2.put()
     # check that merge was done
     self.assertEquals(s2.start_time, 9)
     self.assertEquals(s2.end_time, 18)
Beispiel #2
0
 def test_schedule_no_merge(self):
     s1 = Schedule(day='monday', start_time=9, end_time=13)
     s1.put()
     s2 = Schedule(day='monday', start_time=14, end_time=18)
     s2.put()
     # check that there was no merge
     self.assertEquals(s2.start_time, 14)
     self.assertEquals(s2.end_time, 18)
Beispiel #3
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
Beispiel #4
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')
Beispiel #5
0
 def test_schedule_simple_merge(self):
     s1 = Schedule(day='monday', start_time=9, end_time=15)
     s1.put()
     s2 = Schedule(day='monday', start_time=13, end_time=18)
     s2.put()
     # check that merge was done
     self.assertEquals(s2.start_time, 9)
     self.assertEquals(s2.end_time, 18)
Beispiel #6
0
 def test_schedule_no_merge(self):
     s1 = Schedule(day='monday', start_time=9, end_time=13)
     s1.put()
     s2 = Schedule(day='monday', start_time=14, end_time=18)
     s2.put()
     # check that there was no merge
     self.assertEquals(s2.start_time, 14)
     self.assertEquals(s2.end_time, 18)
Beispiel #7
0
    def testFindBestProviderForBooking(self):
        testCategory = u'physiotherapy'
        testLocation = u'montreal-west'

        # create provider
        p = Provider()
        p.terms_agreement = True
        p.status = 'client_enabled'
        p.first_name = 'Best-Test'
        p.last_name = 'Phys-Io'
        p.category = testCategory
        p.location = testLocation
        p.vanity_url = 'physio_guy'
        pkey = p.put()
        # add a provider's schedule (Thursday Morning)
        s = Schedule()
        s.day = 'thursday'
        s.start_time = 8
        s.end_time = 12
        s.provider = p.key
        s.put()
        # create provider with no schedule
        p = Provider()
        p.first_name = 'NoSchedule'
        p.last_name = 'Phys-Io'
        p.category = testCategory
        p.location = testLocation
        pkey2 = p.put()
        # 2 providers in db
        self.assertEqual(2,
                         Provider.query().count(), '2 providers in datastore')
        # create booking
        b = Booking()
        b.request_category = testCategory
        b.request_location = testLocation
        b.request_datetime = datetime.strptime('2012-04-26 10', '%Y-%m-%d %H')
        b.put()
        # test the matching
        brs = db_search.provider_search(b)
        logging.info('best provider:' + str(brs))
        # assert
        self.assertIsNotNone(brs, 'provider should not be None')
        self.assertEqual(pkey, brs[0].provider.key,
                         'provider keys should be equal')
Beispiel #8
0
 def testFindBestProviderForBooking(self):
     testCategory = u'physiotherapy'
     testLocation = u'montreal-west'
     
     # create provider
     p = Provider()
     p.terms_agreement=True
     p.status = 'client_enabled'
     p.first_name = 'Best-Test'
     p.last_name = 'Phys-Io'
     p.category = testCategory
     p.location = testLocation
     p.vanity_url = 'physio_guy'
     pkey = p.put()
     # add a provider's schedule (Thursday Morning)
     s = Schedule()
     s.day = 'thursday'
     s.start_time = 8
     s.end_time = 12
     s.provider = p.key
     s.put()
     # create provider with no schedule
     p = Provider()
     p.first_name = 'NoSchedule'
     p.last_name = 'Phys-Io'
     p.category = testCategory
     p.location = testLocation
     pkey2 = p.put()
     # 2 providers in db
     self.assertEqual(2, Provider.query().count(), '2 providers in datastore')
     # create booking
     b = Booking()
     b.request_category = testCategory
     b.request_location = testLocation
     b.request_datetime = datetime.strptime('2012-04-26 10', '%Y-%m-%d %H')
     b.put();
     # test the matching
     brs = db_search.provider_search(b)
     logging.info('best provider:' + str(brs))
     # assert
     self.assertIsNotNone(brs, 'provider should not be None')
     self.assertEqual(pkey, brs[0].provider.key, 'provider keys should be equal')
     
Beispiel #9
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
Beispiel #10
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')