Exemplo n.º 1
0
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
Exemplo n.º 2
0
def event_schedule_difference(old_schedule, new_schedule):
    """Compute the difference between two schedules from an event perspective


    Parameters
    ----------
    old_schedule : list or tuple
        of :py:class:`resources.ScheduledItem` objects
    new_schedule : list or tuple
        of :py:class:`resources.ScheduledItem` objects

    Returns
    -------
    list
        A list of :py:class:`resources.ChangedEventScheduledItem` objects

    Example
    -------

    >>> from conference_scheduler.resources import Event, Slot, ScheduledItem
    >>> from conference_scheduler.scheduler import event_schedule_difference
    >>> events = [Event(f'event_{i}', 30, 0) for i in range(5)]
    >>> slots = [Slot(f'venue_{i}', '', 30, 100, None) for i in range(5)]
    >>> old_schedule = (
    ...     ScheduledItem(events[0], slots[0]),
    ...     ScheduledItem(events[1], slots[1]),
    ...     ScheduledItem(events[2], slots[2]))
    >>> new_schedule = (
    ...     ScheduledItem(events[0], slots[0]),
    ...     ScheduledItem(events[1], slots[2]),
    ...     ScheduledItem(events[2], slots[3]),
    ...     ScheduledItem(events[3], slots[4]))
    >>> diff = (event_schedule_difference(old_schedule, new_schedule))
    >>> print([item.event.name for item in diff])
    ['event_1', 'event_2', 'event_3']
    """
    old = {item.event.name: item for item in old_schedule}
    new = {item.event.name: item for item in new_schedule}

    common_events = set(old.keys()).intersection(new.keys())
    added_events = new.keys() - old.keys()
    removed_events = old.keys() - new.keys()

    changed = [
        ChangedEventScheduledItem(
            old[event].event, old[event].slot, new[event].slot)
        for event in common_events
        if old[event].slot != new[event].slot
    ]
    added = [
        ChangedEventScheduledItem(new[event].event, None, new[event].slot)
        for event in added_events
    ]
    removed = [
        ChangedEventScheduledItem(old[event].event, old[event].slot, None)
        for event in removed_events
    ]
    return sorted(changed + added + removed, key=lambda item: item.event.name)
Exemplo n.º 3
0
def test_changed_event_schedule_difference(events, slots):
    old_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[4]),
        ScheduledItem(events[2], slots[2])
    )
    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])
    ]
    assert difference == expected