def application(output_folder="output", csv_name="ReportNodeDemographics.csv", config_filename="config.json",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: " + output_folder + "\n")
        print("csv_name: " + csv_name + "\n")
        print("config_name: " + config_filename + "\n")
        print("report_name: " + report_name + "\n")
        print("debug: " + str(debug) + "\n")

    sft.wait_for_done()

    with open(config_filename) as infile:
        test_config_name = json.load(infile)["parameters"]["Config_Name"]
    sft.start_report_file(report_name, test_config_name)

    all_data_df = pd.read_csv(path.join(output_folder, csv_name))
    all_data_df.rename(columns={' NodeID': 'NodeID', ' Gender': 'Gender',
                                ' AgeYears': 'AgeYears', ' NumIndividuals': 'NumIndividuals',
                                ' NumInfected': 'NumInfected'}, inplace=True)
    all_data_df.drop(['NumInfected'], axis=1, inplace=True)
    if debug:
        all_data_df.to_csv("DEBUG_all_data_cleaned.csv")

    last_day_df = all_data_df.loc[all_data_df['Time']==399]
    if debug:
        last_day_df.to_csv("DEBUG_day_399_data_cleaned.csv")
    northern_nodes = last_day_df[last_day_df['NodeID'].isin([1,2,3])]
    southern_nodes = last_day_df[last_day_df['NodeID'].isin([7,8,9])]
    eastern_nodes = last_day_df[last_day_df['NodeID'].isin([3,6,9])]
    western_nodes = last_day_df[last_day_df['NodeID'].isin([1,4,7])]

    create_report_file(sft_filename=report_name, n_nodes=northern_nodes,
                       s_nodes=southern_nodes, e_nodes=eastern_nodes,
                       w_nodes=western_nodes)
def application(config_filename="config.json", debug=False):
    with open(config_filename) as infile:
        config_json = json.load(infile)
        config_params = config_json[d_ss.ConfigKeys.PARAMETERS_KEY]
    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=sft.sft_output_filename,
                          config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY])
    d_ss.start_serialization_test()
    expected_dtk_filepath = config_params[d_ss.ConfigKeys.Serialization.POPULATION_PATH]
    expected_dtk_filename = config_params[d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY][0]
    expected_dtk_fullpath = path.join(expected_dtk_filepath, expected_dtk_filename)

    dtk_file = d_ss.DtkFile(expected_dtk_fullpath, file_suffix="old")
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    found_people={}
    ignored_people=[]
    testable_infections = 5
    remaining_sim_duration = config_object[d_ss.ConfigKeys.Serialization.TIMESTEPS_KEY][0]
    while len(found_people) < testable_infections:
        maybe_person = dtk_file.find_human_from_node(node_index=0, min_infections=1, ignore_suids=ignored_people)
        human_suid = maybe_person["suid"]["id"]
        if debug:
            print(f"Trying human {human_suid}.\n")
        acceptable_infection = has_acceptable_infection(maybe_person, remaining_sim_duration)
        if acceptable_infection:
            dtk_file.write_human_to_disk(node_index=0, suid=human_suid)
            found_people[human_suid] = acceptable_infection
        ignored_people.append(human_suid)
    dtk_file.write_json_file(found_people, "DEBUG_found_infected_persons.json")
示例#3
0
def application(output_folder="output",
                config_filename="config.json",
                jsonreport_name="InsetChart.json",
                report_name=sft.sft_output_filename,
                debug=False):
    if debug:
        print("output_folder: " + output_folder + "\n")
        print("config_filename: " + config_filename + "\n")
        print("insetchart_name: " + jsonreport_name + "\n")
        print("report_name: " + report_name + "\n")
        print("debug: " + str(debug) + "\n")

    sft.wait_for_done()
    config_object = dtk_iis.load_config_file(config_filename=config_filename,
                                             debug=debug)
    demographics_overlay_name = config_object[
        dtk_iis.ConfigKeys.DEMOGRAPHIC_FILENAMES][-1]
    campaign_name = config_object[dtk_iis.ConfigKeys.CAMPAIGN_FILENAME]
    test_config_name = config_object[dtk_iis.ConfigKeys.CONFIG_NAME]

    campaign_object = dtk_iis.load_campaign_file(campaign_name, debug)
    outbreak_day = campaign_object[dtk_iis.CampaignKeys.START_DAY]

    demographics_object = dtk_iis.load_demographics_file(
        demographics_filename=demographics_overlay_name,
        susceptibility_initialization_type=config_object[
            dtk_iis.ConfigKeys.SUS_INIT_DIST_TYPE],
        debug=debug)
    average_immunity = demographics_object[
        dtk_iis.DemographicFileKeys.KEY_AVERAGE_IMMUNITY]

    sft.start_report_file(report_name, test_config_name)

    report_data_object = dtk_iis.parse_json_report(output_folder=output_folder,
                                                   report_name=jsonreport_name,
                                                   debug=debug)

    statistical_population_channel = report_data_object[
        dtk_iis.InsetChannels.STATISTICAL_POPULATION]
    new_infections_channel = report_data_object[
        dtk_iis.InsetChannels.NEW_INFECTIONS]

    expected_infections_obj = dtk_iis.get_expected_infections(
        statistical_population_channel,
        average_immunity,
        campaign_object,
        debug=debug)

    actual_infections = dtk_iis.get_actual_infections(new_infections_channel,
                                                      outbreak_day)

    dtk_iis.create_report_file(expected_infections_obj,
                               actual_infections,
                               outbreak_day,
                               report_name,
                               debug=debug)
