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")
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)
    if d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY in config_params:
        # TODO: replace this code when issue 2850 is resolved
        if len(config_params[d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY]) == 0:
            config_params.pop(d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY)
    with open(config_filename, 'w') as outfile:
        temp_config = {}
        temp_config[d_ss.ConfigKeys.PARAMETERS_KEY] = config_params
        json.dump(temp_config, outfile, indent=4)
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)
Пример #4
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)
Пример #5
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)
    if d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY in config_params:
        # TODO: replace this code when issue 2850 is resolved
        if len(config_params[
                d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY]) == 0:
            config_params.pop(
                d_ss.ConfigKeys.Serialization.POPULATION_FILENAMES_KEY)
    with open(config_filename, 'w') as outfile:
        temp_config = {}
        temp_config[d_ss.ConfigKeys.PARAMETERS_KEY] = config_params
        json.dump(temp_config, outfile, indent=4)
Пример #6
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)
Пример #8
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")
Пример #9
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)
Пример #11
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)