def test_get_uids_in_school(location='seattle_metro', state_location='Washington', country_location='usa', folder_name='contact_networks'): Npeople = 10000 homes = sprw.read_setting_groups(datadir, location, state_location, country_location, folder_name, 'households', Npeople, with_ages=True) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes) uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school( datadir, Npeople, location, state_location, country_location, age_by_uid_dic, homes_by_uids, use_default=False) assert uids_in_school is not None
def test_get_uids_potential_workers(location='seattle_metro', state_location='Washington', country_location='usa'): n = 10000 homes = sp.get_head_age_by_size_distr(datadir, state_location, country_location, file_path=None, household_size_1_included=False, use_default=True) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes, id_len=16) uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school( datadir, n, location, state_location, country_location, age_by_uid_dic, homes_by_uids, use_default=False) employment_rates = sp.get_employment_rates( datadir, location=location, state_location=state_location, country_location=country_location, use_default=True) potential_worker_uids, potential_worker_uids_by_age, potential_worker_ages_left_count = sp.get_uids_potential_workers( uids_in_school, employment_rates, age_by_uid_dic) assert potential_worker_ages_left_count is not None return potential_worker_uids, potential_worker_uids_by_age, employment_rates, age_by_uid_dic
def test_assign_uids_by_homes(state_location='Washington', country_location='usa'): homes = sp.get_head_age_by_size_distr(datadir, state_location, country_location, file_path=None, household_size_1_included=False, use_default=True) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes, id_len=16) assert homes_by_uids, age_by_uid_dic is not None
def test_send_students_to_school(n=10000, location='seattle_metro', state_location='Washington', country_location='usa', folder_name='contact_networks'): homes = sprw.read_setting_groups(datadir, location, state_location, country_location, folder_name, 'households', n, with_ages=True) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes) uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school( datadir, n, location, state_location, country_location, age_by_uid_dic, homes_by_uids, use_default=False) school_size_distr_by_bracket = sp.get_school_size_distr_by_brackets( datadir, location, state_location, country_location) school_size_brackets = sp.get_school_size_brackets(datadir, location, state_location, country_location) school_sizes = sp.generate_school_sizes(school_size_distr_by_bracket, school_size_brackets, uids_in_school) age_brackets_filepath = sp.get_census_age_brackets_path( datadir, state_location, country_location) age_brackets = sp.get_age_brackets_from_df(age_brackets_filepath) age_by_brackets_dic = sp.get_age_by_brackets_dic(age_brackets) contact_matrix_dic = sp.get_contact_matrix_dic( datadir, sheet_name='United States of America') syn_schools, syn_school_uids, syn_school_types = sp.send_students_to_school( school_sizes, uids_in_school, uids_in_school_by_age, ages_in_school_count, age_brackets, age_by_brackets_dic, contact_matrix_dic, verbose=False) assert syn_schools, syn_school_uids is not None return syn_schools, syn_school_uids
def test_send_students_to_school(n=10000, location='seattle_metro', state_location='Washington', country_location='usa', folder_name='contact_networks'): homes = sp.read_setting_groups(datadir, location, state_location, country_location, 'households', folder_name, n, with_ages=True) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes) uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school(datadir, n, location, state_location, country_location, age_by_uid_dic, homes_by_uids, use_default=False) # assert uids_in_school is not None # def test_send_students_to_school(n=1000, location='seattle_metro', state_location='Washington', # country_location='usa'): # homes = sp.get_head_age_by_size_distr(datadir, state_location, country_location, file_path=None, # household_size_1_included=False, use_default=True) # homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes, id_len=16) # uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school(datadir, n, location, # state_location, # country_location, # age_by_uid_dic, # homes_by_uids, # use_default=False) # >>>>>>> origin/mf/update-saved-pop-fixes school_size_distr_by_bracket = sp.get_school_size_distr_by_brackets(datadir, location, state_location, country_location) school_size_brackets = sp.get_school_size_brackets(datadir, location, state_location, country_location) school_sizes = sp.generate_school_sizes(school_size_distr_by_bracket, school_size_brackets, uids_in_school) age_brackets_filepath = sp.get_census_age_brackets_path(datadir, state_location, country_location) age_brackets = sp.get_age_brackets_from_df(age_brackets_filepath) age_by_brackets_dic = sp.get_age_by_brackets_dic(age_brackets) contact_matrix_dic = sp.get_contact_matrix_dic(datadir, sheet_name='United States of America') syn_schools, syn_school_uids = sp.send_students_to_school(school_sizes, uids_in_school, uids_in_school_by_age, ages_in_school_count, age_brackets, age_by_brackets_dic, contact_matrix_dic, verbose=False) assert syn_schools, syn_school_uids is not None return syn_schools, syn_school_uids
use_bayesian) hha_by_size = sp.get_head_age_by_size_distr(datadir, country_location, use_bayesian) homes_dic, homes = sp.generate_all_households(hh_sizes, hha_by_size, hha_brackets, age_brackets, age_by_brackets_dic, contact_matrix_dic, syn_age_distr) c = 0 for s in homes_dic: c += s * len(homes_dic[s]) print('c', c) homes_by_uids, age_by_uid_dic = sp.assign_uids_by_homes(homes) new_ages_count = Counter(age_by_uid_dic.values()) print('a', len(age_by_uid_dic)) fig = plt.figure(figsize=(6, 4)) ax = fig.add_subplot(111) x = np.arange(100) y_exp = np.zeros(100) y_sim = np.zeros(100) for a in range(100): expected = int(syn_age_distr[a] * totalpop) # print(a, expected, new_ages_count[a], '%.2f' % (-1*(expected - new_ages_count[a])/float(expected) * 100 )) y_exp[a] = expected y_sim[a] = new_ages_count[a]