def application(output_folder="output", config_filename="config.json",
                jsonreport_name="InsetChart.json", stdout_filename="test.txt",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: " + output_folder)
        print("config_filename: " + config_filename)
        print("insetchart_name: " + jsonreport_name)
        print("report_name: " + report_name)
        print("debug: " + str(debug))

    sft.wait_for_done()
    config_object = dtk_iis.load_config_file(config_filename=config_filename,
                                             debug=debug)
    demographics_overlay_name = config_object[dtk_iis.ConfigKeys.DEMOGRAPHIC_FILENAMES][-1]
    campaign_name = config_object[dtk_iis.ConfigKeys.CAMPAIGN_FILENAME]
    test_config_name = config_object[dtk_iis.ConfigKeys.CONFIG_NAME]

    campaign_object = dtk_iis.load_campaign_file(campaign_name, debug)
    outbreak_day = campaign_object[dtk_iis.CampaignKeys.START_DAY]

    demographics_object = dtk_iis.load_demographics_file(
        demographics_filename=demographics_overlay_name,
        susceptibility_initialization_type=config_object[dtk_iis.ConfigKeys.SUS_INIT_DIST_TYPE],
        debug=debug)
    average_immunity = demographics_object[dtk_iis.DemographicFileKeys.KEY_AVERAGE_IMMUNITY]

    sft.start_report_file(report_name, test_config_name)

    individual_df = dtk_iis.parse_stdout_file(stdout_filename, debug=debug)
    dtk_iis.test_immunity_within_age_range(individual_df, max_age=365,
                                           expected_immunity=0.0)
    dtk_iis.test_immunity_within_age_range(individual_df, max_age=730,
                                           expected_immunity=0.4)


    report_data_object = dtk_iis.parse_json_report(output_folder=output_folder,
                                                   report_name=jsonreport_name,
                                                   debug=debug)

    statistical_population_channel = report_data_object[dtk_iis.InsetChannels.STATISTICAL_POPULATION]
    new_infections_channel = report_data_object[dtk_iis.InsetChannels.NEW_INFECTIONS]

    expected_infections_obj = dtk_iis.get_expected_infections(statistical_population_channel,
                                                              average_immunity,
                                                              campaign_object,
                                                              debug=debug)

    actual_infections = dtk_iis.get_actual_infections(new_infections_channel,
                                              outbreak_day)

    dtk_iis.create_report_file(expected_infections_obj, actual_infections,
                               outbreak_day, report_name,
                               debug=debug)
def application(output_folder="output", config_filename="config.json",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: {0}".format(output_folder))
        print("config_filename: {0}".format(config_filename))
        print("report_name: {0}".format(report_name))
        print("debug: {0}".format(debug))

    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=report_name,
                          config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY],
                          already_started=True)

    dtk_filename = path.join(output_folder, 'state-00070.dtk')
    dtk_file = d_ss.DtkFile(dtk_filename)
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    dtk_file.write_human_to_disk(node_index=0, suid=10)
    dtk_file.write_human_to_disk(node_index=0, suid=100)
    dtk_file.write_human_to_disk(node_index=0, suid=1000)

    #TODO: make sure each individual is Simulation_Duration days older
    human_1_first = d_ss.SerializedHuman.from_file('human-10-old.json')
    human_1_second = d_ss.SerializedHuman.from_file('human-10-new.json')

    human_100_first = d_ss.SerializedHuman.from_file('human-100-old.json')
    human_100_second = d_ss.SerializedHuman.from_file('human-100-new.json')

    human_1000_first = d_ss.SerializedHuman.from_file('human-1000-old.json')
    human_1000_second = d_ss.SerializedHuman.from_file('human-1000-new.json')

    messages = []
    expected_age_delta = config_object[d_ss.ConfigKeys.SIMULATION_DURATION_KEY]
    human_1_messages = human_1_first.compare_to_older(human_1_second, expected_age_delta)
    human_100_messages = human_100_first.compare_to_older(human_100_second, expected_age_delta)
    human_1000_messages = human_1000_first.compare_to_older(human_1000_second, expected_age_delta)

    messages += human_1_messages if human_1_messages else ["GOOD: Human 1 checks out"]
    messages += human_100_messages if human_100_messages else ["GOOD: Human 100 checks out"]
    messages += human_1000_messages if human_1000_messages else ["GOOD: Human 1000 checks out"]

    #TODO: compare the simulation objects

    #TODO: compare the node objects
    success_message_formatter = sft.format_success_msg
    d_ss.generate_report_file(config_object, report_name, output_folder=output_folder,
                              messages=messages, success_formatter=success_message_formatter,
                              debug=debug)
    d_ss.clean_serialization_test(debug)
