Example #1
0
 def test_from_dict_value_error(self):
     with self.assertRaises(ValueError):
         Availability.from_dict({0: ['00:00', '01:00']})
     with self.assertRaises(ValueError):
         Availability.from_dict({'0': ['00:00']})
     with self.assertRaises(ValueError):
         Availability.from_dict({'0': ['00:00', '00:15', '00:30']})
     with self.assertRaises(ValueError):
         Availability.from_dict({'0': ['00:00', '00:00']})
     with self.assertRaises(ValueError):
         Availability.from_dict({'0': ['00:14', '01:00']})
Example #2
0
    def test_new_timezone_utc_et_daylight_saving(self):
        # Shift forward
        new_avail = c.free_first_five_avail.new_timezone(
            'US/Eastern', 'UTC', c.dt_us_ds)
        correct_avail = Availability.from_dict({'0': [['04:00', '05:15']]})
        self.assertEqual(new_avail, correct_avail)

        # Shift backward
        new_avail = c.free_first_five_avail.new_timezone(
            'UTC', 'US/Eastern', c.dt_us_ds)
        correct_avail = Availability.from_dict({'6': [['20:00', '21:15']]})
        self.assertEqual(new_avail, correct_avail)
Example #3
0
    def test_new_timezone_availability_utc_et_daylight_saving(self):
        # Shift forward
        user = c.new_user(c.student, {'tz_str': 'US/Eastern'})
        new_avail = user.new_timezone_availability('UTC', c.dt_us_ds)
        avail = Availability.from_dict({'0': [['04:00', '05:30']]})
        self.assertEqual(new_avail, avail)

        # Shift backward
        user = c.new_user(c.student, {'tz_str': 'UTC'})
        new_avail = user.new_timezone_availability('US/Eastern', c.dt_us_ds)
        avail = Availability.from_dict({'6': [['20:00', '21:30']]})
        self.assertEqual(new_avail, avail)
Example #4
0
    def test_new_timezone_midway_chatham_daylight_saving(self):
        # Shift forward
        new_avail = c.free_first_six_avail.new_timezone(
            'Pacific/Midway', 'Pacific/Chatham', c.dt_chatham_ds)
        correct_avail = Availability.from_dict({'1': [['00:45', '02:15']]})
        self.assertEqual(new_avail, correct_avail)

        # Shift backward
        new_avail = c.free_first_six_avail.new_timezone(
            'Pacific/Chatham', 'Pacific/Midway', c.dt_chatham_ds)
        correct_avail = Availability.from_dict({
            '5': [['23:15', '24:00']],
            '6': [['00:00', '00:45']]
        })
        self.assertEqual(new_avail, correct_avail)
Example #5
0
 def test_forward_shifted_free_first_six_avail_forward(self):
     correct_shifted_avail = Availability.from_dict(
         {'0': [['00:15', '01:45']]})
     for i in range(-1, 2):
         shifted_avail = c.free_first_six_avail.forward_shifted(
             c.MINUTES_PER_WEEK * i + 15)
         self.assertEqual(shifted_avail, correct_shifted_avail)
Example #6
0
def run_scheduler(registrations):
    """
    Runs the scheduler and prints a json containing a list of schedule objects
    to be written to the database.
    """
    # Convert registrations dict to students, tutors
    students = []
    tutors = []
    for registration in registrations:
        reg_id = registration['_id']
        availability = Availability.from_dict(registration['availability'])
        gender_preference = registration['genderPref']
        courses = registration['courses']
        earliest_start_date_str = registration['earliestStartTime']
        earliest_start_date = datetime.strptime(earliest_start_date_str,
                                                '%Y-%m-%d').date()
        user_dict = registration['user']
        user_id = user_dict['_id']
        gender = user_dict['gender'].upper()
        tz_string = user_dict['timezone']
        user_type = user_dict['role'].upper()
        user = User(user_id, reg_id, user_type, gender, gender_preference,
                    availability, tz_string, courses, earliest_start_date)
        if user_type == 'STUDENT':
            students.append(user)
        if user_type == 'TUTOR':
            tutors.append(user)

    # Run scheduler
    scheduler = Scheduler(students, tutors)
    schedule_dicts = scheduler.schedule_dicts_for_database()
    # print instead of return because python-shell receives this data from Python stdout
    print(json.dumps(schedule_dicts))
