-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTree.py
114 lines (104 loc) · 4.97 KB
/
Tree.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import subprocess
import sys
import os
import shutil
import pydot
from struct import pack
import numpy as np
import pandas as pd
import seaborn as sns
def m_Max_Time(root,run,workspaces):
input_file = os.path.join(root,workspaces[run])
with open(input_file, 'rb') as f:
try:
data_pickle = pickle.load(f)
except:
data_pickle = pd.read_pickle(input_file)
return '%s'%(str(pd.DataFrame(data_pickle['Max']).tm.max()))
def Bug_tcheque(run,Bugs):
if run in Bugs:
return True
else:
return False
def Map_Old_New_Name(run):
def mapping_1(f):
return f[0]+str(float(f[1:].replace('D','e')))
def mapping_2(f):
return f[0:2]+str(float(f[2:].replace('D','e')))
def mapping_3(f):
return f[0:1]+str(1./float(f[1:].replace('D','e')))
bug = run.split('_')[:-1]
bug_n = []
if len([f for f in bug if f[0]=='G']) == 1:
bug_n.append(mapping_1(bug[0]).replace('E','el'))
bug_n.append(mapping_1(bug[1]).replace('G','gr'))
bug_n.append(mapping_1(bug[4]).replace('D','de'))
bug_n.append(mapping_1(bug[7]).replace('S','si'))
bug_n.append(mapping_1(bug[2]).replace('N','nu'))
bug_n.append(mapping_3(bug[3]).replace('P','Pe'))
bug_n.append(mapping_1(bug[5]).replace('C','Ps'))
bug_n.append(mapping_1(bug[6]).replace('R','N1'))
bug_n.append(mapping_2(bug[10]).replace('Dt','Dt'))
bug_n.append(mapping_2(bug[8]))
bug_n.append(mapping_2(bug[9]).replace('Ep','ep'))
else:
bug_n.append(mapping_1(bug[0]).replace('E','el'))
bug_n.append(mapping_1(bug[1]).replace('G','gr'))
bug_n.append(mapping_1(bug[4]).replace('D','de'))
bug_n.append(mapping_1(bug[9]).replace('S','si'))
bug_n.append(mapping_1(bug[2]).replace('N','nu'))
bug_n.append(mapping_3(bug[3]).replace('P','Pe'))
bug_n.append(mapping_1(bug[5]).replace('C','Ps'))
bug_n.append(mapping_1(bug[6]).replace('R','N1'))
bug_n.append(mapping_1(bug[7]).replace('G','ga'))
bug_n.append(mapping_1(bug[8]).replace('I','In'))
bug_n.append(mapping_2(bug[12]).replace('Dt','Dt'))
bug_n.append(mapping_2(bug[10]))
bug_n.append(mapping_2(bug[11]).replace('Ep','ep'))
bug_new = '_'.join(bug_n)
return bug_new
def Draw_Tree(Root,Startup_Node):
List = [f for f in os.listdir(Root) if f[:2] == 'el']
Runs = ['_'.join([g for g in f.split('_') if g[0]!='M']) for f in List] # On enleve M
workspaces = dict(zip(Runs,List))
Bugs = [f for f in os.listdir(os.path.join(Root,'Run_Code')) if f[0] == 'E' and f.endswith('BUG')]
Bugs = map(Map_Old_New_Name,Bugs)
graph = pydot.Dot(graph_type='graph')
Level = [f[:2] for f in Runs[0].split('_')]
color = ['#'+pack("BBB",*tuple(np.array(triplet)*255)).encode('hex') for triplet in sns.color_palette('deep',len(Level))]
def Visit_Branch(List_Run,Parent_Node):
for key_node,label_node in Parent_Node.iteritems():
print key_node
Level_Parent = Level.index(key_node[:2])
Child_List = list(set([key.split('_')[Level_Parent+1] for key in List_Run if key.split('_')[Level_Parent] == key_node]))
Tree_Child = [f for f in List_Run if f.split('_')[Level_Parent] == key_node]
Child = dict(zip(Child_List,[label_node+'_'+f for f in Child_List]))
node_parent = pydot.Node(label_node, label= key_node,style="filled", fillcolor=color[Level_Parent])
graph.add_node(node_parent)
for key_child,label_child in Child.iteritems():
node_child = pydot.Node(label_child,label = key_child)
graph.add_node(node_child)
graph.add_edge(pydot.Edge(node_parent, node_child))
if not Child_List[0][:2] == 'ep':
Visit_Branch(Tree_Child,Child)
else:
for key_child,label_child in Child.iteritems():
node_final_l = label_node+key_child
print Child.values()[0] in Bugs
if Child.values()[0] in Bugs:
color_Bug = 'red'
else:
color_Bug = 'white'
node_final = pydot.Node(node_final_l,
label = str(m_Max_Time(Root,label_child,workspaces)),
style="filled",
fillcolor=color_Bug)
graph.add_node(node_final)
graph.add_edge(pydot.Edge(label_child, node_final))
print m_Max_Time(Root,label_child,workspaces)
Visit_Branch(Runs,Startup_Node)
graph.write_pdf(os.path.join(Root,'Tree_Runs.pdf'))
Root = '/Users/thorey/Documents/These/Projet/Refroidissement/Skin_Model/SCAPAD'
Root = os.path.join(Root,'ELASGRAV/MSkin_TSc_Newton_HSc_Newton_RBercovici','Workspace_2015-07-05_0')
Startup_Node = {'el1.0':'el1.0'}
Draw_Tree(Root,Startup_Node)