示例#6
0
def application(output_folder="output", config_filename="config.json",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: {0}".format(output_folder))
        print("config_filename: {0}".format(config_filename))
        print("report_name: {0}".format(report_name))
        print("debug: {0}".format(debug))

    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=report_name, config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY])

    success_message_formatter = sft.format_success_msg
    d_ss.generate_report_file(config_object, report_name, output_folder=output_folder,
                              success_formatter=success_message_formatter,
                              debug=debug)
示例#7
0
def application(config_filename="config.json", debug=False):
    with open(config_filename) as infile:
        config_json = json.load(infile)
        config_params = config_json[d_ss.ConfigKeys.PARAMETERS_KEY]
    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=sft.sft_output_filename,
                          config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY])
    d_ss.start_serialization_test()
    expected_dtk_filepath = config_params[d_ss.ConfigKeys.Serialization.POPULATION_PATH]
    expected_dtk_filename = config_params[d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY][0]
    expected_dtk_fullpath = path.join(expected_dtk_filepath, expected_dtk_filename)

    dtk_file = d_ss.DtkFile(expected_dtk_fullpath, file_suffix="old")
    dtk_file.write_node_to_disk(node_index=0)
    # dtk_file.drop_simulation() # TODO: Figure out how to drop random number generator parts
    dtk_file.write_human_to_disk(node_index=0, suid=10)
    dtk_file.write_human_to_disk(node_index=0, suid=100)
    dtk_file.write_human_to_disk(node_index=0, suid=1000)
def application(config_filename="config.json", debug=False):
    with open(config_filename) as infile:
        config_json = json.load(infile)
        config_params = config_json[d_ss.ConfigKeys.PARAMETERS_KEY]
    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=sft.sft_output_filename,
                          config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY])
    d_ss.start_serialization_test()
    expected_dtk_filepath = config_params[d_ss.ConfigKeys.Serialization.POPULATION_PATH]
    expected_dtk_filename = config_params[d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY][0]
    expected_dtk_fullpath = path.join(expected_dtk_filepath, expected_dtk_filename)

    dtk_file = d_ss.DtkFile(expected_dtk_fullpath, file_suffix="old")
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    dtk_file.write_human_to_disk(node_index=0, suid=10)
    dtk_file.write_human_to_disk(node_index=0, suid=100)
    dtk_file.write_human_to_disk(node_index=0, suid=1000)
