Example #1
0
def person_work_home_work_not_closed():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='work',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='home',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='c',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='work',
                 area='c',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))

    return person
Example #2
0
def person_heh():

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

    return person
Example #3
0
def person_crop_last_leg():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(2600)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(2600),
                 end_time=mtdt(3000)))

    return person
Example #4
0
def person_crop_last_act():

    person = Person('1', attributes={'old': True})
    person.add(
        Activity(seq=1,
                 act='home',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='education',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='a',
                 start_time=mtdt(180),
                 end_time=END_OF_DAY))

    return person
Example #5
0
def test_crop_act_out_of_order():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(12000)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='B',
            end_area='A',
            start_time=mtdt(12000),
            end_time=END_OF_DAY))
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(12030)))
    plan.crop()
    assert plan.length == 3
    assert plan.day[-1].end_time == END_OF_DAY
Example #6
0
def test_extract_person_mode_classes():
    person = Person(pid=str(1))
    person.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    person.add(
        Leg(seq=2,
            mode='bike',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    person.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(1200)))
    person.add(
        Leg(seq=2,
            mode='pt',
            start_area='B',
            end_area='A',
            start_time=mtdt(1200),
            end_time=mtdt(1220)))
    person.add(
        Activity(seq=3,
                 act='home',
                 area='A',
                 start_time=mtdt(1220),
                 end_time=mtdt(1500)))

    assert person.mode_classes == set(['bike', 'pt'])
Example #7
0
def Bobby():
    Bobby = Person(4,
                   attributes={
                       'age': 6,
                       'job': 'education',
                       'gender': 'non-binary'
                   })
    Bobby.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Bobby.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Bobby.add(
        Activity(2,
                 'education',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(16 * 60)))
    Bobby.add(
        Leg(2,
            'walk',
            'b',
            'c',
            start_time=mtdt(16 * 60),
            end_time=mtdt(16 * 60 + 30)))
    Bobby.add(
        Activity(5,
                 'home',
                 'a',
                 start_time=mtdt(16 * 60 + 30),
                 end_time=END_OF_DAY))
    return Bobby
Example #8
0
def test_compare_plans_not_equal_types():
    plana = Plan()
    plana.add(
        Activity(seq=1,
                 act='work',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plana.add(
        Leg(seq=2,
            mode='car',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plana.add(
        Activity(seq=3,
                 act='shop',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(1200)))

    with pytest.raises(UserWarning):
        assert not plana == None
Example #9
0
def test_get_component():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(1200)))
    assert plan.get(0).act == 'home'
    assert plan.get(4) is None
    assert plan.get(4, '1') == '1'
Example #10
0
def test_mode_and_activity_classes():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='A',
            end_area='B',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=mtdt(1200)))

    assert plan.activity_classes == set(['home', 'work'])
    assert plan.mode_classes == set(['car'])
Example #11
0
def test_activity_tours_segments_home_to_other_act_nonhome_looped_plan(
        activities_and_tour):
    other_act = Activity(8, 'other', 'e')

    plan = Plan(1)
    plan.add(other_act)
    plan.add(Leg(1))
    for i in range(len(activities_and_tour['activities'])):
        plan.add(activities_and_tour['activities'][i])
        plan.add(Leg(1))
    plan.add(other_act)

    assert plan[0].act == plan[-1].act
    assert plan.activity_tours(
    ) == [[other_act]] + activities_and_tour['tours'] + [[other_act]]
Example #12
0
def test_fix_location_consistency():
    plan = Plan()
    plan.add(
        Activity(seq=1,
                 act='home',
                 area='A',
                 start_time=mtdt(0),
                 end_time=mtdt(600)))
    plan.add(
        Leg(seq=2,
            mode='car',
            start_area='B',
            end_area='A',
            start_time=mtdt(600),
            end_time=mtdt(620)))
    plan.add(
        Activity(seq=3,
                 act='work',
                 area='B',
                 start_time=mtdt(620),
                 end_time=END_OF_DAY))
    plan.fix_location_consistency()
    assert plan[1].start_location.area == 'A'
    assert plan[1].end_location.area == 'B'
