@@ -102,10 +102,10 @@ def calculate_resources(events, resource):
102
102
for event in events :
103
103
all_res = 0
104
104
if event ['type' ] == "start" :
105
- all_res = + int (float (event [resource ]))
105
+ all_res += int (float (event [resource ]))
106
106
current_time = event ['start' ];
107
107
elif event ['type' ] == "finish" :
108
- all_res + int (float (event [resource ]))
108
+ all_res += int (float (event [resource ]))
109
109
current_time = event ['finish' ];
110
110
111
111
res [current_time ] = all_res
@@ -136,15 +136,18 @@ def draw_lines(start, total_duration, minute_scale, scale):
136
136
return result
137
137
138
138
139
- def draw_nodes (start , nodes , cores , scale , colors ):
139
+ def draw_nodes (start , nodes , cores , minute_scale , space_between_minutes , colors ):
140
140
result = ''
141
141
end_times = [datetime .datetime (start .year , start .month , start .day , start .hour , start .minute , start .second ) for x in range (cores )]
142
142
143
+ scale = float (space_between_minutes / float (minute_scale ))
144
+ space_between_minutes = float (space_between_minutes / scale )
145
+
143
146
for node in nodes :
144
147
node_start = node ['start' ]
145
148
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
148
151
if scale_duration < 5 :
149
152
scale_duration = 5
150
153
@@ -159,11 +162,15 @@ def draw_nodes(start, nodes, cores, scale, colors):
159
162
node_finish .hour ,
160
163
node_finish .minute ,
161
164
node_finish .second )
162
- #end_times[j]+= datetime.timedelta(microseconds=node_finish.microsecond)
165
+
163
166
break
164
167
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' ] + '\n duration: ' + str (node ['duration' ]/ 60 ) + '\n start: ' + node ['start' ].strftime ("%Y-%m-%d %H:%M:%S" ) + '\n end: ' + 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\n duration:%s\n start:%s\n end:%s'></div>" % (left , offset , scale_duration , color , node ['name' ], n_dur , n_start , n_finish )
166
172
result += new_node
173
+
167
174
return result
168
175
169
176
def draw_thread_bar (threads ,space_between_minutes , minute_scale ):
@@ -281,10 +288,13 @@ def generate_gantt_chart(logfile, cores, minute_scale=10,
281
288
282
289
html_string += '<p>Start: ' + result [0 ]['start' ].strftime ("%Y-%m-%d %H:%M:%S" ) + '</p>'
283
290
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>'
285
292
html_string += '<p>Nodes: ' + str (len (result ))+ '</p>'
286
293
html_string += '<p>Cores: ' + str (cores )+ '</p>'
287
294
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
+
288
298
result = log_to_events (logfile )
289
299
threads = calculate_resources (result , 'num_threads' )
290
300
html_string += draw_thread_bar (threads , space_between_minutes , minute_scale )
0 commit comments