示例#9
0
def application(output_folder="output",
                csv_name="ReportNodeDemographics.csv",
                config_filename="config.json",
                report_name=sft.sft_output_filename,
                debug=False):
    if debug:
        print("output_folder: " + output_folder + "\n")
        print("csv_name: " + csv_name + "\n")
        print("config_name: " + config_filename + "\n")
        print("report_name: " + report_name + "\n")
        print("debug: " + str(debug) + "\n")

    sft.wait_for_done()

    with open(config_filename) as infile:
        test_config_name = json.load(infile)["parameters"]["Config_Name"]
    sft.start_report_file(report_name, test_config_name)

    all_data_df = pd.read_csv(path.join(output_folder, csv_name))
    all_data_df.rename(columns={
        ' NodeID': 'NodeID',
        ' Gender': 'Gender',
        ' AgeYears': 'AgeYears',
        ' NumIndividuals': 'NumIndividuals',
        ' NumInfected': 'NumInfected'
    },
                       inplace=True)
    all_data_df.drop(['NumInfected'], axis=1, inplace=True)
    if debug:
        all_data_df.to_csv("DEBUG_all_data_cleaned.csv")

    last_day_df = all_data_df.loc[all_data_df['Time'] == 399]
    if debug:
        last_day_df.to_csv("DEBUG_day_399_data_cleaned.csv")
    northern_nodes = last_day_df[last_day_df['NodeID'].isin([1, 2, 3])]
    southern_nodes = last_day_df[last_day_df['NodeID'].isin([7, 8, 9])]
    eastern_nodes = last_day_df[last_day_df['NodeID'].isin([3, 6, 9])]
    western_nodes = last_day_df[last_day_df['NodeID'].isin([1, 4, 7])]

    create_report_file(sft_filename=report_name,
                       n_nodes=northern_nodes,
                       s_nodes=southern_nodes,
                       e_nodes=eastern_nodes,
                       w_nodes=western_nodes)
示例#10
0
def application(output_folder="output", config_filename="config.json",
                jsonreport_name="InsetChart.json", stdout_filename="test.txt",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: " + output_folder + "\n")
        print("config_filename: " + config_filename + "\n")
        print("insetchart_name: " + jsonreport_name + "\n")
        print("stdout filename:" + stdout_filename + "\n")
        print("report_name: " + report_name + "\n")
        print("debug: " + str(debug) + "\n")

    sft.wait_for_done()
    config_object = dtk_iis.load_config_file(config_filename=config_filename,
                                             debug=debug)
    demographics_overlay_name = config_object[dtk_iis.ConfigKeys.DEMOGRAPHIC_FILENAMES][-1]
    campaign_name = config_object[dtk_iis.ConfigKeys.CAMPAIGN_FILENAME]
    test_config_name = config_object[dtk_iis.ConfigKeys.CONFIG_NAME]

    demographics_object = dtk_iis.load_demographics_file(
        demographics_filename=demographics_overlay_name,
        susceptibility_initialization_type=config_object[dtk_iis.ConfigKeys.SUS_INIT_DIST_TYPE],
        debug=debug)

    sft.start_report_file(report_name, test_config_name)

    i_df = dtk_iis.parse_stdout_file(stdout_filename, debug=debug)
    distribution_object = demographics_object[dtk_iis.DemographicFileKeys.SusceptibilityDistribution.KEY]
    distro_values = \
        distribution_object[dtk_iis.DemographicFileKeys.SusceptibilityDistribution.ComplexKeys.DistributionValues][0]
    distro_results = \
        distribution_object[dtk_iis.DemographicFileKeys.SusceptibilityDistribution.ComplexKeys.ResultValues][0]
    if debug:
        print("Sus distribution type: {0}\n".format(config_object[dtk_iis.ConfigKeys.SUS_INIT_DIST_TYPE]))
        print("Distribution object: {0}\n".format(distribution_object))
        print("Distro values: {0}\n".format(distro_values))
    with open(report_name, "a") as outfile:
        messages = dtk_iis.validate_complex_initialization_numpy(
            individual_dataframe=i_df, susceptibility_distribution=distribution_object,
            outfile=outfile, debug=debug)
    pass
示例#11
0
def application(config_filename="config.json", debug=False):
    with open(config_filename) as infile:
        config_json = json.load(infile)
        config_params = config_json[d_ss.ConfigKeys.PARAMETERS_KEY]
    config_object = d_ss.load_config_file(config_filename=config_filename,
                                          debug=debug)
    sft.start_report_file(
        output_filename=sft.sft_output_filename,
        config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY])
    d_ss.start_serialization_test()
    expected_dtk_filepath = config_params[
        d_ss.ConfigKeys.Serialization.POPULATION_PATH]
    expected_dtk_filename = config_params[
        d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY][0]
    expected_dtk_fullpath = path.join(expected_dtk_filepath,
                                      expected_dtk_filename)

    dtk_file = d_ss.DtkFile(expected_dtk_fullpath, file_suffix="old")
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    found_people = {}
    ignored_people = []
    testable_infections = 5
    remaining_sim_duration = config_object[
        d_ss.ConfigKeys.Serialization.TIMESTEPS_KEY][0]
    while len(found_people) < testable_infections:
        maybe_person = dtk_file.find_human_from_node(
            node_index=0, min_infections=1, ignore_suids=ignored_people)
        human_suid = maybe_person["suid"]["id"]
        if debug:
            print(f"Trying human {human_suid}.\n")
        acceptable_infection = has_acceptable_infection(
            maybe_person, remaining_sim_duration)
        if acceptable_infection:
            dtk_file.write_human_to_disk(node_index=0, suid=human_suid)
            found_people[human_suid] = acceptable_infection
        ignored_people.append(human_suid)
    dtk_file.write_json_file(found_people, "DEBUG_found_infected_persons.json")
