Skip to content

Commit

Permalink
visualization for graph- v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriaanRol committed Mar 15, 2018
1 parent 16df5f2 commit 04df666
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
47 changes: 42 additions & 5 deletions autodepgraph/graph_v2.py
Expand Up @@ -41,6 +41,10 @@ def __init__(self, name, cfg_plot_mode=None,
self._calib_cnt = 0
self._check_cnt = 0

def fresh_copy(self):
return AutoDepGraph_DAG(name=self.name,
cfg_plot_mode=self.cfg_plot_mode)

def add_node(self, node_for_adding, **attr):
"""
"""
Expand Down Expand Up @@ -75,12 +79,27 @@ def add_edge(self, u_of_edge, v_of_edge, **attr):
assert v_of_edge in self.nodes()
super().add_edge(u_of_edge, v_of_edge, **attr)

def get_node_state(self, node_name):
Delta_T=(datetime.now() -
self.nodes[node_name]['last_update']).total_seconds()
if ( Delta_T> self.nodes[node_name]['timeout']):
self.nodes[node_name]['state'] = 'unknown'
return self.nodes[node_name]['state']

def set_node_state(self, node_name, state):
assert state in ['good', 'needs calibration',
'bad', 'unknown', 'active']
self.nodes[node_name]['state'] = state
self.nodes[node_name]['last_update'] = datetime.now()

def is_manual_node(self, node_name):
if 'manual' in self.nodes[node_name]['calibrate_function']:
return True
elif 'NotImplemented' in self.nodes[node_name]['calibrate_function']:
return True
else:
return False

def maintain_node(self, node, verbose=True):
"""
Maintaining a node attempts to go from any state to a good state.
Expand All @@ -93,19 +112,19 @@ def maintain_node(self, node, verbose=True):
good state
2. perform the "check" experiment on the node itself. This quick
check
3. Perform calibration and second round of executing dependencies
3. Perform calibration and second round of maintaining dependencies
"""
self._exec_cnt += 1
if verbose:
print('Executing node "{}".'.format(node))
print('Maintaining node "{}".'.format(node))

# 1. Going over the states of all the required nodes and ensure
# these are all in a 'Good' state.
for req_node_name in self.adj[node]:
req_node_state = self.nodes[req_node_name]['state']
if req_node_state in ['good', 'unknown']:
continue # assume req_node is in a good state
else: # executing the node to ensure it is in a good state
else: # maintaining the node to ensure it is in a good state
req_node_state = self.maintain_node(req_node_name,
verbose=verbose)
if req_node_state == 'bad':
Expand Down Expand Up @@ -137,7 +156,7 @@ def maintain_node(self, node, verbose=True):
# if the state is bad it will execute *all* dependencies. Even
# the ones that were updated before.
if verbose:
print('State of node "{}" is bad, executing all required'
print('State of node "{}" is bad, maintaining all required'
' nodes.'.format(node))
for req_node_name in self.adj[node]:
req_node_state = self.maintain_node(req_node_name,
Expand Down Expand Up @@ -249,8 +268,24 @@ def draw_svg(self, filename: str=None):
"""
if filename is None:
filename = self.cfg_svg_filename
self._update_drawing_attrs()
vis.draw_graph_svg(self, filename)

def _update_drawing_attrs(self):
for node_name, node_attrs in self.nodes(True):

state = self.get_node_state(node_name)
color = vis.state_cmap[state]
shape = 'hexagon' if self.is_manual_node(node_name) else 'ellipse'
attr_dict = {'shape': shape,
'style': 'filled',
'color': color,
# 'fixedsize':'shape',
# 'fixedsize' : b"true",
'fixedsize' : "false",
'fillcolor': color}
node_attrs.update(attr_dict)


def _get_function(funcStr):

Expand All @@ -261,7 +296,7 @@ def _get_function(funcStr):
instr_name, method = funcStr.split('.')
instr = Instrument.find_instrument(instr_name)
f = getattr(instr, method)
except Exception:
except Exception as e:
f = get_function_from_module(funcStr)
return f

Expand All @@ -274,3 +309,5 @@ def get_function_from_module(funcStr):
mod = import_module(module_name)
f = getattr(mod, funcStr[(split_idx+1):])
return f


3 changes: 2 additions & 1 deletion autodepgraph/visualization.py
Expand Up @@ -3,7 +3,8 @@
from autodepgraph.pg_visualization.pg_remotegraph import pg_DiGraph_window

# Colormap used to map states to node colors
state_cmap = {'unknown': '#7f7f7f', # middle gray
state_cmap = {#'unknown': '#7f7f7f', # middle gray
'unknown': '#D3D3D3', # light gray
'active': '#1f77b4', # muted blue
'good': '#2ca02c', # cooked asparagus green
'needs calibration': '#ff7f0e', # safety orange
Expand Down

0 comments on commit 04df666

Please sign in to comment.