Esempio n. 1
0
def test_attribute_based_remove_activity_policy_does_not_remove_matching_activities_from_non_strictly_irrelevant_people(
        home_education_home_university_student):
    household = instantiate_household_with(
        [home_education_home_university_student])

    def age_condition_under_0(attribute_value):
        return attribute_value < 0

    def job_condition_wasevrrr(attribute_value):
        return attribute_value == 'wasevrrr'

    assert_correct_activities(
        person=household.people['1'],
        ordered_activities_list=['home', 'education', 'home'])
    assert not age_condition_under_0(household.people['1'].attributes['age'])
    assert not job_condition_wasevrrr(household.people['1'].attributes['job'])

    policy_remove_higher_education = policies.ActivityPolicy(
        modifiers.RemoveActivity(['education']),
        probability_samplers.ActivityProbability(['education'], 1),
        filters.PersonAttributeFilter(conditions={
            'age': age_condition_under_0,
            'job': job_condition_wasevrrr
        },
                                      how='any'))

    policy_remove_higher_education.apply_to(household)

    assert_correct_activities(
        person=household.people['1'],
        ordered_activities_list=['home', 'education', 'home'])
Esempio n. 2
0
def test_attribute_based_remove_activity_policy_removes_all_matching_activities_from_strictly_relevant_people(
        home_education_home_university_student):
    household = instantiate_household_with(
        [home_education_home_university_student])

    def age_condition_over_17(attribute_value):
        return attribute_value > 17

    def job_condition_education(attribute_value):
        return attribute_value == 'education'

    assert_correct_activities(
        person=household.people[1],
        ordered_activities_list=['home', 'education', 'home'])
    assert age_condition_over_17(household.people[1].attributes['age'])
    assert job_condition_education(household.people[1].attributes['job'])

    policy_remove_higher_education = policies.ActivityPolicy(
        modifiers.RemoveActivity(['education']),
        probability_samplers.ActivityProbability(['education'], 1),
        filters.PersonAttributeFilter(conditions={
            'age': age_condition_over_17,
            'job': job_condition_education
        },
                                      how='all'))

    policy_remove_higher_education.apply_to(household)
    assert_correct_activities(person=household.people[1],
                              ordered_activities_list=['home'])
Esempio n. 3
0
 def __init__(self,
              modifier: modifiers.Modifier,
              attribute_filter: filters.Filter = None):
     super().__init__()
     assert isinstance(
         modifier,
         modifiers.Modifier), 'modifier needs to be subclass of {}'.format(
             type(modifiers.Modifier()))
     self.modifier = modifier
     if attribute_filter is None:
         self.attribute_filter = filters.PersonAttributeFilter({})
     else:
         self.attribute_filter = attribute_filter