示例#12
0
def application(output_folder="output",
                config_filename="config.json",
                report_name=sft.sft_output_filename,
                debug=False):
    if debug:
        print("output_folder: {0}".format(output_folder))
        print("config_filename: {0}".format(config_filename))
        print("report_name: {0}".format(report_name))
        print("debug: {0}".format(debug))

    config_object = d_ss.load_config_file(config_filename=config_filename,
                                          debug=debug)
    sft.start_report_file(
        output_filename=report_name,
        config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY],
        already_started=True)

    dtk_filename = path.join(output_folder, 'state-00300.dtk')
    dtk_file = d_ss.DtkFile(dtk_filename)
    dtk_file.write_node_to_disk(node_index=0)
    # dtk_file.drop_simulation() # TODO: remove random number generator parts
    dtk_file.write_human_to_disk(node_index=0, suid=10)
    dtk_file.write_human_to_disk(node_index=0, suid=100)
    dtk_file.write_human_to_disk(node_index=0, suid=1000)

    #TODO: make sure each individual is Simulation_Duration days older
    human_1_first = d_ss.SerializedHuman.from_file('human-10-old.json')
    human_1_second = d_ss.SerializedHuman.from_file('human-10-new.json')

    human_100_first = d_ss.SerializedHuman.from_file('human-100-old.json')
    human_100_second = d_ss.SerializedHuman.from_file('human-100-new.json')

    human_1000_first = d_ss.SerializedHuman.from_file('human-1000-old.json')
    human_1000_second = d_ss.SerializedHuman.from_file('human-1000-new.json')

    messages = []
    expected_age_delta = config_object[d_ss.ConfigKeys.SIMULATION_DURATION_KEY]
    human_1_messages = human_1_first.compare_to_older(human_1_second,
                                                      expected_age_delta)
    human_100_messages = human_100_first.compare_to_older(
        human_100_second, expected_age_delta)
    human_1000_messages = human_1000_first.compare_to_older(
        human_1000_second, expected_age_delta)

    messages += human_1_messages if human_1_messages else [
        "GOOD: Human 1 checks out"
    ]
    messages += human_100_messages if human_100_messages else [
        "GOOD: Human 100 checks out"
    ]
    messages += human_1000_messages if human_1000_messages else [
        "GOOD: Human 1000 checks out"
    ]

    #TODO: compare the simulation objects

    #TODO: compare the node objects
    success_message_formatter = sft.format_success_msg
    d_ss.generate_report_file(config_object,
                              report_name,
                              output_folder=output_folder,
                              messages=messages,
                              success_formatter=success_message_formatter,
                              debug=debug)
    d_ss.clean_serialization_test(debug)
