11 |
my $debug = 0; |
my $debug = 0; |
12 |
|
|
13 |
my $width = 600; # width of bar |
my $width = 600; # width of bar |
14 |
my $height = 12; # height of bar |
my $height = 15; # height of bar |
15 |
my $use_js = 1; # use JavaScript pop-up |
my $use_js = 1; # use JavaScript pop-up |
16 |
|
|
17 |
# status colors |
# status colors |
18 |
my %cols = ( |
my %cols = ( |
19 |
'In Progress' => '0,255,0', |
'In Progress' => '0,255,0', |
20 |
'In Progress/Failure' => '255,64,255', |
'In Progress/Failures' => '192,64,192', |
21 |
'In Progress/Errors' => '255,64,0', |
'In Progress/Errors' => '255,128,128', |
22 |
'Queuing' => '255,255,0', |
'Queuing' => '255,255,0', |
23 |
|
'Queuing/Errors' => '255,192,64', |
24 |
'Aborted' => '255,0,0', |
'Aborted' => '255,0,0', |
25 |
'Failed' => '255,0,0', |
'Failed' => '255,0,0', |
26 |
'Completed' => '64,255,64', |
'Completed' => '64,255,64', |
60 |
# keep count of each status |
# keep count of each status |
61 |
my %count; |
my %count; |
62 |
|
|
63 |
if (param('pic')) { |
if (path_info()) { |
64 |
print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n"; |
print "Content-type: image/png\nCache-Control: max-age=86400, must-revalidate\nExpires: ",scalar localtime(time()+24*60*60),"\nLast-Modified: ",scalar localtime(0),"\n"; |
65 |
# create picture using GD |
# create picture using GD |
66 |
use GD; |
use GD; |
67 |
my $im = new GD::Image(1,$height); |
my $im = new GD::Image(1,$height); |
68 |
my $back = $im->colorAllocate(255,255,255); |
my $back = $im->colorAllocate(255,255,255); |
69 |
$im->transparent($back); |
$im->transparent($back); |
70 |
my ($r,$g,$b) = split(/,/,param('pic')); |
my $col = path_info(); $col =~ s,/,,g; |
71 |
|
my ($r,$g,$b) = split(/,/,$col); |
72 |
my $col = $im->colorAllocate($r,$g,$b); |
my $col = $im->colorAllocate($r,$g,$b); |
73 |
$im->fill(0,0,$col); |
$im->fill(0,0,$col); |
74 |
|
print "Content-Length: ",length($im->png),"\n\n"; |
75 |
binmode STDOUT; |
binmode STDOUT; |
76 |
print $im->png; |
print $im->png; |
77 |
exit; |
exit; |
78 |
} |
} |
79 |
|
|
80 |
print "Content-type: text/html |
print "Content-type: text/html |
81 |
|
Cache-Control: max-age=60, must-revalidate |
82 |
|
|
83 |
<html> |
<html> |
84 |
<head> |
<head> |
85 |
<title>OmniBack Gantt: $from - $to</title>"; |
<title>OmniBack Gantt: $from - $to</title> |
86 |
|
<meta HTTP-EQUIV=\"Refresh\" CONTENT=600>"; |
87 |
if ($use_js) { |
if ($use_js) { |
88 |
print ' |
print ' |
89 |
<script type="text/javascript" language="javascript" src="1k.js"></script> |
<script type="text/javascript" language="javascript" src="1k.js"></script> |
117 |
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
118 |
} |
} |
119 |
|
|
120 |
print "<table>"; |
print "<table cellspacing=0 cellpadding=0>"; |
121 |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
122 |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
123 |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
126 |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
127 |
|
|
128 |
# draw hour grid |
# draw hour grid |
129 |
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
sub hour_grid { |
130 |
my @c = ("255,255,128","255,192,128"); |
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
131 |
my $hr=strftime("%H",localtime ($from_t)); |
my @c = ("255,255,128","255,192,128"); |
132 |
print color_bar(3600 - $from_t % 3600,$c[0],$hr++ % 24); |
my $hr=strftime("%H",localtime ($from_t)); |
133 |
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
sub hour_bar { |
134 |
print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24)); |
my ($t,$c,$hr) = @_; |
135 |
push @c, shift @c; |
my $clock_hr = $hr % 24; |
136 |
|
my $alt = sprintf("%02d:00",$clock_hr); |
137 |
|
if ($clock_hr == 0) { |
138 |
|
my $pix_hr = int(1 / $width); |
139 |
|
print color_bar($pix_hr,"0,0,0",strftime("%Y-%m-%d", localtime($from_t + $hr*3600))); |
140 |
|
print color_bar($t-$pix_hr,$c,$alt); |
141 |
|
} else { |
142 |
|
print color_bar($t,$c,$alt); |
143 |
|
} |
144 |
|
} |
145 |
|
hour_bar(3600 - $from_t % 3600,$c[0],$hr++); |
146 |
|
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
147 |
|
hour_bar(3600,$c[1],$hr++); |
148 |
|
push @c, shift @c; |
149 |
|
} |
150 |
|
hour_bar($from_t % 3600,$c[1],$hr); |
151 |
|
print "</td></tr>\n"; |
152 |
} |
} |
|
print color_bar($from_t % 3600,$c[1],$hr % 24); |
|
|
print "</td></tr>\n"; |
|
153 |
|
|
154 |
my $fix_d = 0; # used to fix graph len |
hour_grid(); |
155 |
|
|
156 |
|
my $fix_d = 0; # used to fix graph len (in pixels) |
157 |
|
my $fix_s = 0; # used to collect round errors of size |
158 |
|
|
159 |
sub bar { |
sub bar { |
160 |
my $l = shift @_; |
my $l = shift @_; |
174 |
# $col .= '240,240,240'; |
# $col .= '240,240,240'; |
175 |
$col .= '220,220,220'; |
$col .= '220,220,220'; |
176 |
} |
} |
177 |
return color_bar($l,$col,$alt); |
return color_bar($l,$col,$alt,$min_l); |
178 |
} |
} |
179 |
|
|
180 |
sub color_bar { |
sub color_bar { |
181 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; # lenght of event utime |
182 |
my $col = shift @_ || '240,240,240'; # default color (filler) |
my $col = shift @_ || '240,240,240'; # default color (filler) |
183 |
my $alt = shift @_ || undef; |
my $alt = shift @_ || undef; |
184 |
|
my $min_l = shift @_ || 1; |
185 |
|
my $h = shift @_ || $height; |
186 |
|
|
187 |
|
my $size = $l / ($len_t / $width); |
188 |
|
$fix_s += $size - int($size); |
189 |
|
$size=int($size); |
190 |
|
# add rounding error to size |
191 |
|
if ($fix_s > 1) { |
192 |
|
my $i = $fix_s ; $i = int($i); |
193 |
|
$fix_s -= $i; |
194 |
|
$size += $i; |
195 |
|
} |
196 |
|
|
197 |
my $size = int($l / ($len_t / $width)); |
if ($alt && $size < $min_l) { |
|
if ($size < $min_l) { |
|
198 |
$fix_d += ($min_l - $size); |
$fix_d += ($min_l - $size); |
199 |
print STDERR "fix_d: $fix_d\n" if ($debug); |
print STDERR "fix_d: $fix_d\n" if ($debug); |
200 |
$size = $min_l; |
$size = $min_l; |
207 |
|
|
208 |
print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
209 |
|
|
210 |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\""; |
my $html = "<img src=\"".$q->url(-relative=>1)."/$col\" width=\"$size\" height=\"$h\""; |
211 |
|
|
212 |
if ($use_js && $alt) { |
if ($use_js && $alt) { |
213 |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
224 |
from gantt |
from gantt |
225 |
where (start < '$from' and finish > '$from') or |
where (start < '$from' and finish > '$from') or |
226 |
(start > '$from' and start < '$to') |
(start > '$from' and start < '$to') |
227 |
order by device,specification |
order by device,specification,start |
228 |
"; |
"; |
229 |
|
|
230 |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
236 |
|
|
237 |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
238 |
|
|
239 |
|
my $dev; # current device |
240 |
|
my @dev_t; # all minutes in one hour [1440] |
241 |
|
my @dev_sum_t; |
242 |
|
|
243 |
|
sub sum_bar { |
244 |
|
my $label = shift @_; |
245 |
|
my @dev_t = @_; |
246 |
|
# display device summary |
247 |
|
my $max_use = 0; |
248 |
|
for (my $i=0; $i < $len_t; $i++) { |
249 |
|
$max_use = $dev_t[$i] if (defined $dev_t[$i] && $dev_t[$i] > $max_use); |
250 |
|
} |
251 |
|
print "<tr><td align=right><small>$label [$max_use]</small></td><td colspan=2>"; |
252 |
|
my $last_var = 0; |
253 |
|
my $len = 0; |
254 |
|
for (my $i=1; $i<= ($to_t-$from_t); $i++) { |
255 |
|
my $v = $dev_t[$i] || 0; |
256 |
|
if ($v == $last_var) { |
257 |
|
$len++; |
258 |
|
} else { |
259 |
|
my $h = $last_var / $max_use * $height; |
260 |
|
my $c = 255 - int (255 * $last_var / $max_use); |
261 |
|
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1); |
262 |
|
$len = 0; |
263 |
|
$last_var = $v; |
264 |
|
} |
265 |
|
} |
266 |
|
my $h = $last_var / $max_use * $height; |
267 |
|
my $c = 255 - int (255 * $last_var / $max_use); |
268 |
|
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len); |
269 |
|
print "</td></tr>"; |
270 |
|
} |
271 |
|
|
272 |
|
my @line_t; # all seconds for this specification |
273 |
|
my @line_arr = (""); # all segments on line which are not fillers |
274 |
|
|
275 |
|
sub html_spec { |
276 |
|
print "<tr><td>$curr_spec</td><td colspan=2>"; |
277 |
|
|
278 |
|
my $last_var = 0; |
279 |
|
my $len = 0; |
280 |
|
my $i; |
281 |
|
for (my $t=0; $t<=$len_t; $t++) { |
282 |
|
$i = $line_t[$t] || 0; |
283 |
|
if ($i == $last_var) { |
284 |
|
$len++; |
285 |
|
} else { |
286 |
|
if ($last_var == 0) { |
287 |
|
print bar($len); |
288 |
|
} else { |
289 |
|
print bar($len,split(/\t/,$line_arr[$last_var],2)); |
290 |
|
} |
291 |
|
$len = 0; |
292 |
|
$last_var = $i; |
293 |
|
} |
294 |
|
} |
295 |
|
print bar($len,split(/\t/,$line_arr[$i],2)); |
296 |
|
|
297 |
|
print "</td></tr>\n"; |
298 |
|
} |
299 |
|
|
300 |
while(my $row = $sth->fetchrow_hashref) { |
while(my $row = $sth->fetchrow_hashref) { |
301 |
if (!defined $curr_spec || $row->{specification} ne $curr_spec) { |
if ($row->{specification} ne $curr_spec) { |
302 |
|
|
303 |
if ($curr_t < $to_t && $curr_spec) { |
if ($curr_t < $to_t && $curr_spec) { |
304 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
305 |
print STDERR "[end filler $curr_t:$t]" if ($debug); |
print STDERR "[end filler $curr_t:$t]" if ($debug); |
306 |
print bar($t); |
# print bar($t); |
307 |
} |
} |
308 |
|
|
309 |
print "</td></tr>\n" if ($curr_t != $from_t); |
# print "</td></tr>\n" if ($curr_t != $from_t); |
310 |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
|
311 |
|
|
312 |
|
# init vars for next line |
313 |
|
($fix_s,$fix_d) = (0,0); # init fix vars for bar |
314 |
|
|
315 |
|
html_spec if ($curr_spec ne ""); |
316 |
|
|
317 |
$curr_t = $from_t; # init timeline |
$curr_t = $from_t; # init timeline |
318 |
$curr_spec = $row->{specification}; |
$curr_spec = $row->{specification}; |
319 |
|
|
320 |
|
@line_t = (); |
321 |
|
@line_arr = ( "" ); |
322 |
|
|
323 |
|
if ($dev && @dev_t && $dev ne $row->{device}) { |
324 |
|
sum_bar("summary for $dev",@dev_t); |
325 |
|
$dev = $row->{device}; |
326 |
|
@dev_t = (); |
327 |
|
} elsif (! $dev) { |
328 |
|
$dev = $row->{device}; |
329 |
|
} |
330 |
} |
} |
331 |
|
|
332 |
my $start_t = m_round(str2time($row->{start})); |
my $start_t = str2time($row->{start}); |
333 |
my $fin_t = m_round(str2time($row->{finish})); |
my $fin_t = str2time($row->{finish}); |
334 |
|
|
335 |
if ($start_t > $curr_t + 60) { |
# Can I squeeze here 1 pixel of time (many seconds) ? |
336 |
|
if ($start_t > $curr_t + ($len_t / $width)) { |
337 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
338 |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
339 |
print bar($t); |
# print bar($t); |
340 |
$curr_t = $start_t; |
$curr_t = $start_t; |
341 |
|
} else { |
342 |
|
# prepend too few seconds to next event |
343 |
|
$start_t = $curr_t; |
344 |
} |
} |
345 |
|
|
346 |
my $len = $fin_t - $start_t; |
my $len = $fin_t - $start_t; |
365 |
my $alt = $row->{start}." - ".$row->{finish}."<br>"; |
my $alt = $row->{start}." - ".$row->{finish}."<br>"; |
366 |
$alt =~ s/:\d\d\.\d+//g; |
$alt =~ s/:\d\d\.\d+//g; |
367 |
$alt =~ s/\s+/ /g; |
$alt =~ s/\s+/ /g; |
368 |
$alt .= $row->{type}." <b>".$row->{status}."</b><br>". |
$alt .= $row->{specification}."<br>". |
369 |
$row->{user_group_host}." <i>".$row->{sessionid}."</i><br>". |
$row->{type}." <b>".$row->{status}."</b><br>". |
370 |
$row->{device}." on ".$row->{host}; |
$row->{user_group_host}." <i>".$row->{sessionid}."</i><br>". |
371 |
print bar($len,$row->{status},$alt); |
$row->{device}." on ".$row->{host}; |
372 |
|
# print bar($len,$row->{status},$alt); |
373 |
|
|
374 |
|
push @line_arr,$row->{status}."\t".$alt; |
375 |
|
# store use of devices for each minute |
376 |
|
for (my $s=0; $s<$len; $s++) { |
377 |
|
$line_t[$curr_t-$from_t+$s] = $#line_arr; |
378 |
|
$dev_t[$curr_t-$from_t+$s]++; |
379 |
|
$dev_sum_t[$curr_t-$from_t+$s]++; |
380 |
|
} |
381 |
|
|
382 |
$curr_t += $len; |
$curr_t += $len; |
383 |
|
|
386 |
} |
} |
387 |
|
|
388 |
if ($curr_t == $from_t) { # no entries in database! |
if ($curr_t == $from_t) { # no entries in database! |
389 |
print "<tr><td></td><td colspan=2>"; |
# print "<tr><td></td><td colspan=2>"; |
390 |
} |
} |
391 |
|
|
392 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t ) { |
393 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
394 |
print STDERR "[last_line filler $curr_t:$t]" if ($debug); |
print STDERR "[last_line filler $curr_t:$t]" if ($debug); |
|
print bar($t); |
|
395 |
} |
} |
396 |
|
|
397 |
undef $sth; |
undef $sth; |
398 |
$dbh->disconnect; |
$dbh->disconnect; |
399 |
|
|
400 |
print "</td></tr>\n</table>"; |
html_spec(); |
401 |
|
sum_bar("summary for $dev",@dev_t); |
402 |
|
hour_grid(); |
403 |
|
sum_bar("summary for all devices",@dev_sum_t); |
404 |
|
print "</table>"; |
405 |
|
|
406 |
|
|
407 |
# label and usage |
# label and usage |
417 |
# it will first evaluate bar sub (thus increasing number by one) and |
# it will first evaluate bar sub (thus increasing number by one) and |
418 |
# then display number (wrongly). |
# then display number (wrongly). |
419 |
} |
} |
420 |
print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>"; |
print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>"; |
421 |
|
|