예제 #1
0
def test_add_network(pywr_json_filename, session_with_pywr_template,
                     projectmaker, root_user_id):
    project = projectmaker.create()

    template = JSONObject(
        hydra_base.get_template_by_name(pywr_template_name('Full')))

    importer = PywrHydraImporter(pywr_json_filename, template)

    # First the attributes must be added.
    attributes = [
        JSONObject(a) for a in importer.add_attributes_request_data()
    ]

    # The response attributes have ids now.
    response_attributes = hydra_base.add_attributes(attributes)

    # Convert to a simple dict for local processing.
    # TODO change this variable name to map or lookup
    attribute_ids = {a.name: a.id for a in response_attributes}

    # Now we try to create the network
    network = importer.add_network_request_data(attribute_ids, project.id)

    # Check transformed data is about right
    with open(pywr_json_filename) as fh:
        pywr_data = json.load(fh)

    assert_hydra_pywr(network, pywr_data)
    hydra_network = hydra_base.add_network(JSONObject(network),
                                           user_id=root_user_id)
예제 #2
0
def session_with_pywr_network(pywr_json_filename, session_with_pywr_template,
                              projectmaker, root_user_id):
    project = projectmaker.create()

    template = JSONObject(
        hydra_base.get_template_by_name(pywr_template_name('Full')))

    importer = PywrHydraImporter(pywr_json_filename, template)

    # First the attributes must be added.
    attributes = [
        JSONObject(a) for a in importer.add_attributes_request_data()
    ]

    # The response attributes have ids now.
    response_attributes = hydra_base.add_attributes(attributes)

    # Convert to a simple dict for local processing.
    attribute_ids = {a.name: a.id for a in response_attributes}

    # Now we try to create the network
    network = importer.add_network_request_data(attribute_ids, project.id)
    hydra_network = hydra_base.add_network(JSONObject(network),
                                           user_id=root_user_id)

    return hydra_network.id, pywr_json_filename
예제 #3
0
def test_add_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id):
    project = projectmaker.create()

    template = JSONObject(hydra_base.get_template_by_name(pywr_template_name('Full')))

    importer = PywrHydraImporter(pywr_json_filename, template)

    # First the attributes must be added.
    attributes = [JSONObject(a) for a in importer.add_attributes_request_data()]

    # The response attributes have ids now.
    response_attributes = hydra_base.add_attributes(attributes)

    # Convert to a simple dict for local processing.
    # TODO change this variable name to map or lookup
    attribute_ids = {a.name: a.id for a in response_attributes}

    # Now we try to create the network
    network = importer.add_network_request_data(attribute_ids, project.id)

    # Check transformed data is about right
    with open(pywr_json_filename) as fh:
        pywr_data = json.load(fh)

    assert_hydra_pywr(network, pywr_data)
    hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id)
예제 #4
0
def test_add_network(pywr_json_filename, db_with_template, projectmaker, logged_in_client):
    client = logged_in_client

    project = projectmaker.create()

    importer = PywrHydraImporter.from_client(client, pywr_json_filename, 'Full')
    importer.import_data(client, project.id)
예제 #5
0
파일: fixtures.py 프로젝트: UMWRG/PywrApp
def db_with_pywr_network(pywr_json_filename, db_with_template, projectmaker, logged_in_client):
    client = logged_in_client

    project = projectmaker.create()

    importer = PywrHydraImporter.from_client(client, pywr_json_filename, 'Full')
    network_id, scenario_id = importer.import_data(client, project.id)

    return network_id, scenario_id, pywr_json_filename
예제 #6
0
파일: fixtures.py 프로젝트: pywr/PywrApp
def db_with_pywr_network(pywr_json_filename, db_with_template, projectmaker,
                         logged_in_client):
    client = logged_in_client

    project = projectmaker.create()

    importer = PywrHydraImporter.from_client(client, pywr_json_filename,
                                             'Full')
    network_id, scenario_id = importer.import_data(client, project.id)

    return network_id, scenario_id, pywr_json_filename