Example #13
0
def Timmy():
    Timmy = Person(3, attributes={'age': 18, 'job': 'education', 'gender': 'male'})
    Timmy.add(Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(10 * 60)))
    Timmy.add(Leg(1, 'bike', 'a', 'b', start_time=mtdt(10 * 60), end_time=mtdt(11 * 60)))
    Timmy.add(Activity(2, 'education', 'b', start_time=mtdt(11 * 60), end_time=mtdt(13 * 60)))
    Timmy.add(Leg(2, 'bike', 'b', 'c', start_time=mtdt(13 * 60), end_time=mtdt(13 * 60 + 5)))
    Timmy.add(Activity(3, 'shop', 'c', start_time=mtdt(13 * 60 + 5), end_time=mtdt(13 * 60 + 30)))
    Timmy.add(Leg(3, 'bike', 'c', 'b', start_time=mtdt(13 * 60 + 30), end_time=mtdt(13 * 60 + 35)))
    Timmy.add(Activity(4, 'education', 'b', start_time=mtdt(13 * 60 + 35), end_time=mtdt(15 * 60)))
    Timmy.add(Leg(4, 'bike', 'b', 'd', start_time=mtdt(15 * 60), end_time=mtdt(15 * 60 + 10)))
    Timmy.add(Activity(5, 'leisure', 'd', start_time=mtdt(15 * 60 + 10), end_time=mtdt(18 * 60)))
    Timmy.add(Leg(5, 'bike', 'd', 'a', start_time=mtdt(18 * 60), end_time=mtdt(18 * 60 + 20)))
    Timmy.add(Activity(6, 'home', 'a', start_time=mtdt(18 * 60 + 20), end_time=END_OF_DAY))
    return Timmy
Example #14
0
def Hilda():
    Hilda = Person(2, attributes={'age': 45, 'job': 'influencer', 'gender': 'female'})
    Hilda.add(Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Hilda.add(Leg(1, 'walk', 'a', 'b', start_time=mtdt(8 * 60), end_time=mtdt(8 * 60 + 5)))
    Hilda.add(Activity(2, 'escort', 'b', start_time=mtdt(8 * 60 + 5), end_time=mtdt(8 * 60 + 30)))
    Hilda.add(Leg(1, 'pt', 'a', 'b', start_time=mtdt(8 * 60), end_time=mtdt(8 * 60 + 30)))
    Hilda.add(Activity(2, 'shop', 'b', start_time=mtdt(8 * 60 + 30), end_time=mtdt(14 * 60)))
    Hilda.add(Leg(2, 'pt', 'b', 'c', start_time=mtdt(14 * 60), end_time=mtdt(14 * 60 + 20)))
    Hilda.add(Activity(3, 'leisure', 'c', start_time=mtdt(14 * 60 + 20), end_time=mtdt(16 * 60 - 20)))
    Hilda.add(Leg(3, 'pt', 'c', 'b', start_time=mtdt(16 * 60 - 20), end_time=mtdt(16 * 60)))
    Hilda.add(Activity(2, 'escort', 'b', start_time=mtdt(16 * 60), end_time=mtdt(16 * 60 + 30)))
    Hilda.add(Leg(1, 'walk', 'a', 'b', start_time=mtdt(16 * 60 + 30), end_time=mtdt(16 * 60 + 5)))
    Hilda.add(Activity(5, 'home', 'a', start_time=mtdt(16 * 60 + 5), end_time=END_OF_DAY))
    return Hilda
Example #15
0
def test_shared_activities_for_removal_finds_shared_activities(Betty, Bobber):
    hhld = instantiate_household_with([Betty, Bobber])
    act_1 = Activity(8,
                     'shop_2',
                     'b',
                     start_time=mtdt(19 * 60),
                     end_time=mtdt(19 * 60 + 50))
    act_2 = Activity(7,
                     'shop_1',
                     'b',
                     start_time=mtdt(18 * 60 + 20),
                     end_time=mtdt(18 * 60 + 50))

    shared_acts = modify.ReduceSharedActivity(
        ['shop_1', 'shop_2']).shared_activities_for_removal(hhld)

    assert shared_acts
    assert act_1.in_list_exact(shared_acts)
    assert act_2.in_list_exact(shared_acts)
Example #16
0
def test_is_activity_for_removal_activity_does_not_match_RemoveActivity_activities():
    activity = Activity(act = 'other_activity')
    policy_remove_activity = modify.RemoveActivity(['some_activity'], probability=0.5)

    assert not policy_remove_activity.is_activity_for_removal(activity)
Example #17
0
def test_home_work_home_education_home_removal_of_education_act():
    person = Person(1)
    person.add(
        Activity(
            seq=1,
            act='home',
            area='a',
            start_time=mtdt(0),
            end_time=mtdt(60)
        )
    )
    person.add(
        Leg(
            seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)
        )
    )
    person.add(
        Activity(
            seq=2,
            act='work',
            area='b',
            start_time=mtdt(90),
            end_time=mtdt(120)
        )
    )
    person.add(
        Leg(
            seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(120),
            end_time=mtdt(180)
        )
    )
    person.add(
        Activity(
            seq=3,
            act='home',
            area='a',
            start_time=mtdt(180),
            end_time=mtdt(300)
        )
    )
    person.add(
        Leg(
            seq=3,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(300),
            end_time=mtdt(390)
        )
    )
    person.add(
        Activity(
            seq=2,
            act='education',
            area='b',
            start_time=mtdt(390),
            end_time=mtdt(520)
        )
    )
    person.add(
        Leg(
            seq=2,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(520),
            end_time=mtdt(580)
        )
    )
    person.add(
        Activity(
            seq=3,
            act='home',
            area='a',
            start_time=mtdt(680),
            end_time=END_OF_DAY
        )
    )
    household = instantiate_household_with([person])
    assert_correct_activities(person=household.people['1'], ordered_activities_list=['home', 'work', 'home', 'education', 'home'])

    policy = modify.RemoveActivity(activities=['education'], probability=1)
    policy.apply_to(household)
    assert_correct_activities(person=household.people['1'], ordered_activities_list=['home', 'work', 'home'])