def application(output_folder="output", config_filename="config.json",
                report_name=sft.sft_output_filename, debug=False):
    if debug:
        print("output_folder: {0}".format(output_folder))
        print("config_filename: {0}".format(config_filename))
        print("report_name: {0}".format(report_name))
        print("debug: {0}".format(debug))

    config_object = d_ss.load_config_file(config_filename=config_filename, debug=debug)
    sft.start_report_file(output_filename=report_name,
                          config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY],
                          already_started=True)
    sft.wait_for_done()

    dtk_filename = path.join(output_folder, 'state-00005.dtk')
    dtk_file = d_ss.DtkFile(dtk_filename)
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    infected_people_to_check = []
    with open("DEBUG_found_infected_persons.json") as infile:
        infected_people_to_check = json.load(infile)
        if debug:
            print(f"Infected_people_to_check: {infected_people_to_check}")
    infected_people_first={}
    infected_people_second={}
    for suid in infected_people_to_check:
        suid_int = int(suid)
        print("Trying suid: {0}".format(suid_int))
        infected_people_first[suid] = d_ss.SerializedHuman.from_file(f"human-{suid_int}-old.json")
        dtk_file.write_human_to_disk(node_index=0, suid=suid_int, debug=debug)
        infected_people_second[suid] = d_ss.SerializedHuman.from_file(f"human-{suid_int}-new.json")

    # Make sure each individual is Simulation_Duration days older
    messages = []
    expected_age_delta = config_object[d_ss.ConfigKeys.Serialization.TIMESTEPS_KEY][0]
    for person in infected_people_to_check:
        infection_suid = infected_people_to_check[person]
        if debug:
            # print(f"X is: {x}")
            print(f"person is: {person}")
            print(f"infection is: {infection_suid}")
            print(f"infected_people_first[person] = {infected_people_first[person]}")
            print(f"infected_people_second[person] = {infected_people_second[person]}")
        aging_messages = infected_people_first[person].compare_to_older(infected_people_second[person], expected_age_delta)
        messages += aging_messages if aging_messages else [f"GOOD: human {person} checks out"]
        older_infection = infected_people_first[person].get_infection_by_suid(infection_suid)
        newer_infection = infected_people_second[person].get_infection_by_suid(infection_suid)
        messages += newer_infection.compare_to_older(older_infection, expected_age_delta)
        messages += newer_infection.validate_own_timers()

    # Make sure each infection is Simulation_Duration days older


    #TODO: compare the simulation objects

    #TODO: compare the node objects
    success_message_formatter = sft.format_success_msg
    d_ss.generate_report_file(config_object, report_name, output_folder=output_folder,
                              messages=messages, success_formatter=success_message_formatter,
                              debug=debug)
    d_ss.clean_serialization_test(debug)
示例#14
0
def application(output_folder="output",
                config_filename="config.json",
                report_name=sft.sft_output_filename,
                debug=False):
    if debug:
        print("output_folder: {0}".format(output_folder))
        print("config_filename: {0}".format(config_filename))
        print("report_name: {0}".format(report_name))
        print("debug: {0}".format(debug))

    config_object = d_ss.load_config_file(config_filename=config_filename,
                                          debug=debug)
    sft.start_report_file(
        output_filename=report_name,
        config_name=config_object[d_ss.ConfigKeys.CONFIGNAME_KEY],
        already_started=True)
    sft.wait_for_done()

    dtk_filename = path.join(output_folder, 'state-00005.dtk')
    dtk_file = d_ss.DtkFile(dtk_filename)
    dtk_file.write_node_to_disk(node_index=0)
    dtk_file.write_simulation_to_disk()
    infected_people_to_check = []
    with open("DEBUG_found_infected_persons.json") as infile:
        infected_people_to_check = json.load(infile)
        if debug:
            print(f"Infected_people_to_check: {infected_people_to_check}")
    infected_people_first = {}
    infected_people_second = {}
    for suid in infected_people_to_check:
        suid_int = int(suid)
        print("Trying suid: {0}".format(suid_int))
        infected_people_first[suid] = d_ss.SerializedHuman.from_file(
            f"human-{suid_int}-old.json")
        dtk_file.write_human_to_disk(node_index=0, suid=suid_int, debug=debug)
        infected_people_second[suid] = d_ss.SerializedHuman.from_file(
            f"human-{suid_int}-new.json")

    # Make sure each individual is Simulation_Duration days older
    messages = []
    expected_age_delta = config_object[
        d_ss.ConfigKeys.Serialization.TIMESTEPS_KEY][0]
    for person in infected_people_to_check:
        infection_suid = infected_people_to_check[person]
        if debug:
            # print(f"X is: {x}")
            print(f"person is: {person}")
            print(f"infection is: {infection_suid}")
            print(
                f"infected_people_first[person] = {infected_people_first[person]}"
            )
            print(
                f"infected_people_second[person] = {infected_people_second[person]}"
            )
        aging_messages = infected_people_first[person].compare_to_older(
            infected_people_second[person], expected_age_delta)
        messages += aging_messages if aging_messages else [
            f"GOOD: human {person} checks out"
        ]
        older_infection = infected_people_first[person].get_infection_by_suid(
            infection_suid)
        newer_infection = infected_people_second[person].get_infection_by_suid(
            infection_suid)
        messages += newer_infection.compare_to_older(older_infection,
                                                     expected_age_delta)
        messages += newer_infection.validate_own_timers()

    # Make sure each infection is Simulation_Duration days older

    #TODO: compare the simulation objects

    #TODO: compare the node objects
    success_message_formatter = sft.format_success_msg
    d_ss.generate_report_file(config_object,
                              report_name,
                              output_folder=output_folder,
                              messages=messages,
                              success_formatter=success_message_formatter,
                              debug=debug)
    d_ss.clean_serialization_test(debug)