Skip to content
Snippets Groups Projects
Commit 61124ab3 authored by George Marchment's avatar George Marchment
Browse files

Added first implementation of the coloured edges in the graph (corresponding...

Added first implementation of the coloured edges in the graph (corresponding to most used conditions)
parent 6ec7a47e
No related branches found
No related tags found
No related merge requests found
Pipeline #14662 failed with stage
in 2 minutes and 11 seconds
...@@ -116,7 +116,7 @@ class Code: ...@@ -116,7 +116,7 @@ class Code:
to_replace.append((all, new)) to_replace.append((all, new))
elif(body==""): elif(body==""):
char, pos = get_next_element_caracter(temp_code, end_line) char, pos = get_next_element_caracter(temp_code, end_line)
if(char!="{"): if(char!="{" and temp_code[pos:pos+3] not in ['"""', "'''"]):
raise BioFlowInsightError(f"The condition '({extracted_condition}' was not extracted correctly. Make sure the condition follows the correct syntaxe.", type="Unable to extract condition") raise BioFlowInsightError(f"The condition '({extracted_condition}' was not extracted correctly. Make sure the condition follows the correct syntaxe.", type="Unable to extract condition")
......
...@@ -200,20 +200,54 @@ class Graph(): ...@@ -200,20 +200,54 @@ class Graph():
node_2_processes[node] = list(set(temp)) node_2_processes[node] = list(set(temp))
links_added = [] #%2x%2x%2x
def add_edges(dico): colours = ["#ffbe00", "#0055c8", "#6e6e00", "#a0006e", "#ff5a00", "#82dc73", "#ff82b4", "#d282be", "#d2d200", "#dc9600", "#6e491e", "#00643c", "#82c8e6", "#640082"]
links_added, links_added__with_conditions= [], []
def add_edges(dico, condition, checking_conditions, index = 0):
for node in dico['nodes']: for node in dico['nodes']:
edges = node_2_processes[node['id']] edges = node_2_processes[node['id']]
for B in edges: for B in edges:
link = f"{node['id']} -> {B}" link = f"{node['id']} -> {B}"
if(link not in links_added): link_with_condition = f"{node['id']} -> {B} ({condition})"
dico['edges'].append({'A': node['id'], 'B': B, 'label': ''}) if(link_with_condition not in links_added__with_conditions):
links_added.append(link) if(checking_conditions):
p1, p2 = get_object(node['id']), get_object(B)
conditions_p1, conditions_p2 = p1.get_call().get_block().get_all_conditions(conditions = {}), p2.get_call().get_block().get_all_conditions(conditions = {})
for c1 in conditions_p1:
#TODO -> need to check the condition in a smarter way
if(c1.get_value()==condition):
#for c2 in conditions_p2:
# if(c2.get_value()==condition):
if(link not in links_added):
dico['edges'].append({'A': node['id'], 'B': B, 'label': '', "colour": colours[index], "condition": condition})
links_added.append(link)
links_added.append(link_with_condition)
else:
checking_conditions = False
else:
if(link not in links_added):
dico['edges'].append({'A': node['id'], 'B': B, 'label': ''})
links_added.append(link)
for sub in dico['subworkflows']: for sub in dico['subworkflows']:
add_edges(dico["subworkflows"][sub]) add_edges(dico["subworkflows"][sub], condition, checking_conditions, index=index)
return checking_conditions
if(self.workflow.get_duplicate_status()):
add_edges(dico) checking_conditions = True
most_influential_conditions = self.workflow.get_most_influential_conditions()
list_most_influential_conditions = list(most_influential_conditions.keys())
index = 0
while(checking_conditions and\
index<len(list_most_influential_conditions) and \
index<5):
condition = list_most_influential_conditions[index]
checking_conditions = add_edges(dico, condition, checking_conditions, index=index)
index+=1
add_edges(dico, condition="", checking_conditions=False)
else:
add_edges(dico, condition="", checking_conditions=False)
self.dico_process_dependency_graph = dico self.dico_process_dependency_graph = dico
......
...@@ -48,10 +48,14 @@ def add_nodes(dot, dico, label_node = True): ...@@ -48,10 +48,14 @@ def add_nodes(dot, dico, label_node = True):
def add_edges(dot, dico, label_edge = True): def add_edges(dot, dico, label_edge = True):
for e in dico["edges"]: for e in dico["edges"]:
try:
colour = e['colour']
except:
colour = "black"
if(label_edge): if(label_edge):
dot.edge(e['A'], e['B'], label= e['label']) dot.edge(e['A'], e['B'], label= e['label'], color=colour)
else: else:
dot.edge(e['A'], e['B']) dot.edge(e['A'], e['B'], color=colour)
for sub in dico["subworkflows"]: for sub in dico["subworkflows"]:
with dot.subgraph(name="cluster"+sub) as c: with dot.subgraph(name="cluster"+sub) as c:
...@@ -139,11 +143,42 @@ def fill_dot_2(dot, dico, label_node = True, label_edge = True): ...@@ -139,11 +143,42 @@ def fill_dot_2(dot, dico, label_node = True, label_edge = True):
fill_dot(c, dico["subworkflows"][sub], label_node, label_edge) fill_dot(c, dico["subworkflows"][sub], label_node, label_edge)
c.attr(label=sub) c.attr(label=sub)
def add_legend(dico, dot):
def get_all_conditions_rec(dico, conditions):
for e in dico["edges"]:
try:
con = e['condition']
colour = e['colour']
conditions[con] = colour
except:
None
for sub in dico["subworkflows"]:
get_all_conditions_rec(dico["subworkflows"][sub], conditions)
def get_all_conditions(dico):
conditions = {}
get_all_conditions_rec(dico, conditions)
return conditions
conditions = get_all_conditions(dico)
if(len(conditions)!=0):
with dot.subgraph(name="cluster"+"_123424653") as c:
index = 0
for con in conditions:
c.node(f'{id(dot)}_{index}_0', style = 'invis')
c.node(f'{id(dot)}_{index}_1', style = 'invis')
c.edge(f'{id(dot)}_{index}_0', f'{id(dot)}_{index}_1', color=conditions[con], label=con)
index += 1
c.attr(label="Legend")
def generate_pos_graph(filename, dico, relevant_nodes = -1, render_graphs = True): def generate_pos_graph(filename, dico, relevant_nodes = -1, render_graphs = True):
if(render_graphs): if(render_graphs):
dot = graphviz.Digraph() dot = graphviz.Digraph()
dot.attr(rankdir='LR') dot.attr(rankdir='LR')
fill_dot(dot, dico, False, False) fill_dot(dot, dico, False, False)
bool_add_legend = True
if(bool_add_legend):
add_legend(dico, dot)
dot.format = 'dot' dot.format = 'dot'
dot.render(filename=f'{filename}_pos') dot.render(filename=f'{filename}_pos')
dot.render(filename=f'{filename}_pos', outfile=f'{filename}_pos.png') dot.render(filename=f'{filename}_pos', outfile=f'{filename}_pos.png')
...@@ -159,6 +194,9 @@ def generate_graph_dot(filename, dico, label_node = True, label_edge = True, ren ...@@ -159,6 +194,9 @@ def generate_graph_dot(filename, dico, label_node = True, label_edge = True, ren
else: else:
fill_dot(dot, dico, True, label_edge) fill_dot(dot, dico, True, label_edge)
#metro_dot(dot, dico, relevant_nodes = relevant_nodes) #metro_dot(dot, dico, relevant_nodes = relevant_nodes)
bool_add_legend = False
if(bool_add_legend):
add_legend(dico, dot)
dot.save(filename=f'{filename}.dot') dot.save(filename=f'{filename}.dot')
#dot.format = 'dot' #dot.format = 'dot'
#dot.render(filename=f'{filename}_pos') #dot.render(filename=f'{filename}_pos')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment