コード例 #1
0
def test_assign_teachers_to_work(location='seattle_metro',
                                 state_location='Washington',
                                 country_location='usa',
                                 folder_name='contact_networks',
                                 n=10000):
    # Assign students to school
    gen_schools, gen_school_uids = test_send_students_to_school()

    employment_rates = sp.get_employment_rates(
        datadir,
        location=location,
        state_location=state_location,
        country_location=country_location,
        use_default=True)

    age_by_uid_dic = sp.read_in_age_by_uid(datadir, location, state_location,
                                           country_location, folder_name, n)

    uids_in_school = sp.get_uids_in_school(datadir,
                                           n,
                                           location,
                                           state_location,
                                           country_location,
                                           folder_name=folder_name,
                                           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)

    workers_by_age_to_assign_count = sp.get_workers_by_age_to_assign(
        employment_rates, potential_worker_ages_left_count, age_by_uid_dic)

    # Assign teachers and update school lists
    syn_schools, syn_school_uids, potential_worker_uids, potential_worker_uids_by_age, \
    workers_by_age_to_assign_count = sp.assign_teachers_to_work(gen_schools, gen_school_uids, employment_rates,
                                                                workers_by_age_to_assign_count,
                                                                potential_worker_uids, potential_worker_uids_by_age,
                                                                potential_worker_ages_left_count,
                                                                student_teacher_ratio=30, teacher_age_min=25,
                                                                teacher_age_max=75, verbose=False)

    for n in range(len(syn_schools)):
        print(syn_schools[n])
        assert syn_schools[n] is not None
        assert syn_school_uids[n] is not None

    assert syn_schools == gen_schools
    assert syn_school_uids == gen_school_uids
    assert potential_worker_uids == potential_worker_uids
    assert potential_worker_uids_by_age == potential_worker_uids_by_age
    assert workers_by_age_to_assign_count == workers_by_age_to_assign_count
コード例 #2
0
def test_get_uids_potential_workers(location='seattle_metro', state_location='Washington',
                                    country_location='usa', folder_name='contact_networks'):
    Nhomes = 10000
    uids_in_school = sp.get_uids_in_school(datadir, Nhomes, location,
                                           state_location,
                                           country_location,
                                           folder_name=folder_name,
                                           use_default=True)
    employment_rates = sp.get_employment_rates(datadir, location=location, state_location=state_location,
                                               country_location=country_location, use_default=True)
    age_by_uid_dic = sp.read_in_age_by_uid(datadir, location, state_location, country_location, folder_name, Nhomes)
    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
コード例 #3
0
def test_generate_workplace_sizes(location='seattle_metro', state_location='Washington',
                                  country_location='usa', folder_name='contact_networks'):
    Npeople = 10000
    uids_in_school, uids_in_school_by_age, ages_in_school_count = sp.get_uids_in_school(datadir, Npeople, location,
                                                                                        state_location,
                                                                                        country_location,
                                                                                        folder_name=folder_name,
                                                                                        use_default=True)

    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')

    # Need to instead get syn_schools now
    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)

    employment_rates = sp.get_employment_rates(datadir, location=location, state_location=state_location,
                                               country_location=country_location, use_default=True)

    age_by_uid_dic = sp.read_in_age_by_uid(datadir, location, state_location, country_location, folder_name, Npeople)

    potential_worker_uids, potential_worker_uids_by_age, potential_worker_ages_left_count = sp.get_uids_potential_workers(
        syn_school_uids, employment_rates, age_by_uid_dic)

    workers_by_age_to_assign_count = sp.get_workers_by_age_to_assign(employment_rates, potential_worker_ages_left_count,
                                                                     age_by_uid_dic)

    workplace_size_brackets = sp.get_workplace_size_brackets(datadir, location, state_location, country_location,
                                                             use_default=True)

    workplace_size_distr_by_brackets = sp.get_workplace_size_distr_by_brackets(datadir,
                                                                               state_location=state_location,
                                                                               country_location=country_location,
                                                                               use_default=True)
    workplace_sizes = sp.generate_workplace_sizes(workplace_size_distr_by_brackets, workplace_size_brackets,
                                                  workers_by_age_to_assign_count)

    return workers_by_age_to_assign_count, workplace_size_brackets, workplace_size_distr_by_brackets, workplace_sizes
コード例 #4
0
def test_generate_workplace_sizes(location='seattle_metro',
                                  state_location='Washington',
                                  country_location='usa'):
    Npeople = 10000
    uids_in_school, uids_in_school_by_age, uids_in_school_count = sp.get_uids_in_school(
        datadir,
        Npeople,
        location,
        state_location,
        country_location,
        use_default=True)

    employment_rates = sp.get_employment_rates(
        datadir,
        location=location,
        state_location=state_location,
        country_location=country_location,
        use_default=True)

    age_by_uid_dic = sp.read_in_age_by_uid(datadir, location, state_location,
                                           country_location, Npeople)

    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)

    workers_by_age_to_assign_count = sp.get_workers_by_age_to_assign(
        employment_rates, potential_worker_ages_left_count, age_by_uid_dic)

    workplace_size_brackets = sp.get_workplace_size_brackets(datadir,
                                                             location,
                                                             state_location,
                                                             country_location,
                                                             use_default=True)

    workplace_size_distr_by_brackets = sp.get_workplace_size_distr_by_brackets(
        datadir,
        state_location=state_location,
        country_location=country_location,
        use_default=True)
    workplace_sizes = sp.generate_workplace_sizes(
        workplace_size_distr_by_brackets, workplace_size_brackets,
        workers_by_age_to_assign_count)
    print(workplace_sizes)
コード例 #5
0
        y_sim[a] = new_ages_count[a]

    ax.plot(x, y_exp, color=cmap(0.2), label='Expected')
    ax.plot(x, y_sim, color=cmap3(0.6), label='Simulated')
    leg = ax.legend(fontsize=18)
    leg.draw_frame(False)
    ax.set_xlim(left=0, right=100)

    # fig.savefig('synthetic_age_comparison.pdf',format = 'pdf')
    # plt.show()

    sp.write_homes_by_age_and_uid(datadir, location, state_location,
                                  country_location, homes_by_uids,
                                  age_by_uid_dic)

age_by_uid_dic = sp.read_in_age_by_uid(datadir, location, state_location,
                                       country_location, Nhomes)

level = 'county'
sc_df = sp.get_school_enrollment_rates_df(datadir, location, state_location,
                                          level)
rates_by_age = sp.get_school_enrollment_rates(datadir, location,
                                              state_location, level)

school_sizes_count = sp.get_school_sizes_by_bracket(datadir, location,
                                                    state_location)

# print(school_sizes_count)

uids_by_age_dic = sp.get_ids_by_age_dic(age_by_uid_dic)
# for a in sorted(uids_by_age_dic):
# print(a, len(uids_by_age_dic[a]))