Example #18
0
def person_whshw():

    person = Person('1')
    person.add(
        Activity(seq=1,
                 act='work',
                 area='a',
                 start_time=mtdt(0),
                 end_time=mtdt(60)))
    person.add(
        Leg(seq=1,
            mode='car',
            start_area='a',
            end_area='b',
            start_time=mtdt(60),
            end_time=mtdt(90)))
    person.add(
        Activity(seq=2,
                 act='home',
                 area='b',
                 start_time=mtdt(90),
                 end_time=mtdt(120)))
    person.add(
        Leg(seq=2,
            mode='car',
            start_area='b',
            end_area='c',
            start_time=mtdt(120),
            end_time=mtdt(190)))
    person.add(
        Activity(seq=3,
                 act='shop',
                 area='c',
                 start_time=mtdt(190),
                 end_time=mtdt(220)))
    person.add(
        Leg(seq=3,
            mode='car',
            start_area='c',
            end_area='b',
            start_time=mtdt(220),
            end_time=mtdt(280)))
    person.add(
        Activity(seq=4,
                 act='home',
                 area='b',
                 start_time=mtdt(280),
                 end_time=mtdt(320)))
    person.add(
        Leg(seq=4,
            mode='car',
            start_area='b',
            end_area='a',
            start_time=mtdt(320),
            end_time=mtdt(380)))
    person.add(
        Activity(seq=5,
                 act='work',
                 area='a',
                 start_time=mtdt(380),
                 end_time=END_OF_DAY))

    return person
Example #19
0
def test_is_activity_for_removal_activity_matches_RemoveActivity_activities():
    activity = Activity(act='some_activity')
    policy_remove_activity = modify.RemoveActivity(['some_activity'])

    assert policy_remove_activity.is_activity_for_removal(activity)
Example #20
0
def test_person_add_activity():
    plan = Plan()
    act = Activity(1, 'home', 1)
    plan.add(act)
    assert len(plan.day) == 1
Example #21
0
def test_person_not_closed_plan_different_acts():
    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))
    assert not person.closed_plan
Example #22
0
def test_activity_not_equal_areas():
    assert not Activity(1, 'work', 2) == Activity(3, 'work', 1)
Example #23
0
def test_is_activity_for_removal_activity_does_not_match_ReduceSharedActivity_activities(
):
    activity = Activity(act='other_activity')
    policy_remove_activity = modify.ReduceSharedActivity(['some_activity'])

    assert not policy_remove_activity.is_activity_for_removal(activity)
Example #24
0
def Bobber():
    Bobber = Person('Bobber',
                    attributes={
                        'age': 6,
                        'job': 'education',
                        'gender': 'male',
                        'key_worker': False
                    })
    Bobber.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Bobber.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Bobber.add(
        Activity(2,
                 'education',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(16 * 60)))
    Bobber.add(
        Leg(2,
            'walk',
            'b',
            'c',
            start_time=mtdt(16 * 60),
            end_time=mtdt(16 * 60 + 30)))
    Bobber.add(
        Activity(3,
                 'home',
                 'a',
                 start_time=mtdt(16 * 60 + 30),
                 end_time=mtdt(18 * 60)))
    Bobber.add(
        Leg(3,
            'car',
            'a',
            'b',
            start_time=mtdt(18 * 60),
            end_time=mtdt(18 * 60 + 20)))
    Bobber.add(
        Activity(4,
                 'shop_1',
                 'b',
                 start_time=mtdt(18 * 60 + 20),
                 end_time=mtdt(18 * 60 + 50)))
    Bobber.add(
        Leg(4,
            'walk',
            'b',
            'b',
            start_time=mtdt(18 * 60 + 50),
            end_time=mtdt(19 * 60)))
    Bobber.add(
        Activity(5,
                 'shop_2',
                 'b',
                 start_time=mtdt(19 * 60),
                 end_time=mtdt(19 * 60 + 50)))
    Bobber.add(
        Leg(5,
            'car',
            'b',
            'a',
            start_time=mtdt(19 * 60 + 50),
            end_time=mtdt(20 * 60 + 10)))
    Bobber.add(
        Activity(6,
                 'home',
                 'a',
                 start_time=mtdt(20 * 60 + 10),
                 end_time=END_OF_DAY))
    return Bobber
