def test_createInfectedPersons3(): config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") Expected = -1 with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__),"..","src", paramsDataPath), override=True) kids = [random.randint(0,17) for i in range(5)] adults = [random.randint(19,40) for i in range(5)] ageList = kids + adults PersonList = list(map(Person, ageList)) env_arr = [] my_world = World( all_people = PersonList, all_environments=env_arr, generating_city_name = "test", generating_scale = 1) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.infect_random_set(num_infected = 0, infection_doc = "", per_to_immune = 0.5,Immune_compliance = 0,city_name = None,min_age=18,people_per_day =5) my_simulation.simulate_day() #assert events dictionary is not empty cnt_immune = 0 for person in my_world.all_people(): if person.get_disease_state() == DiseaseState.IMMUNE: cnt_immune = cnt_immune + 1 assert cnt_immune == 0
def test_createInfectedPersonsOredredASCENDING(): config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") Expected = -1 with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__),"..","src", paramsDataPath), override=True) kids = [0,4,8,12,16] adults = [25,29,33] ageList = kids + adults youngest = Person(21) Oldest = Person(37) PersonList = list(map(Person, ageList)) PersonList = PersonList + [youngest , Oldest] env_arr = [] my_world = World( all_people = PersonList, all_environments=env_arr, generating_city_name = "test", generating_scale = 1) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.infect_random_set(num_infected = 0, infection_doc = "", per_to_immune = 0.5,order= ORDER.ASCENDING,city_name = None,min_age=18,people_per_day =1) my_simulation.simulate_day() assert youngest.get_disease_state() == DiseaseState.IMMUNE #Can't check day by day lots of noise with seir times for _ in range(4): my_simulation.simulate_day() cnt_immune =0 for person in my_world.all_people(): if person.get_disease_state() == DiseaseState.IMMUNE: cnt_immune = cnt_immune + 1 assert cnt_immune <= 5
def test_createInfectedPersonsBestEffort2(): """ Test that when the population size is less then the amount of people that had been chosen to be infected, the simulation doesn't crash """ config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__),"..","src", paramsDataPath), override=True) ageList = [random.randint(19,40) for i in range(10)] PersonList = list(map(Person, ageList)) env_arr = [] my_world = World( all_people = PersonList, all_environments=env_arr, generating_city_name = "test", generating_scale = 1) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.infect_random_set(num_infected = 0, infection_doc = "", per_to_immune = 2,city_name = None,min_age=18,people_per_day =0) my_simulation.simulate_day() cnt_immune = 0 cnt_sick = 0 for person in my_world.all_people(): if person.get_disease_state() == DiseaseState.IMMUNE: cnt_immune += 1 else: cnt_sick += 1 assert cnt_immune == 10 assert cnt_sick == 0
def test_CreateDeltaFileAtlit(helpers): helpers.clean_outputs() config_path = os.path.join(os.path.dirname(__file__), "..", "src", "config.json") with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) citiesDataPath = ConfigData['CitiesFilePath'] paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__), "..", "src", paramsDataPath), override=True) Params.loader()["person"]["state_macine_type"] = "SIR" DiseaseState.init_infectiousness_list() pop = population_loader.PopulationLoader(citiesDataPath) my_world = pop.get_world(city_name='Atlit', scale=1, is_smart=False) sim = Simulation(world=my_world, initial_date=INITIAL_DATE) sim.infect_random_set(num_infected=500, infection_doc="") sim.run_simulation(num_days=180, name="test") #assert events dictionary is not empty txt = sim.stats.get_state_stratified_summary_table( table_format=TableFormat.CSV) test_data = StringIO(txt) tbl = pd.read_csv(test_data) cnt_start = tbl.iloc[0, DiseaseState.SUSCEPTIBLE.value] + tbl.iloc[ 0, DiseaseState.LATENT.value] cnt_end = 0 for i in range(len(tbl)): cnt_end = cnt_end + tbl.iloc[i, DiseaseState.IMMUNE.value] + tbl.iloc[ i, DiseaseState.DECEASED.value] plug_number = len([ p for p in sim._world.all_people() if p.get_disease_state() == DiseaseState.SUSCEPTIBLE ]) assert cnt_start >= cnt_end + plug_number