def test__decide_person_goes_to_social_venue(social_venue_distributor): dt = 0.01 person = Person(age=40, sex="m") estimated_day_to_go_to_the_pub = 1 / 0.5 estimated_day_to_go_to_the_pub_weekend = 1 / ( 2 * 0.5) rest = get_days_until_pub(person, dt, False, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub, atol=0, rtol=0.2) rest = get_days_until_pub(person, dt, True, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub_weekend, atol=0, rtol=0.2) person = Person(age=68, sex="m") estimated_day_to_go_to_the_pub = 1 / 0.2 estimated_day_to_go_to_the_pub_weekend = 1 / ( 2 * 0.2) rest = get_days_until_pub(person, dt, False, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub, atol=0, rtol=0.1) rest = get_days_until_pub(person, dt, True, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub_weekend, atol=0, rtol=0.1) person = Person(age=20, sex="f") estimated_day_to_go_to_the_pub = 1 / 0.1 estimated_day_to_go_to_the_pub_weekend = 1 / ( 2 * 0.1) rest = get_days_until_pub(person, dt, False, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub, atol=0, rtol=0.1) rest = get_days_until_pub(person, dt, True, social_venue_distributor) assert np.isclose(rest, estimated_day_to_go_to_the_pub_weekend, atol=0, rtol=0.1)
def get_health_index_by_age_and_sex(self): health_dict = {"m": defaultdict(int), "f": defaultdict(int)} for sex in ("m", "f"): for age in np.arange(100): health_dict[sex][age] = self.health_index( Person(sex=sex, age=age)) return health_dict
def test__add_patient_release_patient(hospitals, health_info, selector): dummy_person = Person().from_attributes(age=80, sex='m') selector.infect_person_at_time(dummy_person, 0.0) dummy_person.health_information.infection.symptoms.tag = getattr( SymptomTag, health_info) assert dummy_person.medical_facility is None hospitals.members[0].add_as_patient(dummy_person) if health_info == "hospitalised": assert hospitals.members[0][ Hospital.SubgroupType.patients][0] == dummy_person elif health_info == "intensive_care": assert (hospitals.members[0][Hospital.SubgroupType.icu_patients][0] == dummy_person) assert dummy_person.medical_facility is not None hospitals.members[0].release_as_patient(dummy_person) assert dummy_person.medical_facility is None
def test__allocate_patient_release_patient(hospitals, health_info, selector): dummy_person = Person().from_attributes(age=80, sex='m') selector.infect_person_at_time(dummy_person, 0.0) dummy_person.area = MockArea(hospitals.members[-1].coordinates) assert dummy_person.medical_facility is None dummy_person.health_information.infection.symptoms.tag = getattr( SymptomTag, health_info) hospitals.allocate_patient(dummy_person) if health_info == "hospitalised": assert ( dummy_person in hospitals.members[-1][Hospital.SubgroupType.patients].people) elif health_info == "intensive_care": assert (dummy_person in hospitals.members[-1][ Hospital.SubgroupType.icu_patients].people) selected_hospital = dummy_person.medical_facility assert dummy_person.medical_facility is not None dummy_person.medical_facility.group.release_as_patient(dummy_person) assert dummy_person.medical_facility is None
def get_symptoms_rates_per_age_sex( self, ) -> dict: """ Computes the rates of ending up with certain SymptomTag for all ages and sex. Returns ------- dictionary with rates of symptoms (fate) as a function of age and sex """ symptoms_rates_dict = {"m": defaultdict(int), "f": defaultdict(int)} for sex in ("m", "f"): for age in np.arange(100): symptoms_rates_dict[sex][age] = np.diff( self.health_index_generator(Person(sex=sex, age=age)), prepend=0.0, append=1.0, ) # need np.diff because health index is cummulative return symptoms_rates_dict
def test_try_allocate_patient_to_full_hospital(hospitals, health_info, selector): dummy_person = Person().from_attributes(age=80, sex='m') selector.infect_person_at_time(dummy_person, 0.0) dummy_person.health_information.infection.symptoms.tag = getattr( SymptomTag, health_info) dummy_person.area = MockArea(hospitals.members[0].coordinates) for hospital in hospitals.members: for _ in range(int(hospital.n_beds)): hospital.add_as_patient(dummy_person) hospitals.allocate_patient(dummy_person) if health_info == 'hospitalised': assert len(dummy_person.medical_facility.people ) > dummy_person.medical_facility.group.n_beds elif health_info == 'intensive_care': assert len(dummy_person.medical_facility.people ) > dummy_person.medical_facility.group.n_icu_beds for hospital in hospitals.members: for _ in range(int(hospital.n_beds)): hospital.release_as_patient(dummy_person)
def create_person(): return Person(sex="m", age=44)
def test__filling_carehome(self, module_carehome): person = Person(sex="m", age=33) module_carehome.add(person, CareHome.SubgroupType.workers) assert bool(module_carehome.subgroups[0].people) is True
def __init__(self): super().__init__() person = Person() self.add(Person(), "box", self.SubgroupType.type1) person = Person() self.add(person, "box", self.SubgroupType.type2)