def test_Init_haifa():
    file_path = os.path.dirname(__file__) + "/../src/config.json"
    with open(file_path) as json_data_file:
        ConfigData = json.load(json_data_file)
        citiesDataPath = ConfigData['CitiesFilePath']
    pop = population_loader.PopulationLoader(citiesDataPath)
    City1 = pop.get_city_by_name('Haifa')
    assert City1 is not None
def test_Init_TownNotExist():
    file_path = os.path.dirname(__file__) + "/../src/config.json"
    with open(file_path) as json_data_file:
        ConfigData = json.load(json_data_file)
        citiesDataPath = ConfigData['CitiesFilePath']
    with pytest.raises(Exception):
        pop = population_loader.PopulationLoader(citiesDataPath)
        City1 = pop.get_city_by_name('lala')
def test_Init_haifa():
    citiesDataPath = ""
    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__), paramsDataPath),
                     override=True)

    pop = population_loader.PopulationLoader(citiesDataPath,
                                             added_description="",
                                             with_caching=False,
                                             verbosity=False)
    world = pop.get_world(city_name='Haifa', scale=1, is_smart=False)
    assert world is not None
def test_Init_haifaParms():
    citiesDataPath = ""
    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__), paramsDataPath),
                     override=True)

    pop = population_loader.PopulationLoader(citiesDataPath,
                                             added_description="",
                                             with_caching=False,
                                             verbosity=False)
    City1 = pop.get_city_by_name('Haifa')
    assert City1.region == 3
    assert City1.nafa == 31
def test_neiborhoods_diff_IDs():
    '''
    Test different neiborhood get different ids
    '''
    file_path = os.path.dirname(__file__) + "/../src/config.json"
    with open(file_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__), paramsDataPath),
                     override=True)
    pop = population_loader.PopulationLoader(citiesDataPath)
    my_world = pop.get_world(city_name='Atlit', scale=1, is_smart=True)

    sample = []
    for env in my_world.all_environments:
        if env.name == "neighborhood_community":
            sample.append(env)
    assert not (sample[0].get_neighborhood_id()
                == sample[1].get_neighborhood_id())
Example #6
0
def test_CityGeneration():
    file_path = os.path.dirname(__file__) + "/../src/config.json"
    with open(file_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__), paramsDataPath),
                     override=True)
    pop = population_loader.PopulationLoader(citiesDataPath)
    tmp_city = pop.get_city_by_name('Haifa')
    city = generate_city(tmp_city,
                         True,
                         internal_workplaces=True,
                         scaling=1.0,
                         verbosity=False,
                         to_world=True)

    humans = city.all_people()
    assert abs(283637 - len(humans)) < 5
    assert len(city.get_all_city_communities()) == 1
    assert city.get_person_from_id(humans[0]._id) is not None
Example #7
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