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 CGI::Carp qw(fatalsToBrowser); |
9 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
10 |
|
|
11 |
my $debug = 0; |
my $debug = 0; |
26 |
'Completed/Errors' => '255,128,0', |
'Completed/Errors' => '255,128,0', |
27 |
'Completed/Failure' => '128,0,128', |
'Completed/Failure' => '128,0,128', |
28 |
'Mount Request' => '128,128,255', |
'Mount Request' => '128,128,255', |
29 |
|
'Mount/Errors' => '255,64,128', |
30 |
); |
); |
31 |
|
|
32 |
my $int_t = (12 * 60 * 60); # interval to display on one screen |
my $int_t = (12 * 60 * 60); # interval to display on one screen |
36 |
|
|
37 |
# time range |
# time range |
38 |
|
|
39 |
|
$int_t = m_round($int_t); |
40 |
|
|
41 |
my ($from_t,$to_t) = (time()-$int_t,time()); |
my ($from_t,$to_t) = (time()-$int_t,time()); |
42 |
|
|
43 |
$to_t = param('to_t') if (param('to_t')); |
$to_t = param('to_t') if (param('to_t')); |
44 |
$from_t = param('from_t') if (param('from_t')); |
$from_t = param('from_t') if (param('from_t')); |
45 |
|
|
46 |
# round to nearest minute |
# round to nearest minute |
47 |
$to_t = $to_t - ($to_t % 60); |
sub m_round { |
48 |
$from_t = $from_t - ($from_t % 60) + 60; |
my $t = shift @_; |
49 |
|
return ($t - ($t % 60)); |
50 |
|
} |
51 |
|
|
52 |
|
$to_t = m_round($to_t); |
53 |
|
$from_t = m_round($from_t); |
54 |
|
|
55 |
my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t)); |
my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t)); |
56 |
my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t)); |
my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t)); |
120 |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
121 |
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"; |
122 |
|
|
123 |
|
# draw hour grid |
124 |
|
sub hour_grid { |
125 |
|
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
126 |
|
my @c = ("255,255,128","255,192,128"); |
127 |
|
my $hr=strftime("%H",localtime ($from_t)); |
128 |
|
print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24)); |
129 |
|
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
130 |
|
print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24)); |
131 |
|
push @c, shift @c; |
132 |
|
} |
133 |
|
print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24)); |
134 |
|
print "</td></tr>\n"; |
135 |
|
} |
136 |
|
|
137 |
|
hour_grid(); |
138 |
|
|
139 |
my $fix_d = 0; # used to fix graph len |
my $fix_d = 0; # used to fix graph len |
140 |
|
|
141 |
sub bar { |
sub bar { |
142 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; |
143 |
my $status = shift @_ || undef; # what to draw |
my $status = shift @_; |
144 |
|
my $alt = shift @_; |
145 |
|
|
146 |
|
my $col; |
147 |
|
|
148 |
|
if ($status) { |
149 |
|
if ($cols{$status}) { |
150 |
|
$col .= $cols{$status}; |
151 |
|
} else { |
152 |
|
$col .= "0,0,0"; # unknown status, black |
153 |
|
} |
154 |
|
$count{$status}++; |
155 |
|
} else { |
156 |
|
# $col .= '240,240,240'; |
157 |
|
$col .= '220,220,220'; |
158 |
|
} |
159 |
|
return color_bar($l,$col,$alt); |
160 |
|
} |
161 |
|
|
162 |
|
sub color_bar { |
163 |
|
my $l = shift @_; # lenght of event utime |
164 |
|
my $col = shift @_ || '240,240,240'; # default color (filler) |
165 |
my $alt = shift @_ || undef; |
my $alt = shift @_ || undef; |
166 |
|
|
167 |
my $size = int($l / ($len_t / $width)); |
my $size = int($l / ($len_t / $width)); |
168 |
if ($size < $min_l) { |
if ($size < $min_l) { |
169 |
|
$fix_d += ($min_l - $size); |
170 |
|
print STDERR "fix_d: $fix_d\n" if ($debug); |
171 |
$size = $min_l; |
$size = $min_l; |
|
$fix_d += $min_l; |
|
172 |
} |
} |
173 |
if ($fix_d && $size > $fix_d+$min_l) { |
if ($fix_d && $size > $fix_d+$min_l) { |
174 |
$size -= $fix_d; |
$size -= $fix_d; |
175 |
$fix_d = 0; |
$fix_d = 0; |
176 |
|
print STDERR "fix_d: $fix_d\n" if ($debug); |
177 |
} |
} |
178 |
|
|
179 |
print STDERR "bar[$status] 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); |
180 |
|
|
181 |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic="; |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\""; |
|
|
|
|
if ($status) { |
|
|
$html .= $cols{$status}; |
|
|
$count{$status}++; |
|
|
} else { |
|
|
# $html .= '240,240,240'; |
|
|
$html .= '220,220,220'; |
|
|
} |
|
182 |
|
|
|
$html .= "\" width=\"$size\" height=\"$height\""; |
|
183 |
if ($use_js && $alt) { |
if ($use_js && $alt) { |
184 |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
185 |
} elsif ($alt) { |
} elsif ($alt) { |
224 |
|
|
225 |
} |
} |
226 |
|
|
227 |
my $start_t = str2time($row->{start}); |
my $start_t = m_round(str2time($row->{start})); |
228 |
my $fin_t = str2time($row->{finish}); |
my $fin_t = m_round(str2time($row->{finish})); |
229 |
|
|
230 |
if ($start_t > $curr_t) { |
if ($start_t > $curr_t + 60) { |
231 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
232 |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
233 |
print bar($t); |
print bar($t); |
280 |
undef $sth; |
undef $sth; |
281 |
$dbh->disconnect; |
$dbh->disconnect; |
282 |
|
|
283 |
print "</td></tr>\n</table>"; |
print "</td></tr>\n"; |
284 |
|
hour_grid(); |
285 |
|
print "</table>"; |
286 |
|
|
287 |
|
|
288 |
# label and usage |
# label and usage |
292 |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
293 |
foreach my $status (keys %count) { |
foreach my $status (keys %count) { |
294 |
#foreach my $status (keys %cols) { |
#foreach my $status (keys %cols) { |
295 |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status}-1,"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status}*1,"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
296 |
# -1 in line above is a cludge to display correct number on |
# *1 in line above is a cludge to display correct number on |
297 |
# occurences on graph and without one on legend! |
# occurences on graph and without one on legend! If you remove * op |
298 |
|
# it will first evaluate bar sub (thus increasing number by one) and |
299 |
|
# then display number (wrongly). |
300 |
} |
} |
301 |
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>.</p></body></html>"; |
302 |
|
|