def test_init_value_error(self): with self.assertRaises(ValueError): Availability([]) with self.assertRaises(ValueError): Availability([True for i in range(671)]) with self.assertRaises(ValueError): Availability([True for i in range(673)])
def test_one_task_one_user_assign(self): start_a = datetime.datetime(2000, 1, 1, 6, 0, 0) end_a = datetime.datetime(2000, 1, 1, 22, 0, 0) availability = [Availability(Duration(start_a, end_a))] category = Category(1, 'TestCategory') preferences = [Preference(category, 0, True)] groups = [Group(1, 'Employee')] generic = CommonTestFunctions() staff_member = StaffMember(1, 'TestMember', 0, 40, 80, 10, availability, preferences, groups) start_t = datetime.datetime(2000, 1, 1, 9, 0, 0) end_t = datetime.datetime(2000, 1, 1, 16, 0, 0) task_time = Duration(start_t, end_t) location = Location(1, 'TestLocation') task = Task(1, 'TestTask', task_time, 1, groups[0], location, category) staff_members = [staff_member] roles = [] tasks = [task] settings = generic.settings(40, True) generator = ScheduleGenerator(staff_members, roles, tasks) generator.schedule(settings) self.assertTrue(staff_member.has_task(task)) self.assertFalse(generator.has_unassigned_tasks())
def period_avail(period, days, hours, minutes): plist = ('daily', 'weekly', 'monthly', 'yearly') av = Availability(days, hours, minutes) if period in plist and isinstance(period, str): return json.dumps(av.service(period=period, out_dict=True)) else: return json.dumps({"error":"period not properly set, must be of : " + str(plist)})
def camp_availability(self, day, start_hour, end_hour, start_minute=0, end_minute=0): start_a = datetime.datetime(2018, 7, day, start_hour, start_minute, 0) end_a = datetime.datetime(2018, 7, day, end_hour, end_minute, 0) return Availability(Duration(start_a, end_a))
def setUpClass(cls): with open("etc/environment.json") as f: cls.config = json.load(f) # os.environ["AWS_LAMBDA_FUNCTION_NAME"] = "test" os.environ["TOPIC"] = cls.config["Fn"]["TOPIC"] os.environ["TABLE"] = cls.config["Fn"]["TABLE"] cls.av = Availability() cls.av.logging = False cls.av.pull_config() cls.user = "******" cls.store = "cvs" cls.notification = { "store": "CVS", "availability_at": [ "BROWNS MILLS", "ELIZABETH", "ENGLEWOOD", "EWING", "GIBBSBORO", "GLASSBORO", "LAWRENCEVILE", "LODI", "LONG BRANCH", "NORTH BRUNSWICK", "NORTH PLAINFIELD", "PENNSAUKEN", "PLAINSBORO", "TEANECK", "WEST ORANGE", "WILLINGBORO" ] } cls.context = Context()
def assemble(database_availabilities, database_days_off, current_date=datetime.datetime.now()): availability = [] converter = DateConverter() for time in database_availabilities: day = time.get_day_as_string() start_time = time.start_time end_time = time.end_time duration = Availability( converter.create_duration_on_next_day(day, day, start_time, end_time, current_date)) # Hack because the dateConverter isn't working properly but it'll work so we'll leave it. if day == 'Sunday': duration.start_time = duration.start_time - timedelta(days=7) duration.end_time = duration.end_time - timedelta(days=7) availability.append(duration) for day_off in database_days_off: if not day_off.get_is_approved(): continue date = day_off.day start_time = datetime.datetime(date.year, date.month, date.day, 0, 0) end_time = datetime.datetime(date.year, date.month, date.day, 23, 59) duration = Duration(start_time, end_time) to_remove = [] for a in availability: if a.can_happen_inside_of(duration): to_remove.append(a) for t in to_remove: availability.remove(t) return availability
def availability(self, start_hour=6, end_hour=22, start_day=1, end_day=1): return Availability( self.duration(start_hour, end_hour, 0, 0, start_day, end_day))
def availability(self, pk): raw_availability = FareHarborService().get_availability( self.shortname, pk) availability_data = raw_availability['availability'] return Availability(availability_data)
def availabilities_by_date_range(self, data): raw_availabilities = FareHarborService( ).get_availabilities_by_date_range(self.shortname, data) availabilities_data = raw_availabilities['availabilities'] return [Availability(i) for i in availabilities_data]
# Availability dicts always_free_dict = {str(i): [['00:00', '24:00']] for i in range(7)} never_free_dict = {} free_sat_sun_six_dict = {'0': [['00:00', '00:45']], '6': [['23:15', '24:00']]} 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
def setUp(self): self.avail = Availability(0, 0, 0) self.avail_x = Availability(0, 5, 15)
def avail(days, hours, minutes): av = Availability(days, hours, minutes) return json.dumps(av.service(out_dict=True))
def __init__(self, id, type, availability): self.id = id self.availability = Availability(availability) self.type = type
down_reg = re.compile(r'^(\d+)d(\d+)h(\d+)m$') format_match = False print('Enter downtime') print('Use format XdYhZm') print('\tWhere X is number of day, Y number of Hours and Z number of minutes') print('\tWith X,Y,Z are integer and 0 as minimum or none value') while not format_match: downtime = str(input('>')) if down_reg.match(downtime): format_match = True else: print('Format entered not compatible !') downtime_match = down_reg.search(downtime) #print(type(downtime_match.group(1))) down = Availability(int(downtime_match.group(1)), int(downtime_match.group(2)), int(downtime_match.group(3))) daily = down.service(period='daily') print(daily) weekly = down.service(period='weekly') print(weekly) monthly = down.service(period='monthly', out_dict=True) print(monthly) fullsla = down.service(out_dict=True) print(json.dumps(fullsla)) #err_test = down.period_uptime(-32) #err_test = down.period_uptime('fail') #err_test = down.period_uptime(5.43)
from aws_xray_sdk.core import patch_all # helper functions def build_response(code, body): # headers for cors headers = { "Access-Control-Allow-Origin": "amazonaws.com", "Access-Control-Allow-Credentials": True } # lambda proxy integration response = { 'isBase64Encoded': False, 'statusCode': code, 'headers': headers, 'body': body } return response # function: lambda invoker handler def handler(event, context): av.check_stores() output = av.check_users() for o in output: av.put_emf(context, o["user"], o["availability"]) return output # function: initialization patch_all() av = Availability() av.logging = False av.pull_config()