Exemplo n.º 1
0
 def test__quarantine_zero_complacency(self, setup_policy_world, selector):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     quarantine = Quarantine(
         start_time="2020-1-1",
         end_time="2020-1-30",
         n_days=7,
         n_days_household=14,
         household_compliance=0.0,
     )
     policies = Policies([quarantine])
     sim.activity_manager.policies = policies
     infect_person(worker, selector, "mild")
     sim.update_health_status(0.0, 0.0)
     activities = ["primary_activity", "residence"]
     sim.clear_world()
     time_during_policy = datetime(2020, 1, 2)
     individual_policies = IndividualPolicies.get_active_policies(
         policies, date=time_during_policy)
     # before symptoms onset
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=4.0)
     # after symptoms onset
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=8.0)
     # more thatn two weeks after symptoms onset
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=25)
     worker.health_information = None
     sim.clear_world()
Exemplo n.º 2
0
    def move_people_to_active_subgroups(
        self,
        activities: List[str],
        date: datetime = datetime(2020, 2, 2),
        days_from_start=0,
    ):
        """
        Sends every person to one subgroup. If a person has a mild illness,
        they stay at home

        Parameters
        ----------

        """
        individual_policies = IndividualPolicies.get_active_policies(
            policies=self.policies, date=date
        )
        activities = self.apply_activity_hierarchy(activities)
        for person in self.world.people.members:
            if person.dead or person.busy:
                continue
            allowed_activities = individual_policies.apply(
                person=person, activities=activities, days_from_start=days_from_start,
            )
            self.move_to_active_subgroup(allowed_activities, person)
Exemplo n.º 3
0
 def test__housemates_stay_for_two_weeks(self, setup_policy_world,
                                         selector):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     quarantine = Quarantine(
         start_time="2020-1-1",
         end_time="2020-1-30",
         n_days=7,
         n_days_household=14,
     )
     policies = Policies([quarantine])
     sim.activity_manager.policies = policies
     infect_person(worker, selector, "mild")
     sim.update_health_status(0.0, 0.0)
     activities = ["primary_activity", "residence"]
     sim.clear_world()
     time_during_policy = datetime(2020, 1, 2)
     # before symptoms onset
     individual_policies = IndividualPolicies.get_active_policies(
         policies, date=time_during_policy)
     assert "primary_activity" not in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=8.0)
     # after symptoms onset
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_during_policy, 8.0)
     assert pupil in pupil.residence.people
     # more thatn two weeks after symptoms onset
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=25)
     worker.health_information = None
     sim.clear_world()
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_during_policy, 25)
     assert pupil in pupil.primary_activity.people
     sim.clear_world()
Exemplo n.º 4
0
 def test__housemates_of_asymptomatic_are_free(self, setup_policy_world,
                                               selector):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     quarantine = Quarantine(
         start_time="2020-1-1",
         end_time="2020-1-30",
         n_days=7,
         n_days_household=14,
     )
     policies = Policies([quarantine])
     sim.activity_manager.policies = policies
     infect_person(worker, selector, "asymptomatic")
     sim.update_health_status(0.0, 0.0)
     activities = ["primary_activity", "residence"]
     sim.clear_world()
     time_during_policy = datetime(2020, 1, 2)
     # after symptoms onset
     individual_policies = IndividualPolicies.get_active_policies(
         policies, date=time_during_policy)
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=8.0)
     assert "primary_activity" in individual_policies.apply(
         person=pupil, activities=activities, days_from_start=25.0)
     worker.health_information = None
     sim.clear_world()
Exemplo n.º 5
0
 def test__close_universities(self, setup_policy_world):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     university_closure = CloseUniversities(
         start_time="2020-1-1",
         end_time="2020-10-1",
     )
     policies = Policies([university_closure])
     sim.activity_manager.policies = policies
     sim.clear_world()
     activities = ["primary_activity", "residence"]
     time_before_policy = datetime(2019, 2, 1)
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_before_policy)
     assert student in student.primary_activity.people
     assert pupil in pupil.primary_activity.people
     sim.clear_world()
     time_during_policy = datetime(2020, 2, 1)
     individual_policies = IndividualPolicies.get_active_policies(
         policies=policies, date=time_during_policy)
     assert individual_policies.apply(person=student,
                                      activities=activities,
                                      days_from_start=0) == [
                                          "residence",
                                      ]
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_during_policy)
     assert student in student.residence.people
     sim.clear_world()
     time_after_policy = datetime(2030, 2, 2)
     individual_policies = IndividualPolicies.get_active_policies(
         policies=policies, date=time_after_policy)
     assert individual_policies.apply(person=student,
                                      activities=activities,
                                      days_from_start=0) == [
                                          "primary_activity", "residence"
                                      ]
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_after_policy)
     assert pupil in pupil.primary_activity.people
     assert student in student.primary_activity.people
     sim.clear_world()