Example #7
0
 def test_shared_course_start_times_UTC_kabul_et_no_ds_overlap_one(self):
     user1 = c.new_user(
         c.student, {
             'tz_str': 'Asia/Kabul',
             'availability': c.free_first_six_avail,
             'earliest_start_date': c.dt_2000_1_1
         })
     avail = Availability.from_dict({'6': [['14:30', '16:00']]})
     user2 = c.new_user(
         c.student, {
             'tz_str': 'US/Eastern',
             'availability': avail,
             'earliest_start_date': date(2017, 3, 12)
         })
     shared = user1.shared_course_start_times_UTC(user2)
     self.assertEqual(shared, [WeeklyTime(6, 19, 30)])
Example #8
0
 def test_from_dict_nonconsecutive_free_dict(self):
     self.assertEqual(Availability.from_dict(c.nonconsecutive_free_dict),
                      c.nonconsecutive_free_avail)
Example #9
0
 def test_from_dict_free_sat_sun_six_dict(self):
     self.assertEqual(Availability.from_dict(c.free_sat_sun_six_dict),
                      c.free_sat_sun_six_avail)
Example #10
0
 def test_from_dict_never_free_dict(self):
     self.assertEqual(Availability.from_dict(c.never_free_dict),
                      c.never_free_avail)
Example #11
0
 def test_from_dict_free_first_five_dict(self):
     self.assertEqual(Availability.from_dict(c.free_first_five_dict),
                      c.free_first_five_avail)
Example #12
0
 def test_from_dict_always_free_dict(self):
     self.assertEqual(Availability.from_dict(c.always_free_dict),
                      c.always_free_avail)
Example #13
0
nonconsecutive_free_dict = {
    '0': [['00:15', '00:30'], ['00:45', '01:30']],
    '1': [['01:00', '01:15']]
}
free_first_five_dict = {'0': [['00:00', '01:15']]}
free_first_six_dict = {'0': [['00:00', '01:30']]}
free_first_seven_dict = {'0': [['00:00', '01:45']]}
free_0_0930_1100_dict = {'0': [['09:30', '11:00']]}

# Availability objects
always_free_avail = Availability(always_free_slots)
never_free_avail = Availability(never_free_slots)
free_sat_sun_six_avail = Availability(free_sat_sun_six_slots)
nonconsecutive_free_avail = Availability(nonconsecutive_free_slots)
free_first_five_avail = Availability(free_first_five_slots)
free_first_six_avail = Availability.from_dict(free_first_six_dict)
free_first_seven_avail = Availability.from_dict(free_first_seven_dict)
free_0_0115_0245_avail = Availability.from_dict({'0': [['01:15', '02:45']]})
free_0_0215_0345_avail = Availability.from_dict({'0': [['02:15', '03:45']]})
free_0_0830_1000_avail = Availability.from_dict({'0': [['08:30', '10:00']]})
free_0_0930_1100_avail = Availability.from_dict(free_0_0930_1100_dict)

# Timezone constants
all_tz = [pytz.timezone(tz_name) for tz_name in pytz.all_timezones]
utc = pytz.timezone('UTC')
midway = pytz.timezone('Pacific/Midway')  # UTC-11:00, no daylight saving
arizona = pytz.timezone('US/Arizona')  # UTC-07:00, no daylight saving
central = pytz.timezone(
    'US/Central'
)  # UTC-05:00 during daylight saving, UTC-06:00 without daylight saving
et = pytz.timezone(