Skip to content

Commit

Permalink
(RSM) clean up code, iterate thru attributes, improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mwe-sandag committed May 4, 2023
1 parent 8873cb2 commit 4246ec6
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/main/emme/toolbox/import/import_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,16 @@ def _create_base_net(self, data, network, mode_callback, centroid_callback, arc_
network_editor_yaml_file = FILE_NAMES["NETWORK_EDITS"]
network_editor_bool = False
network_editor_yaml_path = _join(self.source, network_editor_yaml_file)
self._log.append({"type": "header", "content": "__Network Edits"})
if os.path.exists(network_editor_yaml_path):
network_editor_bool = True
self._log.append({"type": "text", "content": "%s" % network_editor_yaml_path})
with open(network_editor_yaml_path, "r") as stream:
network_editor_data = yaml.safe_load(stream)
self._log.append({"type": "text", "content": "loaded YAML"})
self._log.append({"type": "text", "content": "Successfully loaded Network Edits YAML"})
self._log.append({"type": "text", "content": "\tYAML Path: %s" % network_editor_yaml_path})
else:
self._log.append({"type": "text", "content": "NO Network Edits YAML to load"})


# Create nodes and links
for arc in data:
if not arc_filter(arc):
Expand All @@ -807,15 +809,13 @@ def _create_base_net(self, data, network, mode_callback, centroid_callback, arc_
new_node_id += 1

#arc edits to raw_network
# if network_editor_bool:
if arc_id_name == "HWYCOV-ID":
for link_edits in network_editor_data.get('raw_network',[]):
if arc["HWYCOV-ID"] in link_edits.get("@tcov_id",[]):
#could explore using set_attribute_values() method in EMME API
try:
arc[link_edits["attribute_to_edit"]] = link_edits["new_value"]
except KeyError:
setattr(arc, link_edits["attribute_to_edit"], link_edits["new_value"])
if network_editor_bool:
if arc_id_name == "HWYCOV-ID":
for link_edits in network_editor_data.get('raw_network',[]):
if arc["HWYCOV-ID"] in link_edits.get("@tcov_id",[]):
#could explore using set_attribute_values() method in EMME API
for attribute,value in link_edits["attributes_to_edit"].items():
arc[attribute] = value

modes = mode_callback(arc)
link = network.create_link(i_node, j_node, modes)
Expand Down Expand Up @@ -1235,12 +1235,9 @@ def get_line(line_id):
for link_edits in network_editor_data.get('transit',[]):
for link in network.links():
if link["@tcov_id"] in link_edits.get("@tcov_id",[]):
#this format permits only one attribute change per edit
#could explore using set_attribute_values() method in EMME API
try:
link[link_edits["attribute_to_edit"]] = link_edits["new_value"]
except KeyError: #one of two solutions should probably be removed
setattr(link, link_edits["attribute_to_edit"], link_edits["new_value"])
for attribute,value in link_edits["attributes_to_edit"].items():
link[attribute] = value

self._log.append({"type": "text", "content": "Calculate derived transit attributes complete"})
return
Expand Down Expand Up @@ -2222,4 +2219,4 @@ def interchange_distance(orig_link, direction):
# IndexError if heap is empty
# case where start / end of highway, dist = 99
return 99
return orig_link["length"] / 2.0 + link_cost
return orig_link["length"] / 2.0 + link_cost

0 comments on commit 4246ec6

Please sign in to comment.