예제 #7
0
파일: fixtures.py 프로젝트: UMWRG/PywrApp
def session_with_pywr_network(pywr_json_filename, session_with_pywr_template, projectmaker, root_user_id):
    project = projectmaker.create()

    template = JSONObject(hydra_base.get_template_by_name(pywr_template_name('Full')))

    importer = PywrHydraImporter(pywr_json_filename, template)

    # First the attributes must be added.
    attributes = [JSONObject(a) for a in importer.add_attributes_request_data()]

    # The response attributes have ids now.
    response_attributes = hydra_base.add_attributes(attributes)

    # Convert to a simple dict for local processing.
    attribute_ids = {a.name: a.id for a in response_attributes}

    # Now we try to create the network
    network = importer.add_network_request_data(attribute_ids, project.id)
    hydra_network = hydra_base.add_network(JSONObject(network), user_id=root_user_id)

    return hydra_network.id, pywr_json_filename
예제 #8
0
def test_add_network(pywr_json_filename, db_with_template, projectmaker,
                     logged_in_client):
    client = logged_in_client

    project = projectmaker.create()

    config = load_template_config('full')
    template = client.get_template_by_name(pywr_template_name(config['name']))

    importer = PywrHydraImporter.from_client(client, pywr_json_filename,
                                             template['id'])
    importer.import_data(client, project.id)
예제 #9
0
def pywr_nodes_edges_importer(logged_in_client, pywr_nodes_edges):
    # Note the use of a fake template here because we're not testing nodes/links.
    return PywrHydraImporter(logged_in_client, pywr_nodes_edges,
                             {'templatetypes': []})
예제 #10
0
def pywr_with_demand_pattern(model_directory, db_with_template, projectmaker,
                             logged_in_client):
    client = logged_in_client

    # Create the basic pywr model
    project = projectmaker.create()
    pywr_json_filename = os.path.join(model_directory, 'simple1.json')
    template = client.get_template_by_name(pywr_template_name('Full'))

    importer = PywrHydraImporter.from_client(client, pywr_json_filename,
                                             template['id'])
    network_id, scenario_id = importer.import_data(client, project.id)

    # Create the demand pattern
    pattern_attr = client.add_attribute({'name': 'demand_pattern'})
    ra = client.add_resource_attribute('NETWORK', network_id,
                                       pattern_attr['id'], 'N')

    with open(os.path.join(model_directory,
                           'simple_demand_pattern.json')) as fh:
        pattern_str = fh.read()

    pattern_data = Dataset({
        'name': 'demand_pattern',
        'value': pattern_str,
        "hidden": "N",
        "type": 'PYWR_PARAMETER_PATTERN',
    })

    client.add_data_to_attribute(scenario_id, ra['id'], pattern_data)

    # Assign the pattern to one of the nodes
    node = client.get_node_by_name(network_id, 'demand1')
    pattern_ref_attr = client.add_attribute({'name': 'demand'})
    ra = client.add_resource_attribute('NODE', node['id'],
                                       pattern_ref_attr['id'], 'N')

    pattern_ref_data = Dataset({
        'name': 'demand',
        'value': 'demand_pattern',
        'hidden': 'N',
        'type': 'PYWR_PARAMETER_PATTERN_REF'
    })

    client.add_data_to_attribute(scenario_id, ra['id'], pattern_ref_data)

    #
    population_attr = client.add_attribute({'name': 'population'})
    ra = client.add_resource_attribute('NODE', node['id'],
                                       population_attr['id'], 'N')

    population_data = Dataset({
        'name': 'population',
        'value': 3.14,
        'hidden': 'N',
        'type': 'SCALAR'
    })

    client.add_data_to_attribute(scenario_id, ra['id'], population_data)

    return network_id, scenario_id
예제 #11
0
def pywr_component_importer(pywr_component_data):
    # Note the use of a fake template here because we're not testing nodes/links.
    return PywrHydraImporter({'recorders': pywr_component_data}, {'templatetypes': []})