Example #25
0
def test_act_init():
    act = Activity()
    assert act.act is None
Example #26
0
def test_shift_end_time():
    act = Activity(1, 'home', 1, start_time=mtdt(900), end_time=mtdt(930))
    assert act.shift_end_time(new_end_time=mtdt(920)) == mtdt(890)
Example #27
0
def test_person_add_activity():
    person = Person('1')
    act = Activity(1, 'home', 1)
    person.add(act)
    assert len(person.plan) == 1
Example #28
0
def Betty():
    Betty = Person('Betty',
                   attributes={
                       'age': 40,
                       'job': 'work',
                       'gender': 'female',
                       'key_worker': True
                   })
    Betty.add(
        Activity(1, 'home', 'a', start_time=mtdt(0), end_time=mtdt(8 * 60)))
    Betty.add(
        Leg(1,
            'walk',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 5)))
    Betty.add(
        Activity(2,
                 'escort',
                 'b',
                 start_time=mtdt(8 * 60 + 5),
                 end_time=mtdt(8 * 60 + 30)))
    Betty.add(
        Leg(2,
            'pt',
            'a',
            'b',
            start_time=mtdt(8 * 60),
            end_time=mtdt(8 * 60 + 30)))
    Betty.add(
        Activity(3,
                 'work',
                 'b',
                 start_time=mtdt(8 * 60 + 30),
                 end_time=mtdt(14 * 60)))
    Betty.add(
        Leg(3,
            'pt',
            'b',
            'c',
            start_time=mtdt(14 * 60),
            end_time=mtdt(14 * 60 + 20)))
    Betty.add(
        Activity(4,
                 'leisure',
                 'c',
                 start_time=mtdt(14 * 60 + 20),
                 end_time=mtdt(16 * 60 - 20)))
    Betty.add(
        Leg(4,
            'pt',
            'c',
            'b',
            start_time=mtdt(16 * 60 - 20),
            end_time=mtdt(16 * 60)))
    Betty.add(
        Activity(5,
                 'escort',
                 'b',
                 start_time=mtdt(16 * 60),
                 end_time=mtdt(16 * 60 + 30)))
    Betty.add(
        Leg(5,
            'walk',
            'a',
            'b',
            start_time=mtdt(16 * 60 + 30),
            end_time=mtdt(17 * 60)))
    Betty.add(
        Activity(6,
                 'home',
                 'a',
                 start_time=mtdt(17 * 60),
                 end_time=mtdt(18 * 60)))
    Betty.add(
        Leg(6,
            'car',
            'a',
            'b',
            start_time=mtdt(18 * 60),
            end_time=mtdt(18 * 60 + 20)))
    Betty.add(
        Activity(7,
                 'shop_1',
                 'b',
                 start_time=mtdt(18 * 60 + 20),
                 end_time=mtdt(18 * 60 + 50)))
    Betty.add(
        Leg(7,
            'walk',
            'b',
            'b',
            start_time=mtdt(18 * 60 + 50),
            end_time=mtdt(19 * 60)))
    Betty.add(
        Activity(8,
                 'shop_2',
                 'b',
                 start_time=mtdt(19 * 60),
                 end_time=mtdt(19 * 60 + 50)))
    Betty.add(
        Leg(8,
            'car',
            'b',
            'a',
            start_time=mtdt(19 * 60 + 50),
            end_time=mtdt(20 * 60 + 10)))
    Betty.add(
        Activity(9,
                 'home',
                 'a',
                 start_time=mtdt(20 * 60 + 10),
                 end_time=END_OF_DAY))
    return Betty
Example #29
0
def test_activity_not_equal_acts():
    assert not Activity(1, 'home', 2) == Activity(3, 'work', 2)
Example #30
0
def test_activity_equal():
    assert Activity(1, 'work', 1) == Activity(3, 'work', 1)