Skip to content

Commit a829e91

Browse files
committedSep 28, 2023
helper to extract node ids as integers
1 parent aed1636 commit a829e91

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎nrel/hive/model/roadnetwork/link_id.py

+23
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ def extract_node_ids(
4545
return None, (src, dst)
4646

4747

48+
def extract_node_ids_int(
49+
link_id: LinkId
50+
) -> Tuple[Optional[Exception], Optional[Tuple[int, int]]]:
51+
"""node ids can be strings for the haversine case but for networkx graphs they must be
52+
integers as they are treated as indices.
53+
54+
:param link_id: link id to read
55+
:type link_id: LinkId
56+
:return: _description_
57+
:rtype: Tuple[Optional[Exception], Optional[Tuple[int, int]]]
58+
"""
59+
err, ids = extract_node_ids(link_id)
60+
if err is not None or ids is None:
61+
return err, None
62+
else:
63+
try:
64+
src_str, dst_str = ids
65+
src = int(src_str)
66+
dst = int(dst_str)
67+
return None, (src, dst)
68+
except ValueError as e:
69+
return e, None
70+
4871
def reverse_link_id(
4972
link_id: LinkId,
5073
) -> Tuple[Optional[Exception], Optional[LinkId]]:

0 commit comments

Comments
 (0)
Please sign in to comment.