Exemplo n.º 6
0
    def __init__(self, policies=None):
        self.policies = policies
        # Note (Arnau): This import here is ugly, but I couldn't
        # find a way to get around a redundant import loop.
        from june.policy import (
            IndividualPolicies,
            InteractionPolicies,
            MedicalCarePolicies,
            LeisurePolicies,
            RegionalCompliances,
            TieredLockdowns
        )

        self.individual_policies = IndividualPolicies.from_policies(self)
        self.interaction_policies = InteractionPolicies.from_policies(self)
        self.medical_care_policies = MedicalCarePolicies.from_policies(self)
        self.leisure_policies = LeisurePolicies.from_policies(self)
        self.regional_compliance = RegionalCompliances.from_policies(self)
        self.tiered_lockdown = TieredLockdowns.from_policies(self)
Exemplo n.º 7
0
    def test__old_people_shield_with_compliance(self, setup_policy_world):
        world, pupil, student, worker, _ = setup_policy_world
        super_area = world.super_areas[0]
        shielding = Shielding(start_time="2020-1-1",
                              end_time="2020-10-1",
                              min_age=30,
                              compliance=0.6)
        policies = Policies([shielding])
        activities = ["primary_activity", "residence"]
        time_during_policy = datetime(2020, 2, 1)
        individual_policies = IndividualPolicies.get_active_policies(
            policies, date=time_during_policy)
        compliant_days = 0
        for i in range(100):
            if "primary_activity" not in individual_policies.apply(
                    person=worker, activities=activities, days_from_start=0):
                compliant_days += 1

        assert compliant_days / 100 == pytest.approx(shielding.compliance,
                                                     abs=0.1)
Exemplo n.º 8
0
 def test__old_people_shield(self, setup_policy_world):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     shielding = Shielding(start_time="2020-1-1",
                           end_time="2020-10-1",
                           min_age=30)
     policies = Policies([shielding])
     sim.activity_manager.policies = policies
     activities = ["primary_activity", "residence"]
     sim.clear_world()
     time_during_policy = datetime(2020, 2, 1)
     individual_policies = IndividualPolicies.get_active_policies(
         policies, date=time_during_policy)
     assert "primary_activity" not in individual_policies.apply(
         person=worker, activities=activities, days_from_start=0)
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_during_policy)
     assert worker in worker.residence.people
     assert pupil in pupil.primary_activity.people
     sim.clear_world()
Exemplo n.º 9
0
 def test__close_companies_full_closure(self, setup_policy_world):
     world, pupil, student, worker, sim = setup_policy_world
     super_area = world.super_areas[0]
     company_closure = CloseCompanies(
         start_time="2020-1-1",
         end_time="2020-10-1",
         full_closure=True,
     )
     policies = Policies([company_closure])
     sim.activity_manager.policies = policies
     worker.lockdown_status = "key_worker"
     activities = ["commute", "primary_activity", "residence"]
     sim.clear_world()
     time_during_policy = datetime(2020, 2, 1)
     individual_policies = IndividualPolicies.get_active_policies(
         policies, date=time_during_policy)
     assert individual_policies.apply(person=worker,
                                      activities=activities,
                                      days_from_start=0) == ["residence"]
     sim.activity_manager.move_people_to_active_subgroups(
         activities, time_during_policy)
     assert worker in worker.residence.people
     sim.clear_world()
