-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility_functions.py
More file actions
30 lines (21 loc) · 1.03 KB
/
utility_functions.py
File metadata and controls
30 lines (21 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## Function to extract source node properties whilst mapping connections through the graph
def get_node_props(node: str, results: list[dict], kind: str) -> tuple:
"""
This function takes a destination node and a list of source node properties and extracts the
relevant source data
Args:
dest_node (str): the identifier of the current node
results (list[dict]): list of potential source nodes through which to search
kind (str): node type indicator, either "source_node" or "dest_node"
Returns:
tuple: source weight_product, layer and tree_path (extracted from source node dictionary)
"""
node_types = ['source_node', 'dest_node']
if kind not in node_types:
raise ValueError("argument 'kind' must have value 'source_node' or 'dest_node'")
node_types.remove(kind)
for r in results:
if r[node_types[0]] == node:
return r['weight_product'], r['layer'], r['tree_path']
# Return default if no value found
return 1.0, 0, node