def get_nurse_events_2(employee_name, unavilable_slots): employee_events = [] unavailable_events = [] for day in range(0, 7): selected = random.sample([1, 2, 3], 1) event1 = Event(name=employee_name + '_e1_' + '_' + str(day), duration=60 * 8, tags=[employee_name], demand=3, unavailability=unavilable_slots) event2 = Event(name=employee_name + '_e2_' + '_' + str(day), duration=60 * 8, tags=[employee_name], demand=3, unavailability=unavilable_slots) event3 = Event(name=employee_name + '_e3_' + '_' + str(day), duration=60 * 8, tags=[employee_name], demand=3, unavailability=unavilable_slots) if selected == 1: employee_events.append(event1) unavailable_events = [event2, event3] elif selected == 2: employee_events.append(event2) unavailable_events = [event1, event3] else: employee_events.append(event3) unavailable_events = [event1, event2] return employee_events, unavailable_events
def test_removed_event_schedule_difference(slots): events = [ Event(name='Talk 1', duration=30, demand=30), Event(name='Talk 2', duration=30, demand=500), Event(name='Workshop 1', duration=60, demand=20), Event(name='Workshop 2', duration=60, demand=20) ] old_schedule = ( ScheduledItem(events[0], slots[1]), ScheduledItem(events[1], slots[4]), ScheduledItem(events[2], slots[2]), ScheduledItem(events[3], slots[5]) ) new_schedule = ( ScheduledItem(events[0], slots[1]), ScheduledItem(events[1], slots[3]), ScheduledItem(events[2], slots[4]) ) difference = scheduler.event_schedule_difference( old_schedule, new_schedule) expected = [ ChangedEventScheduledItem(events[1], slots[4], slots[3]), ChangedEventScheduledItem(events[2], slots[2], slots[4]), ChangedEventScheduledItem(events[3], slots[5], None) ] assert difference == expected
def test_optional_args_are_safely_mutable(): # Construct an instance of `Event` with the optional arguments, # omitted, then assign it a tag e = Event(name='example', duration=60, demand=100) assert e.tags == () e.add_tags('intermediate') assert e.tags == ('intermediate', ) # Now create a second instance of `Event`, and check we haven't # polluted the default arguments. f = Event(name='another example', duration=30, demand=50) assert f.tags == ()
def events(slots): event1 = Event(name='Talk 1', duration=30, tags=['community'], unavailability=[slots[0], slots[1]], demand=30) event2 = Event(name='Talk 2', duration=30, tags=['community', 'documentation'], unavailability=[slots[2], slots[3], event1], demand=500) event3 = Event(name='Workshop 1', duration=60, tags=['documentation'], unavailability=[], demand=20) return (event1, event2, event3)
def test_can_construct_event(): e = Event(name='example', duration=60, demand=100, tags=['beginner', 'python'], unavailability=[]) assert isinstance(e, Event) assert e.name == 'example' assert e.tags == ('beginner', 'python') assert e.unavailability == ()
def get_nurse_events(employee_name, unavilable_slots): employee_events = [] for day in range(0, 7): event = Event(name=employee_name + '_' + str(day), duration=60 * 8, tags=[employee_name], demand=3) employee_events.append(event) return employee_events
def convert_mozfestevent_to_event_for_auto_schedule(events): converted_events = [] for event in events: converted_events.append(Event( name=event.title, duration=event.duration, demand=0, tags=[event.track] )) return converted_events
def events(event_types, roles, people): return ( Event( name='Talk 1', event_type=event_types['talk'], duration=30, roles={roles['speaker']: people['alice']} ), Event( name='Talk 2', event_type=event_types['talk'], duration=30, roles={roles['speaker']: people['bob']} ), Event( name='Workshop 1', event_type=event_types['workshop'], duration=60, roles={roles['leader']: people['charlie']} ) )
def unbounded(unbound_definition, timetable): return [{ 'event': Event(name=event, duration=details['duration'], demand=0, tags=details['tags'] + [day, venue]), 'slot': Slot(venue=venue, starts_at=(datetime.combine(day, datetime.min.time()) + timedelta(seconds=details['starts_at'])), duration=details['duration'], session=f'{day} unbound', capacity=0) } for unbound in unbound_definition for event, details in unbound.items() for venue, days in timetable.items() for day in days]
def allocations(allocations_definition): try: return [{ 'event': Event(name=event, duration=details['duration'], demand=0, tags=details['tags'] + [details['day'], details['venue']]), 'slot': Slot(venue=details['venue'], starts_at=( datetime.combine(details['day'], datetime.min.time()) + timedelta(seconds=details['starts_at'])), duration=details['duration'], session=(f'{details["day"]} {details["session"]}'), capacity=-1) } for allocation in allocations_definition for event, details in allocation.items()] except TypeError: return []
def types_and_events(events_definition): """ Parameters ---------- events_definition : list of dicts of the form {'title': Event title, 'duration': <integer in minutes>, 'tags': <list of strings>, 'person': <string>} Returns ------- list of dicts mapping an event type to an Event instance """ return [{ 'event_type': event['event_type'], 'event': Event(name=event['title'], duration=event['duration'], demand=event['demand'], tags=event['tags']) } for event in events_definition]
def test_event_is_hashable(): e = Event(name='example', duration=60, demand=100) events = set([e]) assert len(events) == 1
def test_remove_tag(): e = Event(name='example', duration=60, demand=100) e.add_tags('test1', 'test2', 'test3') e.remove_tag('test2') assert e.tags == ('test1', 'test3')
def test_clear_tags(): e = Event(name='example', duration=60, demand=100) e.add_tags('test1', 'test2', 'test3') e.clear_tags() assert e.tags == ()
def test_add_single_tag(): e = Event(name='example', duration=60, demand=100) e.add_tags('test') assert e.tags == ('test', )
def test_add_multiple_tags(): e = Event(name='example', duration=60, demand=100) e.add_tags('test1', 'test2', 'test3') assert e.tags == ('test1', 'test2', 'test3')
def test_clear_unavailability(): e = Event(name='example', duration=60, demand=100) e.add_unavailability(2, 3, 4) e.clear_unavailability() assert e.unavailability == ()
def test_remove_unavailability(): e = Event(name='example', duration=60, demand=100) e.add_unavailability(2, 3, 4) e.remove_unavailability(3) assert e.unavailability == (2, 4)
def test_add_multiple_unavailability(): e = Event(name='example', duration=60, demand=100) e.add_unavailability(2, 3, 4) assert e.unavailability == (2, 3, 4)
0, slot_time['starts_at'])).strftime('%d-%b-%Y %H:%M'), duration=slot_time['duration'], session=f"{day.date()} {slot_time['session_name']}", capacity=venues[venue]['capacity']) for venue, day, slot_time in it.product(venues, days, slot_times[event_type]) if (event_type in venues[venue]['suitable_for'] and event_type in days[day]['event_types']) ] for event_type in event_types } talks = definition['talks'] events = { 'talk': [ Event(talk['title'], talk['duration'], demand=None, tags=talk.get('tags', None)) for talk in talks ] } speaker_unavailability = definition['speaker_unavailability'] talk_unavailability = { talks.index(talk): [ slots['talk'].index(slot) for period in periods for slot in slots['talk'] if period['unavailable_from'] <= datetime.strptime( slot.starts_at, '%d-%b-%Y %H:%M') and period['unavailable_until'] >= datetime.strptime(slot.starts_at, '%d-%b-%Y %H:%M') + timedelta(0, slot.duration * 60) ] for speaker, periods in speaker_unavailability.items() for talk in talks
def test_optional_args_to_event_are_defaulted(): e = Event(name='example', duration=60, demand=100) assert e.tags == () assert e.unavailability == ()