Skip to content

Commit 89a0059

Browse files
authored
Merge branch 'dev' into feat/transit-zone-label-tool
2 parents 79d41a8 + 177b7eb commit 89a0059

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

Scripts/emme_tools/helmet_link_printing.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class LinkPrinting(_m.Tool()):
1414
results_path = _m.Attribute(str)
15+
scenarios = _m.Attribute(list)
1516

1617
def __init__(self):
1718
"""Tool with click-button that can be imported in the Modeller GUI.
@@ -23,9 +24,12 @@ def __init__(self):
2324
def page(self):
2425
pb = _m.ToolPageBuilder(self)
2526
pb.title = "Print link attributes to file"
27+
pb.add_select_scenario(tool_attribute_name="scenarios",
28+
title="Scenarios:",
29+
note="Scenario selection for link printing.")
2630
pb.add_select_file(
2731
"results_path", "directory", file_filter="", start_path="",
28-
title="Directory to save file in:")
32+
title="Directory to save file(s) in:")
2933
if self.tool_run_msg:
3034
pb.add_html(self.tool_run_msg)
3135
return pb.render()
@@ -36,12 +40,16 @@ def run(self):
3640
def __call__(self):
3741
"""Print link attributes for current scenario.
3842
"""
39-
scen = _m.Modeller().scenario
40-
print_links(scen.get_network(), ResultsData(self.results_path))
41-
msg = "Link attributes for scenario {} printed to links.txt!".format(
42-
scen.id)
43+
if self.scenarios == []:
44+
self.scenarios.append(_m.Modeller().scenario)
45+
msg_strings = []
46+
for scen in self.scenarios:
47+
print_links(scen, ResultsData(self.results_path))
48+
scen_msg = f"Link attributes for scenario {scen.id} printed to links_{scen.id}.txt!"
49+
msg_strings.append(scen_msg)
50+
msg = ("<br>").join(msg_strings)
4351
self.write(msg)
44-
self.tool_run_msg = _m.PageBuilder.format_info(msg)
52+
self.tool_run_msg = _m.PageBuilder.format_info(msg, escape=False)
4553

4654
def write(self, message):
4755
_m.logbook_write(message)

Scripts/utils/print_links.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from utils.calc_noise import NoiseModel
2+
from datahandling.resultdata import ResultsData
23

3-
4-
def print_links(network, resultdata):
4+
def print_links(scenario, resultdata: ResultsData):
55
"""Dump link attributes with wkt coordinates to file.
66
77
Includes noise calculation (works well only when morning peak hour
@@ -10,12 +10,13 @@ def print_links(network, resultdata):
1010
1111
Parameters
1212
----------
13-
network : inro.emme.network.Network
14-
Network where whole-day results are stored
13+
scenario : inro.emme.database.scenario.Scenario
14+
Scenario with a network where whole-day results are stored
1515
"""
16+
network = scenario.get_network()
1617
attr_names = network.attributes("LINK")
1718
resultdata.print_line(
18-
"Link\tnode_i\tnode_j\tmodes" + "\t".join(attr_names) + "\tNoise_zone_width", "links")
19+
"Link\tnode_i\tnode_j\tmodes\t" + "\t".join(attr_names) + "\tNoise_zone_width", f"links_{scenario.id}")
1920
noisemodel = NoiseModel(
2021
network, ("@car_work_vrk", "@car_leisure_vrk", "@van_vrk"),
2122
("@truck_vrk", "@trailer_truck_vrk"))
@@ -27,6 +28,6 @@ def print_links(network, resultdata):
2728
attrs = "\t".join([str(link[attr]) for attr in attr_names])
2829
noise_zone_width = noisemodel.calc_noise(link)
2930
resultdata.print_line(
30-
wkt + "\t" + str(link.i_node.id) + "\t" + str(link.j_node.id)+ "\t" + modes + "\t" + attrs + "\t" + str(noise_zone_width), "links")
31+
wkt + "\t" + str(link.i_node.id) + "\t" + str(link.j_node.id)+ "\t" + modes + "\t" + attrs + "\t" + str(noise_zone_width), f"links_{scenario.id}")
3132
resultdata.flush()
3233

0 commit comments

Comments
 (0)