5 |
use Data::Dumper; |
use Data::Dumper; |
6 |
use Date::Parse; |
use Date::Parse; |
7 |
use CGI qw/:standard/; |
use CGI qw/:standard/; |
8 |
|
use POSIX qw(strftime); |
|
# default range |
|
|
my $from="2002-09-11 18:00"; |
|
|
my $to="2002-09-13 00:00:00"; |
|
9 |
|
|
10 |
my $debug = 1; |
my $debug = 1; |
11 |
my $width = 800; |
my $width = 600; |
12 |
|
my $use_js = 1; |
|
#--- no user servicable parts below this line |
|
13 |
|
|
14 |
|
# status colors |
15 |
my %cols = ( |
my %cols = ( |
16 |
'In Progress' => '0,255,0', |
'In Progress' => '0,255,0', |
17 |
'In Progress/Failure' => '255,128,128', |
'In Progress/Failure' => '255,64,255', |
18 |
'In Progress/Errors' => '255,128,128', |
'In Progress/Errors' => '255,64,0', |
19 |
'Queuing' => '255,255,0', |
'Queuing' => '255,255,0', |
20 |
'Aborted', => '255,0,0', |
'Aborted' => '255,0,0', |
21 |
'Failed', => '255,0,0', |
'Failed' => '255,0,0', |
22 |
'Completed', => '0,255,0', |
'Completed' => '64,255,64', |
23 |
'Completed/Errors' => '0,255,255', |
'Completed/Errors' => '255,128,0', |
24 |
'Completed/Failure', => '0,255,255' |
'Completed/Failure' => '128,0,128', |
25 |
|
'Mount Request' => '128,128,255', |
26 |
); |
); |
27 |
|
|
28 |
|
#--- no user servicable parts below this line |
29 |
|
|
30 |
|
# time range |
31 |
|
|
32 |
|
my $day_t = (24 * 60 * 60); # 24h interval |
33 |
|
|
34 |
|
my ($from_t,$to_t) = (time()-$day_t,time()); |
35 |
|
|
36 |
|
$to_t = param('to_t') if (param('to_t')); |
37 |
|
$from_t = param('from_t') if (param('from_t')); |
38 |
|
|
39 |
|
my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t)); |
40 |
|
my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t)); |
41 |
|
|
42 |
|
|
43 |
|
# keep count of each status |
44 |
|
my %count; |
45 |
|
|
46 |
if (param('pic')) { |
if (param('pic')) { |
47 |
print "Content-type: image/png\n\n"; |
print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n"; |
48 |
# create picture using GD |
# create picture using GD |
49 |
use GD; |
use GD; |
50 |
my $im = new GD::Image(1,8); |
my $im = new GD::Image(1,8); |
58 |
exit; |
exit; |
59 |
} |
} |
60 |
|
|
61 |
print "Content-type: text/html\n\n"; |
print "Content-type: text/html |
62 |
|
|
63 |
|
<html> |
64 |
|
<head> |
65 |
|
<title>OmniBack Gantt: $from - $to</title>"; |
66 |
|
if ($use_js) { |
67 |
|
print ' |
68 |
|
<script type="text/javascript" language="javascript" src="1k.js"></script> |
69 |
|
<script type="text/javascript" language="javascript" src="tooltip.js"></script> |
70 |
|
<script language="javascript" type="text/javascript"> |
71 |
|
onload=function(){ |
72 |
|
T.init() |
73 |
|
T.follows = false // false by default |
74 |
|
T.delay = .3 // any nonnegative value (0.7 by default) |
75 |
|
} |
76 |
|
</script> |
77 |
|
'; |
78 |
|
} |
79 |
|
print "</head><body>"; |
80 |
|
|
81 |
# all vars ending in *_t have utime in them. |
# all vars ending in *_t have utime in them. |
82 |
# |
# |
|
my $from_t = str2time($from); |
|
|
my $to_t = str2time($to); |
|
83 |
my $len_t = $to_t - $from_t; |
my $len_t = $to_t - $from_t; |
84 |
|
|
85 |
die "interval must be positive and bigger than 1 sec !" if ($len_t < 1); |
die "interval must be positive and bigger than 1 sec !" if ($len_t < 1); |
88 |
my $q=new CGI; |
my $q=new CGI; |
89 |
|
|
90 |
|
|
91 |
print "<table>"; |
sub mknav { |
92 |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>\n"; |
my $f = shift @_; # from_t |
93 |
|
my $t = shift @_; # to_t |
94 |
|
my $ch = shift @_; # char |
95 |
|
|
96 |
|
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
97 |
|
} |
98 |
|
|
99 |
|
print "<table>"; |
100 |
|
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
101 |
|
print mknav(($from_t-$day_t),$to_t,'<small><<</small>'),$from; |
102 |
|
print mknav(($from_t+$day_t),$to_t,'<small>>></small>') if ($from_t+$day_t < $to_t); |
103 |
|
print "</td><td align=right>"; |
104 |
|
print mknav($from_t,($to_t-$day_t),'<small><<</small>') if ($to_t-$day_t > $from_t); |
105 |
|
print $to,mknav($from_t,($to_t+$day_t),'<small>>></small>'),"</td></tr>\n"; |
106 |
|
|
107 |
|
my $fix_d = 0; # used to fix graph len |
108 |
|
my $min_l = 3; # min length; |
109 |
|
|
110 |
sub draw { |
sub bar { |
111 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; # lenght of event utime |
112 |
my $status = shift @_; # what to draw |
my $status = shift @_ || undef; # what to draw |
113 |
my $alt = shift @_; |
my $alt = shift @_ || undef; |
114 |
|
|
115 |
|
my $size = int($l / ($len_t / $width)); |
116 |
|
if ($size < $min_l) { |
117 |
|
$size = $min_l; |
118 |
|
$fix_d += $min_l; |
119 |
|
} |
120 |
|
if ($fix_d && $size > $fix_d+$min_l) { |
121 |
|
$size -= $fix_d; |
122 |
|
$fix_d = 0; |
123 |
|
} |
124 |
|
|
125 |
|
print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br> alt:$alt\n" if ($debug); |
126 |
|
|
127 |
my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1) |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic="; |
128 |
|
|
129 |
print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug); |
if ($status) { |
130 |
|
$html .= $cols{$status}; |
131 |
|
$count{$status}++; |
132 |
|
} else { |
133 |
|
# $html .= '240,240,240'; |
134 |
|
$html .= '220,220,220'; |
135 |
|
} |
136 |
|
|
137 |
my $col = $cols{$status} || '240,240,240'; |
$html .= "\" width=\"$size\" height=\"12\""; |
138 |
print "<img src=".$q->url(-relative=>1)."?pic=$col width=$size height=8 alt=\"$alt\">"; |
if ($use_js && $alt) { |
139 |
|
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
140 |
|
} elsif ($alt) { |
141 |
|
$html .= " alt=\"$alt\""; |
142 |
|
} |
143 |
|
$html .= ">"; |
144 |
|
|
145 |
|
return($html); |
146 |
} |
} |
147 |
|
|
148 |
my $sql = "select start,finish,specification,status |
my $sql = "select start,finish,specification,status |
167 |
if ($curr_t < $to_t && $curr_spec) { |
if ($curr_t < $to_t && $curr_spec) { |
168 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
169 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
170 |
draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status}); |
print bar($t); |
171 |
} |
} |
172 |
|
|
173 |
print "</td></tr>\n" if ($curr_t != 0); |
print "</td></tr>\n" if ($curr_t != 0); |
184 |
if ($start_t > $curr_t) { |
if ($start_t > $curr_t) { |
185 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
186 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
187 |
draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status}); |
print bar($t); |
188 |
$curr_t = $start_t; |
$curr_t = $start_t; |
189 |
} |
} |
190 |
|
|
198 |
$len = ($fin_t - $curr_t); |
$len = ($fin_t - $curr_t); |
199 |
$less = "<<"; |
$less = "<<"; |
200 |
} |
} |
201 |
|
|
202 |
|
next if ($fin_t > $to_t); |
203 |
|
|
204 |
if ($fin_t > $to_t) { |
if ($fin_t > $to_t) { |
205 |
# $len -= ($fin_t - $to_t); |
# $len -= ($fin_t - $to_t); |
206 |
$len = ($to_t - $curr_t); |
$len = ($to_t - $curr_t); |
208 |
} |
} |
209 |
|
|
210 |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
211 |
draw($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status}); |
print bar($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status}); |
212 |
|
|
213 |
$curr_t += $len; |
$curr_t += $len; |
214 |
|
|
219 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t ) { |
220 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
221 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
222 |
draw($t); |
print bar($t); |
223 |
} |
} |
224 |
|
|
225 |
undef $sth; |
undef $sth; |
227 |
|
|
228 |
print "</td></tr>\n</table>"; |
print "</td></tr>\n</table>"; |
229 |
|
|
230 |
|
|
231 |
|
# label and usage |
232 |
|
$len_t = 50; # disable bar scaling |
233 |
|
|
234 |
|
print "<hr>\nColors for statuses and usage (#):\n"; |
235 |
|
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
236 |
|
foreach my $status (keys %count) { |
237 |
|
#foreach my $status (keys %cols) { |
238 |
|
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status},"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
239 |
|
} |
240 |
|
print "</table>\n</body></html>"; |
241 |
|
|