Exemplo n.º 10
0
    def test__close_companies_frequency_of_randoms(self, setup_policy_world):
        world, pupil, student, worker, sim = setup_policy_world
        super_area = world.super_areas[0]
        company_closure = CloseCompanies(
            start_time="2020-1-1",
            end_time="2020-10-1",
            random_work_probability=0.2
            # go for 8 hours per week (one week has 168 hours)
        )
        policies = Policies([company_closure])
        sim.activity_manager.policies = policies
        sim.clear_world()
        activities = ["commute", "primary_activity", "residence"]
        time_before_policy = datetime(2019, 2, 1)
        worker.lockdown_status = "random"
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_before_policy)
        assert worker in worker.primary_activity.people
        assert pupil in pupil.primary_activity.people
        sim.clear_world()
        time_during_policy = datetime(2020, 2, 1)
        individual_policies = IndividualPolicies.get_active_policies(
            policies, date=time_during_policy)
        # Move the person 1_0000 times for five days
        n_days_in_week = []
        for i in range(500):
            n_days = 0
            for j in range(5):
                if "primary_activity" in individual_policies.apply(
                        person=worker, activities=activities,
                        days_from_start=0):
                    n_days += 1.0
            n_days_in_week.append(n_days)
        assert np.isclose(np.mean(n_days_in_week), 1.1, atol=0.1)
        n_days_in_week = []
        for i in range(500):
            n_days = 0
            for j in range(10):
                if "primary_activity" in individual_policies.apply(
                        person=worker, activities=activities,
                        days_from_start=0):
                    n_days += 0.5
            n_days_in_week.append(n_days)
        assert np.mean(n_days_in_week) == pytest.approx(1.0, rel=0.1)

        sim.clear_world()
        time_after_policy = datetime(2030, 2, 2)
        individual_policies = IndividualPolicies.get_active_policies(
            policies, date=time_after_policy)
        assert individual_policies.apply(person=worker,
                                         activities=activities,
                                         days_from_start=0) == [
                                             "commute",
                                             "primary_activity",
                                             "residence",
                                         ]
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_after_policy)
        assert pupil in pupil.primary_activity.people
        assert worker in worker.primary_activity.people
        sim.clear_world()
Exemplo n.º 11
0
    def test__close_schools(self, setup_policy_world):
        world, pupil, student, worker, sim = setup_policy_world
        super_area = world.super_areas[0]
        school_closure = CloseSchools(
            start_time="2020-1-1",
            end_time="2020-10-1",
            years_to_close=[6],
        )
        policies = Policies([school_closure])
        sim.activity_manager.policies = policies

        # non key worker
        worker.lockdown_status = "furlough"
        sim.clear_world()
        activities = ["primary_activity", "residence"]
        time_before_policy = datetime(2019, 2, 1)
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_before_policy)
        assert worker in worker.primary_activity.people
        assert pupil in pupil.primary_activity.people
        sim.clear_world()
        time_during_policy = datetime(2020, 2, 1)
        individual_policies = IndividualPolicies.get_active_policies(
            policies, date=time_during_policy)
        assert individual_policies.apply(person=pupil,
                                         activities=activities,
                                         days_from_start=0) == [
                                             "residence",
                                         ]
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_during_policy)
        assert pupil in pupil.residence.people
        assert worker in worker.primary_activity.people
        sim.clear_world()
        time_after_policy = datetime(2030, 2, 2)
        individual_policies = IndividualPolicies.get_active_policies(
            policies, date=time_after_policy)
        assert individual_policies.apply(person=pupil,
                                         activities=activities,
                                         days_from_start=0) == [
                                             "primary_activity",
                                             "residence",
                                         ]
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_after_policy)
        assert pupil in pupil.primary_activity.people
        assert worker in worker.primary_activity.people
        sim.clear_world()

        # key worker
        worker.lockdown_status = "key_worker"
        student.lockdown_status = "key_worker"
        sim.clear_world()
        activities = ["primary_activity", "residence"]
        time_before_policy = datetime(2019, 2, 1)
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_before_policy)
        assert worker in worker.primary_activity.people
        assert pupil in pupil.primary_activity.people
        sim.clear_world()
        time_during_policy = datetime(2020, 2, 1)
        individual_policies = IndividualPolicies.get_active_policies(
            policies=policies, date=time_during_policy)
        assert individual_policies.apply(person=pupil,
                                         activities=activities,
                                         days_from_start=0) == [
                                             "primary_activity",
                                             "residence",
                                         ]
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_during_policy)
        assert pupil in pupil.primary_activity.people
        assert worker in worker.primary_activity.people
        sim.clear_world()
        time_after_policy = datetime(2030, 2, 2)
        individual_policies = IndividualPolicies.get_active_policies(
            policies=policies, date=time_after_policy)
        assert individual_policies.apply(person=pupil,
                                         activities=activities,
                                         days_from_start=0) == [
                                             "primary_activity",
                                             "residence",
                                         ]
        sim.activity_manager.move_people_to_active_subgroups(
            activities, time_after_policy)
        assert pupil in pupil.primary_activity.people
        assert worker in worker.primary_activity.people
        sim.clear_world()