Skip to content

Commit 8fce738

Browse files
committed
partial commit to gantt chart
1 parent 340a7b7 commit 8fce738

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

nipype/utils/draw_gantt_chart.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,20 @@ def log_to_dict(logfile):
100100
def calculate_resources(events, resource):
101101
res = OrderedDict()
102102
for event in events:
103-
all_res = 0
103+
all_res = 0.0
104104
if event['type'] == "start":
105-
all_res += int(float(event[resource]))
105+
if resource in event and event[resource] != 'Unkown':
106+
all_res += float(event[resource])
106107
current_time = event['start'];
107108
elif event['type'] == "finish":
108-
all_res+= int(float(event[resource]))
109+
if resource in event and event[resource] != 'Unkown':
110+
all_res+= float(event[resource])
109111
current_time = event['finish'];
110-
111112
res[current_time] = all_res
112113

113114
timestamps = [dateutil.parser.parse(ts) for ts in res.keys()]
114-
time_series = pd.Series(res.values(), timestamps)
115+
time_series = pd.Series(data=res.values(), index=timestamps)
116+
#TODO: pandas is removing all data values somewhere here
115117
interp_seq = pd.date_range(time_series.index[0], time_series.index[-1], freq='S')
116118
interp_time_series = time_series.reindex(interp_seq)
117119
interp_time_series = interp_time_series.fillna(method='ffill')
@@ -164,7 +166,9 @@ def draw_nodes(start, nodes, cores, minute_scale, space_between_minutes, colors)
164166
node_finish.second)
165167

166168
break
167-
color = random.choice(colors)
169+
color = random.choice(colors)
170+
if 'error' in node:
171+
color = 'red'
168172
n_start = node['start'].strftime("%Y-%m-%d %H:%M:%S")
169173
n_finish = node['finish'].strftime("%Y-%m-%d %H:%M:%S")
170174
n_dur = node['duration']/60
@@ -173,20 +177,22 @@ def draw_nodes(start, nodes, cores, minute_scale, space_between_minutes, colors)
173177

174178
return result
175179

176-
def draw_thread_bar(threads,space_between_minutes, minute_scale):
180+
def draw_thread_bar(threads,space_between_minutes, minute_scale, color):
177181
result = "<p class='time' style='top:198px;left:900px;'>Threads</p>"
178182

179183
scale = float(space_between_minutes/float(minute_scale))
180184
space_between_minutes = float(space_between_minutes/60.0)
185+
181186
for i in range(len(threads)):
187+
#print threads[i]
182188
width = threads[i] * 10
183189
t = (float(i*scale*minute_scale)/60.0) + 220
184190
bar = "<div class='bar' style='height:"+ str(space_between_minutes) + "px;width:"+ str(width) +"px;left:900px;top:"+str(t)+"px'></div>"
185191
result += bar
186192

187193
return result
188194

189-
def draw_memory_bar(memory, space_between_minutes, minute_scale):
195+
def draw_memory_bar(memory, space_between_minutes, minute_scale, color):
190196
result = "<p class='time' style='top:198px;left:1200px;'>Memory</p>"
191197

192198
scale = float(space_between_minutes/float(minute_scale))
@@ -195,7 +201,7 @@ def draw_memory_bar(memory, space_between_minutes, minute_scale):
195201
for i in range(len(memory)):
196202
width = memory[i] * 10
197203
t = (float(i*scale*minute_scale)/60.0) + 220
198-
bar = "<div class='bar' style='height:"+ str(space_between_minutes) + "px;width:"+ str(width) +"px;left:1200px;top:"+str(t)+"px'></div>"
204+
bar = "<div class='bar' style='background-color:"+color+";height:"+ str(space_between_minutes) + "px;width:"+ str(width) +"px;left:1200px;top:"+str(t)+"px'></div>"
199205
result += bar
200206

201207
return result
@@ -265,8 +271,8 @@ def generate_gantt_chart(logfile, cores, minute_scale=10,
265271
266272
.bar{
267273
position: absolute;
268-
background-color: #80E680;
269274
height: 1px;
275+
opacity: 0.7;
270276
}
271277
272278
.dot{
@@ -296,11 +302,19 @@ def generate_gantt_chart(logfile, cores, minute_scale=10,
296302
html_string += draw_nodes(start, result, cores, minute_scale,space_between_minutes, colors)
297303

298304
result = log_to_events(logfile)
299-
threads = calculate_resources(result, 'num_threads')
300-
html_string += draw_thread_bar(threads, space_between_minutes, minute_scale)
301305

302-
memory = calculate_resources(result, 'estimated_memory_gb')
303-
html_string += draw_memory_bar(memory, space_between_minutes, minute_scale)
306+
#threads_estimated = calculate_resources(result, 'num_threads')
307+
#html_string += draw_thread_bar(threads_estimated, space_between_minutes, minute_scale, '#90BBD7')
308+
309+
#threads_real = calculate_resources(result, 'runtime_threads')
310+
#html_string += draw_thread_bar(threads_real, space_between_minutes, minute_scale, '#03969D')
311+
312+
313+
#memory_estimated = calculate_resources(result, 'estimated_memory_gb')
314+
#html_string += draw_memory_bar(memory_estimated, space_between_minutes, minute_scale, '#90BBD7')
315+
316+
memory_real = calculate_resources(result, 'runtime_memory_gb')
317+
html_string += draw_memory_bar(memory_real, space_between_minutes, minute_scale, '#03969D')
304318

305319

306320
#finish html
@@ -311,4 +325,7 @@ def generate_gantt_chart(logfile, cores, minute_scale=10,
311325
#save file
312326
html_file = open(logfile +'.html', 'wb')
313327
html_file.write(html_string)
314-
html_file.close()
328+
html_file.close()
329+
330+
331+
generate_gantt_chart('/home/caroline/Downloads/callback_0051472.log',8)

0 commit comments

Comments
 (0)