def test__care_home_visits_leisure_integration(world_visits, leisure): person1 = Person.from_attributes(sex="m", age=26) person2 = Person.from_attributes(sex="f", age=28) household = Household(type="family") household.add(person1) household.add(person2) person1.busy = False person2.busy = False for area in world_visits.areas: if area.care_home is not None: break person1.residence.group.relatives_in_care_homes = [area.care_home.residents[0]] person1.residence.group.social_venues = {"care_home_visits": [area.care_home]} assigned = False for _ in range(0, 100): subgroup = leisure.get_subgroup_for_person_and_housemates( person1 ) if subgroup is not None: assigned = True assert ( subgroup == area.care_home.subgroups[area.care_home.SubgroupType.visitors] ) assert subgroup.group == area.care_home assert assigned
def apply(self, person: Person, days_from_start: float, activities: List[str]): """ Applies all active individual policies to the person. Stay home policies are applied first, since if the person stays home we don't need to check for the others. IF a person is below 15 years old, then we look for a guardian to stay with that person at home. """ for policy in self.policies: if policy.policy_subtype == "stay_home": if policy.check_stay_home_condition(person, days_from_start): activities = policy.apply( person=person, days_from_start=days_from_start, activities=activities, ) if person.age < self.min_age_home_alone: # can't stay home alone possible_guardians = [ housemate for housemate in person.residence.group.people if housemate.age >= 18 ] if not possible_guardians: guardian = person.find_guardian() if guardian is not None: if guardian.busy: for subgroup in guardian.subgroups.iter(): if subgroup is not None and guardian in subgroup: subgroup.remove(guardian) break guardian.residence.append(guardian) return activities # if it stays at home we don't need to check the rest elif policy.policy_subtype == "skip_activity": if policy.check_skips_activity(person): activities = policy.apply(activities=activities) return activities
def test__symptoms_progression(self): selector = infect.InfectionSelector.from_file(transmission_config_path=paths.configs_path / 'defaults/transmission/TransmissionConstant.yaml') dummy = Person(sex='f', age=65) infection = selector.make_infection(person=dummy, time=0.1) fixed_severity = 0.97 infection.symptoms.max_severity = fixed_severity max_tag = infection.symptoms.max_tag() assert max_tag == june.infection.symptom_tag.SymptomTag.hospitalised infection.symptoms.trajectory = selector.trajectory_maker[max_tag] print(infection.symptoms.trajectory) assert infection.symptoms.trajectory == [ (0.0, june.infection.symptom_tag.SymptomTag.exposed), (pytest.approx(5, 2.5), june.infection.symptom_tag.SymptomTag.mild), (pytest.approx(5, rel=5), june.infection.symptom_tag.SymptomTag.hospitalised), (pytest.approx(13, rel=5), june.infection.symptom_tag.SymptomTag.mild), (pytest.approx(30, rel=5), june.infection.symptom_tag.SymptomTag.recovered), ] hospitalised_time = infection.symptoms.trajectory[2][0] infection.update_at_time(float(1.)) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.exposed infection.update_at_time(float(1.)) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.exposed infection.update_at_time(float(6.)) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.mild infection.update_at_time(hospitalised_time + 8.) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.hospitalised infection.update_at_time(float(40.)) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.mild infection.update_at_time(float(50.)) assert infection.symptoms.tag == june.infection.symptom_tag.SymptomTag.recovered
def missing_workforce_nr(self): """ Estimate missing workforce in simulated region. This will establish the number of workers recruited from the boundary. """ self.ADULT_THRESHOLD = self.world.config["people"]["adult_threshold"] self.OLD_THRESHOLD = self.world.config["people"]["old_threshold"] self._init_frequencies() for company in self.world.companies.members: # nr. of missing workforce # TODO companies shouldn always be completely full n_residents = (company.n_employees_max - company.n_employees) (sex_rnd_arr, nomis_bin_rnd_arr, age_rnd_arr) = self.init_random_variables(n_residents, company.industry) for i in range(n_residents): # create new person person = Person( self.world, (i + self.n_residents), 'boundary', company.msoa, age_rnd_arr[i], nomis_bin_rnd_arr[i], sex_rnd_arr[i], econ_index=0, mode_of_transport=None, ) person.industry = company.industry # Inform groups about new person self.people.append(person) self.world.people.members.append(person) company.people.append(person) idx = [ idx for idx, msoa in enumerate(self.world.msoareas.members) if msoa.name == company.msoa ][0] self.world.msoareas.members[idx].work_people.append(person) self.n_residents += n_residents
def test__substract_information_from_group(): hospital = Hospital(n_beds=None, n_icu_beds=None) person1 = Person.from_attributes() person2 = Person.from_attributes() person3 = Person.from_attributes() person4 = Person.from_attributes() infection_selector = InfectionSelector.from_file() hospital.add(person1, subgroup_type=0) hospital.add(person2, subgroup_type=0) hospital.add(person3, subgroup_type=1) hospital.add(person4, subgroup_type=2) infection_selector.infect_person_at_time(person1, 1) person1.health_information.update_health_status(5, 5) person3.susceptibility = 0.0 interactive_group = InteractiveGroup(hospital) assert len(interactive_group.infector_ids) == 1 assert interactive_group.infector_ids[0][0] == person1.id assert (interactive_group.transmission_probabilities[0] == person1.health_information.infection.transmission.probability) assert len(interactive_group.susceptible_ids) == 2 assert interactive_group.susceptible_ids[0][0] == person2.id assert interactive_group.susceptible_ids[1][0] == person4.id
def test__create_shelters(): shelter = Shelter() household = Household() person1 = Person.from_attributes() household.add(person1) shelter.add(household) assert len(shelter.subgroups) == 2 assert shelter.n_families == 1 assert shelter.n_households == 1 n_families_area = 100 shelters = Shelters.from_families_in_area(n_families_area, sharing_shelter_ratio=0.75) assert np.isclose( len(shelters), 0.75 * n_families_area / 2 + 0.25 * n_families_area, atol=1, rtol=0, )
def test__do_not_visit_dead_people(world_visits, leisure): # look for a person in carehome found = False for area in world_visits.areas: for person in area.people: if person.residence.group.spec == "care_home": found = True break assert found person2 = Person.from_attributes() household = Household(type="family") household.add(person2) household.relatives_in_care_homes = [person] person2.residence.group.social_venues = {"care_home_visits" : [person.residence.group[2]]} person.dead = True leisure.update_household_and_care_home_visits_targets([person2]) for _ in range(0, 100): care_home = leisure.get_subgroup_for_person_and_housemates(person2) assert care_home is None
def test__shelter_distributor(): n_families_area = 100 shelters = Shelters.from_families_in_area(n_families_area, sharing_shelter_ratio=0.75) households = [Household() for _ in range(n_families_area)] for household in households: for _ in range(3): person = Person.from_attributes() household.add(person) shelter_distributor = ShelterDistributor(sharing_shelter_ratio=0.75) shelter_distributor.distribute_people_in_shelters(shelters, households) shelter_one_household = 0 shelter_more_one_household = 0 empty_shelters = 0 for shelter in shelters: assert shelter.n_families <= 2 if shelter.n_families > 1: shelter_more_one_household += 1 elif shelter.n_families == 1: shelter_one_household += 1 else: empty_shelters += 1 assert np.isclose( shelter_one_household / len(shelters), 0.25 / (0.25 + 0.75 / 2), atol=0.02, rtol=0, ) assert np.isclose( shelter_more_one_household / len(shelters), 0.75 / 2 / (0.25 + 0.75 / 2), atol=0.02, rtol=0, ) assert empty_shelters == 0
def add(self, person: Person): self.people.append(person) person.area = self
def add_worker(self, person: Person): self.workers.append(person) person.work_super_area = self
def make_medic_old(): medic = Person.from_attributes(age=40) medic.sector = "Q" medic.sub_sector = "Hospital" return medic
def make_medic_young(): medic = Person.from_attributes(age=18) medic.sector = "Q" medic.sub_sector = "Hospital" return medic
def remove_worker(self, person: Person): self.workers.remove(person) person.work_super_area = None
def remove(self, person: Person): self.people.remove(person) person.busy = False
def append(self, person: Person): """ Add a person to this group """ self.people.append(person) person.busy = True
def test_group_types(self): group = Household() group.add(Person(), Household.SubgroupType.adults) assert group[Household.SubgroupType.adults].size == 1