Exemple #1
0
def test_scenario_requisites(request):
    print("\n--Starting:", request.node.name)
    base_scenario = {}

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '4_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '5_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '6_test_project_card.yml')))

    scen = Scenario.create_scenario(base_scenario=base_scenario,
                                    project_cards_list=project_cards_list)

    print(str(scen), "\n")

    scen.check_scenario_requisites()
    if scen.has_requisite_error:
        print('Missing pre- or co-requisite projects found for scenario!')

    print('Requisite checks done:', scen.requisites_checked)
    print("--Finished:", request.node.name)
Exemple #2
0
def test_scenario_conflicts(request):

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "a_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "b_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "c_test_project_card.yml")))

    scen = Scenario.create_scenario(base_scenario={},
                                    project_cards_list=project_cards_list)

    print(str(scen), "\n")

    scen.check_scenario_conflicts()
    if scen.has_conflict_error:
        print("Conflicting project found for scenario!")

    print("Conflict checks done:", scen.conflicts_checked)
    print("--Finished:", request.node.name)
Exemple #3
0
def test_scenario_requisites(request):
    print("\n--Starting:", request.node.name)
    base_scenario = {}

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "a_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "b_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "c_test_project_card.yml")))

    scen = Scenario.create_scenario(base_scenario=base_scenario,
                                    project_cards_list=project_cards_list)

    print(str(scen), "\n")

    scen.check_scenario_requisites()
    if scen.has_requisite_error:
        print("Missing pre- or co-requisite projects found for scenario!")

    print("Requisite checks done:", scen.requisites_checked)
    print("--Finished:", request.node.name)
Exemple #4
0
def test_project_sort(request):
    print("\n--Starting:", request.node.name)
    base_scenario = {}

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '4_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '5_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '6_test_project_card.yml')))

    scen = Scenario.create_scenario(base_scenario=base_scenario,
                                    project_cards_list=project_cards_list)
    print("\n> Prerequisites:")
    import pprint
    pprint.pprint(scen.prerequisites)
    print("\nUnordered Projects:", scen.project_names())
    scen.check_scenario_conflicts()
    scen.check_scenario_requisites()

    scen.order_project_cards()
    print("Ordered Projects:", scen.project_names())
    print("--Finished:", request.node.name)
Exemple #5
0
def test_scenario_conflicts(request):

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '4_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '5_test_project_card.yml')))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(os.getcwd(), 'example', 'stpaul', 'project_cards',
                         '6_test_project_card.yml')))

    scen = Scenario.create_scenario(base_scenario={},
                                    project_cards_list=project_cards_list)

    print(str(scen))
    scen.check_scenario_conflicts()
    if scen.has_conflict_error:
        print('Conflicting project found for scenario!')

    print('Conflict checks done:', scen.conflicts_checked)
    print("--Finished:", request.node.name)
Exemple #6
0
def test_project_sort(request):
    print("\n--Starting:", request.node.name)
    base_scenario = {}

    project_cards_list = []
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "a_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "b_test_project_card.yml")))
    project_cards_list.append(
        ProjectCard.read(
            os.path.join(STPAUL_DIR, "project_cards",
                         "c_test_project_card.yml")))

    scen = Scenario.create_scenario(base_scenario=base_scenario,
                                    project_cards_list=project_cards_list)
    print("\n> Prerequisites:")
    import pprint

    pprint.pprint(scen.prerequisites)
    print("\nUnordered Projects:", scen.get_project_names())
    scen.check_scenario_conflicts()
    scen.check_scenario_requisites()

    scen.order_project_cards()
    print("Ordered Projects:", scen.get_project_names())
    print("--Finished:", request.node.name)
