Ejemplo n.º 1
0
def test_person_add_activity_activity_raise_error():
    person = Person(1)
    act = Activity(1, 'home', 1)
    person.add(act)
    act = Activity(2, 'work', 1)
    with pytest.raises(UserWarning):
        person.add(act)
Ejemplo n.º 2
0
def test_person_closed_plan():
    person = Person(1)
    person.add(Activity(1, 'home', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'work', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=1))
    person.add(Activity(3, 'home', 1))
    assert person.closed_plan
Ejemplo n.º 3
0
def test_person_not_home_based():
    person = Person(1)
    person.add(Activity(1, 'work', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'home', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=1))
    person.add(Activity(3, 'work', 1))
    assert not person.home_based
Ejemplo n.º 4
0
def test_person_not_closed_plan_different_areas():
    person = Person(1)
    person.add(Activity(1, 'work', 1))
    person.add(Leg(1, 'car', start_area=1, end_area=2))
    person.add(Activity(2, 'home', 1))
    person.add(Leg(2, 'car', start_area=2, end_area=3))
    person.add(Activity(3, 'work', 3))
    assert not person.closed_plan
Ejemplo n.º 5
0
def home_education_home():

    person = Person(1)
    person.add(Activity(1, 'home', 'a'))
    person.add(Leg(1, 'car', 'a', 'b'))
    person.add(Activity(2, 'education', 'b'))
    person.add(Leg(2, 'car', 'b', 'a'))
    person.add(Activity(3, 'home', 'a'))

    return person
Ejemplo n.º 6
0
def test_person_add_leg():
    person = Person(1)
    act = Activity(1, 'home', 1)
    person.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2)
    person.add(leg)
    assert len(person.plan) == 2
Ejemplo n.º 7
0
def test_household_add_person():
    household = Household(1)
    person = Person(1)
    person.add(Activity(1, 'home', 1, start_time=0))
    household.add(person)
    assert len(household.people) == 1
    assert list(household.people) == [1]
Ejemplo n.º 8
0
def test_person_add_leg_leg_raise_error():
    person = Person(1)
    act = Activity(1, 'home', 1)
    person.add(act)
    leg = Leg(1, 'car', start_area=1, end_area=2)
    person.add(leg)
    leg = Leg(2, 'car', start_area=2, end_area=1)
    with pytest.raises(UserWarning):
        person.add(leg)
Ejemplo n.º 9
0
def test_home_education_home_removal_of_education_act():

    household = HouseHold(1)
    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_loc='a',
            end_loc='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_loc='b',
            end_loc='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(24 * 60 - 1)))
    household.add(person)

    policy = policies.RemoveEducationActivity(1)
    policy.apply_to(household)
    assert [p.act for p in household.people[1].activities] == ['home']
    assert household.people[1].plan[0].start_time == minutes_to_datetime(0)
    assert household.people[1].plan[0].end_time == minutes_to_datetime(24 *
                                                                       60 - 1)
Ejemplo n.º 10
0
def population():

    population = Population()
    for hid in range(1, 11):
        household = HouseHold(hid)
        for pid in range(2):
            pid = f"{hid}-{pid}"
            person = Person(pid)

            person.add(Activity(1, 'home', 'a'))
            person.add(Leg(1, 'car', 'a', 'b'))
            person.add(Activity(2, 'work', 'b'))
            person.add(Leg(2, 'car', 'b', 'a'))
            person.add(Activity(3, 'home', 'a'))

            household.add(person)
        population.add(household)

    for hid in range(10, 21):
        household = HouseHold(hid)
        for pid in range(2):
            pid = f"{hid}-{pid}"
            person = Person(pid)

            person.add(Activity(1, 'home', 'a'))
            person.add(Leg(1, 'bus', 'a', 'b'))
            person.add(Activity(2, 'education', 'b'))
            person.add(Leg(2, 'bus', 'b', 'a'))
            person.add(Activity(3, 'home', 'a'))

            household.add(person)
        population.add(household)
    return population
Ejemplo n.º 11
0
def person_home_education_home():

    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(24 * 60 - 1)))

    return person
Ejemplo n.º 12
0
def test_home_work_home_education_home_removal_of_education_act():

    household = Household(1)
    person = Person(1)
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(0),
                 end_time=minutes_to_datetime(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(60),
            end_time=minutes_to_datetime(90)))
    person.add(
        Activity(seq=2,
                 act='work',
                 area='b',
                 start_time=minutes_to_datetime(90),
                 end_time=minutes_to_datetime(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(120),
            end_time=minutes_to_datetime(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(180),
                 end_time=minutes_to_datetime(300)))
    person.add(
        Leg(seq=3,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=minutes_to_datetime(300),
            end_time=minutes_to_datetime(390)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=minutes_to_datetime(390),
                 end_time=minutes_to_datetime(520)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=minutes_to_datetime(520),
            end_time=minutes_to_datetime(580)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=minutes_to_datetime(680),
                 end_time=minutes_to_datetime(24 * 60 - 1)))
    household.add(person)

    policy = policies.RemoveEducationActivity(1)
    policy.apply_to(household)
Ejemplo n.º 13
0
def test_person_add_activity():
    person = Person(1)
    act = Activity(1, 'home', 1)
    person.add(act)
    assert len(person.plan) == 1