Skip to content

Commit 340a7b7

Browse files
committed
minor bugs
1 parent e1d19cb commit 340a7b7

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

nipype/utils/draw_gantt_chart.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def calculate_resources(events, resource):
102102
for event in events:
103103
all_res = 0
104104
if event['type'] == "start":
105-
all_res =+ int(float(event[resource]))
105+
all_res += int(float(event[resource]))
106106
current_time = event['start'];
107107
elif event['type'] == "finish":
108-
all_res+ int(float(event[resource]))
108+
all_res+= int(float(event[resource]))
109109
current_time = event['finish'];
110110

111111
res[current_time] = all_res
@@ -136,15 +136,18 @@ def draw_lines(start, total_duration, minute_scale, scale):
136136
return result
137137

138138

139-
def draw_nodes(start, nodes, cores, scale, colors):
139+
def draw_nodes(start, nodes, cores, minute_scale, space_between_minutes, colors):
140140
result = ''
141141
end_times = [datetime.datetime(start.year, start.month, start.day, start.hour, start.minute, start.second) for x in range(cores)]
142142

143+
scale = float(space_between_minutes/float(minute_scale))
144+
space_between_minutes = float(space_between_minutes/scale)
145+
143146
for node in nodes:
144147
node_start = node['start']
145148
node_finish = node['finish']
146-
offset = ((node_start - start).total_seconds() / 60) * scale + 220
147-
scale_duration = (node['duration'] / 60) * scale
149+
offset = ((node_start - start).total_seconds() / 60) * scale * space_between_minutes + 220
150+
scale_duration = (node['duration'] / 60) * scale * space_between_minutes
148151
if scale_duration < 5:
149152
scale_duration = 5
150153

@@ -159,11 +162,15 @@ def draw_nodes(start, nodes, cores, scale, colors):
159162
node_finish.hour,
160163
node_finish.minute,
161164
node_finish.second)
162-
#end_times[j]+= datetime.timedelta(microseconds=node_finish.microsecond)
165+
163166
break
164167
color = random.choice(colors)
165-
new_node = "<div class='node' style=' left:" + str(left) + "px;top: " + str(offset) + "px;height:" + str(scale_duration) + "px; background-color: " + color + " 'title='" + node['name'] +'\nduration: ' + str(node['duration']/60) + '\nstart: ' + node['start'].strftime("%Y-%m-%d %H:%M:%S") + '\nend: ' + node['finish'].strftime("%Y-%m-%d %H:%M:%S") + "'></div>";
168+
n_start = node['start'].strftime("%Y-%m-%d %H:%M:%S")
169+
n_finish = node['finish'].strftime("%Y-%m-%d %H:%M:%S")
170+
n_dur = node['duration']/60
171+
new_node = "<div class='node' style='left:%spx;top:%spx;height:%spx;background-color:%s;'title='%s\nduration:%s\nstart:%s\nend:%s'></div>"%(left, offset, scale_duration, color, node['name'], n_dur, n_start, n_finish)
166172
result += new_node
173+
167174
return result
168175

169176
def draw_thread_bar(threads,space_between_minutes, minute_scale):
@@ -281,10 +288,13 @@ def generate_gantt_chart(logfile, cores, minute_scale=10,
281288

282289
html_string += '<p>Start: '+ result[0]['start'].strftime("%Y-%m-%d %H:%M:%S") +'</p>'
283290
html_string += '<p>Finish: '+ last_node['finish'].strftime("%Y-%m-%d %H:%M:%S") +'</p>'
284-
html_string += '<p>Duration: '+ str(duration/60) +' minutes</p>'
291+
html_string += '<p>Duration: '+ "{0:.2f}".format(duration/60) +' minutes</p>'
285292
html_string += '<p>Nodes: '+str(len(result))+'</p>'
286293
html_string += '<p>Cores: '+str(cores)+'</p>'
287294

295+
html_string += draw_lines(start, duration, minute_scale, space_between_minutes)
296+
html_string += draw_nodes(start, result, cores, minute_scale,space_between_minutes, colors)
297+
288298
result = log_to_events(logfile)
289299
threads = calculate_resources(result, 'num_threads')
290300
html_string += draw_thread_bar(threads, space_between_minutes, minute_scale)

0 commit comments

Comments
 (0)