Exemple #7
0
def test_project_card_write(request):
    print("\n--Starting:", request.node.name)
    in_dir = os.path.join(STPAUL_DIR, "project_cards")
    in_file = os.path.join(in_dir, "1_simple_roadway_attribute_change.yml")
    outfile = os.path.join(SCRATCH_DIR,
                           "t_simple_roadway_attribute_change.yml")
    project_card = ProjectCard.read(in_file)
    project_card.write(outfile)
    test_card = ProjectCard.read(in_file)
    for k, v in project_card.__dict__.items():
        assert v == test_card.__dict__[k]
def test_create_ml_network_shape(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")
    net = _read_stpaul_net()

    print("Reading project card ...")
    project_card_name = "4_simple_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path, validate=False)
    project_card_dictionary = project_card.__dict__

    orig_links_count = len(net.links_df)
    orig_shapes_count = len(net.shapes_df)

    net.apply(project_card_dictionary)
    ml_net = net.create_managed_lane_network()

    rev_links_count = len(ml_net.links_df)
    rev_shapes_count = len(ml_net.shapes_df)

    assert (rev_links_count - orig_links_count) == (rev_shapes_count -
                                                    orig_shapes_count)

    # 2 new ML links, each ML link has 2 more access/egress links
    # total new links for 2 ML links will be 6 (2*3)
    assert rev_shapes_count == orig_shapes_count + 2 * 3
    assert rev_links_count == orig_links_count + 2 * 3

    print("--Finished:", request.node.name)
def test_add_roadway_shape(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")
    net = _read_stpaul_net()

    print("Reading project card ...")
    project_card_name = "10_simple_roadway_add_change.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path, validate=False)
    project_card_dictionary = project_card.__dict__

    orig_links_count = len(net.links_df)
    orig_shapes_count = len(net.shapes_df)

    net.add_new_roadway_feature_change(project_card_dictionary.get("links"),
                                       project_card_dictionary.get("nodes"))

    rev_links_count = len(net.links_df)
    rev_shapes_count = len(net.shapes_df)

    assert (rev_links_count - orig_links_count) == (rev_shapes_count -
                                                    orig_shapes_count)
    assert rev_shapes_count == orig_shapes_count + 2
    assert rev_links_count == orig_links_count + 2

    print("--Finished:", request.node.name)
def test_select_roadway_features_from_projectcard(request):
    print("\n--Starting:",request.node.name)

    print("Reading network ...")
    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)

    print("Reading project card ...")
    #project_card_name = '1_simple_roadway_attribute_change.yml'
    #project_card_name = '2_multiple_roadway.yml'
    project_card_name = '3_multiple_roadway_attribute_change.yml'

    project_card_path = os.path.join(os.getcwd(),'example','stpaul','project_cards',project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    sel = project_card.facility
    print("Selection:\n",sel)
    selected_links = net.select_roadway_features(sel)

    if not type(selected_links) == GeoDataFrame:
        print("Couldn't find path from {} to {}".format(sel['A'],sel['B']))
    else:
        print("Features selected:",len(selected_links))

    print("--Finished:",request.node.name)
Exemple #11
0
def test_add_managed_lane(request):
    print("\n--Starting:", request.node.name)
    net = _read_stpaul_net()
    print("Reading project card ...")
    project_card_name = "5_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    selected_link_indices = net.select_roadway_features(project_card.facility)

    attributes_to_update = [p["property"] for p in project_card.properties]
    orig_links = net.links_df.loc[selected_link_indices, attributes_to_update]
    print("Original Links:\n", orig_links)

    net.apply_managed_lane_feature_change(
        net.select_roadway_features(project_card.facility), project_card.properties
    )

    rev_links = net.links_df.loc[selected_link_indices, attributes_to_update]
    print("Revised Links:\n", rev_links)

    net.write(filename="test_ml", path=SCRATCH_DIR)

    print("--Finished:", request.node.name)
def test_apply_roadway_feature_change(request,
                                      apply_feature_change_project_card):
    print("\n--Starting:", request.node.name)
    my_net = _read_stpaul_net()
    print("Reading project card", apply_feature_change_project_card, "...")
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     apply_feature_change_project_card)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    selected_link_indices = my_net.select_roadway_features(
        project_card.facility)

    attributes_to_update = [
        p["property"] for p in project_card.properties
        if p["property"] in my_net.links_df.columns
    ]
    orig_links = my_net.links_df.loc[selected_link_indices,
                                     attributes_to_update]
    print("Original Links:\n", orig_links)

    my_net.apply_roadway_feature_change(
        my_net.select_roadway_features(project_card.facility),
        project_card.properties)

    rev_links = my_net.links_df.loc[selected_link_indices,
                                    attributes_to_update]
    print("Revised Links:\n", rev_links)

    print("--Finished:", request.node.name)
Exemple #13
0
def test_write_model_net(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    print("Reading project card ...")
    project_card_name = "5_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    net.apply(project_card.__dict__)
    net.links_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_links.csv"), index=False)
    net.nodes_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_nodes.csv"), index=False)
    net.shapes_df.to_csv(os.path.join(SCRATCH_DIR, "in_ml_shape.csv"), index=False)

    ml_net = net.create_managed_lane_network(in_place=False)
    ml_net.links_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_links.csv"), index=False)
    ml_net.nodes_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_nodes.csv"), index=False)
    ml_net.shapes_df.to_csv(os.path.join(SCRATCH_DIR, "out_ml_shape.csv"), index=False)

    print("--Finished:", request.node.name)
Exemple #14
0
def test_add_adhoc_field_from_card(request):
    """
    Makes sure new fields can be added from a project card and that
    they will be the right type.
    """
    print("\n--Starting:", request.node.name)
    net = _read_stpaul_net()
    project_card_name = "new_fields_project_card.yml"

    print("Reading project card", project_card_name, "...")
    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    selected_link_indices = net.select_roadway_features(project_card.facility)

    attributes_to_update = [p["property"] for p in project_card.properties]

    net.apply_roadway_feature_change(
        net.select_roadway_features(project_card.facility), project_card.properties
    )

    rev_links = net.links_df.loc[selected_link_indices, attributes_to_update]
    rev_types = [(a, net.links_df[a].dtypes) for a in attributes_to_update]
    # rev_types = net.links_df[[attributes_to_update]].dtypes
    print("Revised Links:\n", rev_links, "\nNew Property Types:\n", rev_types)

    assert net.links_df.loc[selected_link_indices[0], "my_ad_hoc_field_float"] == 1.1
    assert net.links_df.loc[selected_link_indices[0], "my_ad_hoc_field_integer"] == 2
    assert (
        net.links_df.loc[selected_link_indices[0], "my_ad_hoc_field_string"] == "three"
    )
    print("--Finished:", request.node.name)
Exemple #15
0
def test_read_write_project_card(request):

    card_dir = os.path.join(".", "tests", "projects", "project_AB")
    card_file = os.path.join(card_dir, "project_A.yml")
    output_file = "test_card.yml"

    card = ProjectCard.read(card_file, validate=False)
    card.__dict__.pop("file")
    card.__dict__.pop("valid")
    card.write(filename=output_file)

    card_from_disk = ProjectCard.read(output_file, validate=False)
    card_from_disk.__dict__.pop("file")
    card_from_disk.__dict__.pop("valid")

    os.remove(output_file)

    assert (card.__dict__ == card_from_disk.__dict__) is True
def test_dot_wrangler_roadway(request):
    print("\n--Starting:", request.node.name)

    print("Reading .wrangler project card ...")
    project_card_name = "add_highway_lanes.wrangler"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path, validate=False)
    print(project_card)
    assert ("self.links_df.loc[self.links_df['lanes'] == 4, 'lanes'] = 12"
            in project_card.pycode)
Exemple #17
0
def test_project_card_read(request):
    print("\n--Starting:", request.node.name)
    in_dir = os.path.join(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
        'example', 'stpaul', 'project_cards')
    in_file = os.path.join(in_dir, "1_simple_roadway_attribute_change.yml")
    project_card = ProjectCard.read(in_file)
    WranglerLogger.info(project_card.__dict__)
    print(str(project_card))
    assert (project_card.category == "Roadway Attribute Change")
    print("--Finished:", request.node.name)
Exemple #18
0
def test_managed_lane_project_card(request):
    print("\n--Starting:", request.node.name)

    print("Reading project card ...")
    project_card_name = "5_managed_lane.yml"
    project_card_path = os.path.join(os.getcwd(), "examples", "stpaul",
                                     "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)
    print(project_card)

    print("--Finished:", request.node.name)
Exemple #19
0
    def write_project_card(self, filename):
        """
        Writes project cards.

        Args:
            filename (str): File path to output .yml

        Returns:
            None
        """
        ProjectCard(self.card_data).write(filename)
        WranglerLogger.info("Wrote project card to: {}".format(filename))
Exemple #20
0
def test_project_card(request):
    print("\n--Starting:", request.node.name)

    transit_net = TransitNetwork.read(STPAUL_DIR)
    project_card_path = os.path.join(
        STPAUL_DIR, "project_cards", "12_transit_shape_change.yml"
    )
    project_card = ProjectCard.read(project_card_path)
    transit_net.apply_transit_feature_change(
        transit_net.select_transit_features(project_card.facility),
        project_card.properties
    )

    # Shapes
    result = transit_net.feed.shapes[transit_net.feed.shapes["shape_id"] ==
                                     "2940002"]["shape_model_node_id"].tolist()
    answer = ["45983", "126312", "126316", "46663", "46665", "150855", "11188",
              "84899", "46666", "77077", "68609", "39425", "62146", "41991", "70841",
              "45691", "69793", "45683", "45685", "7688", "45687", "100784", "100782",
              "45688", "37609", "19077", "38696", "91685", "38698", "138152", "91825",
              "71086", "133190", "133187", "133188", "133183", "133179", "133177",
              "44298", "67125", "68417", "72311", "75802", "46083", "75783", "71964",
              "71456", "44190", "61464", "75786", "74898", "73817", "51814", "75787",
              "75122", "75788", "123002", "123003", "39803", "75789", "70300", "68072",
              "68039", "68041", "68043", "68044", "40878", "32484", "32474", "32485",
              "32499", "32532", "32544", "32479", "32491", "32502", "10658", "10655",
              "10651", "10652", "10649", "111619", "10643", "10642", "10640", "74056",
              "70553", "12145", "12147", "56079", "12142", "79492", "76595", "51578",
              "74179", "82208", "41799", "123353", "123351", "51651", "67557", "12136",
              "12135",  "67419", "56842", "80494", "128663", "52195", "12137", "12146",
              "25816", "25809", "115180", "9910", "115159", "115154", "162573", "10409",
              "164501", "170453", "158052", "145473", "25658",  "91126", "90985", "90993",
              "145453", "112931", "157281", "163689",  "163713", "117979", "116895",
              "138571", "87210", "97813", "165113",  "133948", "101458", "105285",
              "100603", "165025", "127797", "7753",  "127801", "28889", "28890", "127804",
              "7754", "127802", "48699",  "125802", "125237", "96386", "96366", "96367",
              "145532", "94231", "6578", "7278", "9831", "10910", "10242", "112268",
              "110085", "114928", "114941", "11694", "11654", "11705", "154299", "11708",
              "11710",  "11704", "11674", "11668", "11677", "9483", "161536", "88542",
              "22645", "19792", "126666", "170579", "145513", "155886", "101864",
              "100562",  "51955", "23270", "23263", "23271", "139930"]
    assert result == answer

    # Stops
    result = transit_net.feed.stop_times[transit_net.feed.stop_times["trip_id"] ==
                                         "14944022-JUN19-MVS-BUS-Weekday-01"]["stop_id"].tolist()
    result_tail = result[-5:]
    answer_tail = ["16842", "16837", "16836", "16833", "17040"]
    assert result_tail == answer_tail

    print("--Finished:", request.node.name)
Exemple #21
0
def test_select_roadway_features_from_projectcard(request):
    print("\n--Starting:", request.node.name)
    net = _read_stpaul_net()
    print("Reading project card ...")
    project_card_name = "3_multiple_roadway_attribute_change.yml"

    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    sel = project_card.facility
    selected_link_indices = net.select_roadway_features(sel)
    print("Features selected:", len(selected_link_indices))

    print("--Finished:", request.node.name)
Exemple #22
0
def test_query_builder(request, test_spec):
    selection, answer = test_spec

    sel_query = ProjectCard.build_link_selection_query(
        selection=selection["selection"],
        unique_model_link_identifiers=RoadwayNetwork.
        UNIQUE_MODEL_LINK_IDENTIFIERS,
        ignore=selection["ignore"],
    )

    print("\nsel_query:\n", sel_query)
    print("\nanswer:\n", answer)
    assert sel_query == answer

    print("--Finished:", request.node.name)
Exemple #23
0
def test_add_roadway_links(request):
    print("\n--Starting:", request.node.name)
    net = _read_stpaul_net()

    print("Reading project card ...")
    # project_card_name = "10_simple_roadway_add_change.yml"
    project_card_name = "10a_incorrect_roadway_add_change.yml"

    project_card_path = os.path.join(STPAUL_DIR, "project_cards", project_card_name)
    project_card = ProjectCard.read(project_card_path)

    project_card_dictionary = project_card.__dict__

    net.add_new_roadway_feature_change(
        project_card_dictionary.get("links"), project_card_dictionary.get("nodes")
    )

    print("--Finished:", request.node.name)
Exemple #24
0
def test_query_roadway_property_by_time_group(request, variable_query):
    print("\n--Starting:", request.node.name)
    net = _read_stpaul_net()
    print("Applying project card...")
    project_card_path = os.path.join(STPAUL_DIR, "project_cards", "5_managed_lane.yml")
    project_card = ProjectCard.read(project_card_path, validate=False)
    net.apply_managed_lane_feature_change(
        net.select_roadway_features(project_card.facility), project_card.properties
    )
    print("Querying Attribute...")
    print("QUERY:\n", variable_query)
    v_series = net.get_property_by_time_period_and_group(
        variable_query["v"],
        category=variable_query["category"],
        time_period=variable_query["time_period"],
    )
    selected_link_indices = net.select_roadway_features(project_card.facility)

    print("CALCULATED:\n", v_series.loc[selected_link_indices])
    print("ORIGINAL:\n", net.links_df.loc[selected_link_indices, variable_query["v"]])
def test_roadway_feature_change(request):
    print("\n--Starting:",request.node.name)

    print("Reading network ...")
    net = RoadwayNetwork.read(link_file= STPAUL_LINK_FILE, node_file=STPAUL_NODE_FILE, shape_file=STPAUL_SHAPE_FILE, fast=True)

    project_card_set = [
        (net, '1_simple_roadway_attribute_change.yml'),
        (net, '2_multiple_roadway.yml'),
        (net, '3_multiple_roadway_attribute_change.yml'),
    ]

    for my_net, project_card_name in project_card_set:
        project_card_path = os.path.join(os.getcwd(),'example','stpaul','project_cards',project_card_name)
        print("Reading project card from:\n {}".format(project_card_path))
        project_card = ProjectCard.read(project_card_path)

        roadway_feature_change(my_net, project_card)

    print("--Finished:",request.node.name)
def test_create_default_geometry(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")
    net = _read_stpaul_net()

    print("Reading project card ...")
    project_card_name = "10_simple_roadway_add_change.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path, validate=False)
    project_card_dictionary = project_card.__dict__

    net.add_new_roadway_feature_change(project_card_dictionary.get("links"),
                                       project_card_dictionary.get("nodes"))

    links_without_geometry = net.links_df[net.links_df["geometry"] == ""]

    assert len(links_without_geometry) == 0

    print("--Finished:", request.node.name)
def test_existing_managed_lane_apply(request):
    print("\n--Starting:", request.node.name)

    print("Reading network ...")

    net = RoadwayNetwork.read(
        link_file=STPAUL_LINK_FILE,
        node_file=STPAUL_NODE_FILE,
        shape_file=STPAUL_SHAPE_FILE,
        fast=True,
    )

    print("Reading project card ...")
    project_card_name = "4_simple_managed_lane.yml"
    project_card_path = os.path.join(STPAUL_DIR, "project_cards",
                                     project_card_name)
    project_card = ProjectCard.read(project_card_path)

    print("Selecting roadway features ...")
    selected_link_indices = net.select_roadway_features(project_card.facility)

    if "managed" in net.links_df.columns:
        existing_ml_links = len(
            (net.links_df[net.links_df["managed"] == 1]).index)
    else:
        existing_ml_links = 0

    print("Existing # of ML links in the network:", existing_ml_links)

    net.apply_managed_lane_feature_change(
        net.select_roadway_features(project_card.facility),
        project_card.properties)

    new_ml_links = len((net.links_df[net.links_df["managed"] == 1]).index)
    print("New # of ML links in the network:", new_ml_links)

    assert new_ml_links == existing_ml_links + len(selected_link_indices)

    print("--Finished:", request.node.name)
def read_project_cards(card_dir: str = CARD_DIR) -> list:
    """
    Returns a list of project cards from a directory.

    Args:
        card_dir: a folder location storing project cards

    Returns:
        List of tuples, with the ProjectCard and card filename

    """

    card_file_list = []
    for (dirpath, dirnames, filenames) in os.walk(card_dir):
        for filename in filenames:
            name, extension = os.path.splitext(filename)
            if extension in [".yml", ".yaml"]:
                card_file = os.path.join(dirpath, filename)
                card = ProjectCard.read(card_file, validate=False)
                card_file_list.append((card, card_file))

    return card_file_list
Exemple #29
0
def test_highway_change_project_card_valid(request, logfilename):
    print("\n--Starting:", request.node.name)

    print("Reading: {}".format(logfilename))
    lf = Project.read_logfile(logfilename)
    test_project = Project.create_project(roadway_log_file=logfilename,
                                          base_roadway_dir=ROADWAY_DIR)

    test_project.write_project_card(
        os.path.join(
            SCRATCH_DIR,
            "t_" + os.path.splitext(os.path.basename(logfilename))[0] + ".yml",
        ))

    from network_wrangler import ProjectCard

    valid = ProjectCard.validate_project_card_schema(
        os.path.join(
            SCRATCH_DIR,
            "t_" + os.path.splitext(os.path.basename(logfilename))[0] + ".yml",
        ))

    assert valid == True
Exemple #30
0
def test_apply_summary_wrappers(request):
    print("\n--Starting:", request.node.name)

    card_filenames = [
        "3_multiple_roadway_attribute_change.yml",
        "multiple_changes.yml",
        "4_simple_managed_lane.yml",
    ]

    project_card_directory = os.path.join(STPAUL_DIR, "project_cards")

    project_cards_list = [
        ProjectCard.read(os.path.join(project_card_directory, filename),
                         validate=False) for filename in card_filenames
    ]

    base_scenario = {
        "road_net":
        RoadwayNetwork.read(
            link_file=STPAUL_LINK_FILE,
            node_file=STPAUL_NODE_FILE,
            shape_file=STPAUL_SHAPE_FILE,
            fast=True,
        ),
        "transit_net":
        TransitNetwork.read(STPAUL_DIR),
    }

    my_scenario = Scenario.create_scenario(
        base_scenario=base_scenario, project_cards_list=project_cards_list)

    my_scenario.apply_all_projects()

    my_scenario.scenario_summary()

    print("--Finished:", request.node.name)