/[omni_gantt]/db2gantt.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /db2gantt.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations)
Fri Sep 13 14:34:02 2002 UTC (16 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.8: +13 -5 lines
round all times to nearest minute, removed extra fillers

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5     use Data::Dumper;
6     use Date::Parse;
7 dpavlin 1.3 use CGI qw/:standard/;
8 dpavlin 1.4 use POSIX qw(strftime);
9 dpavlin 1.3
10 dpavlin 1.6 my $debug = 0;
11    
12     my $width = 600; # width of bar
13     my $height = 12; # height of bar
14     my $use_js = 1; # use JavaScript pop-up
15 dpavlin 1.3
16 dpavlin 1.4 # status colors
17 dpavlin 1.3 my %cols = (
18     'In Progress' => '0,255,0',
19 dpavlin 1.4 'In Progress/Failure' => '255,64,255',
20     'In Progress/Errors' => '255,64,0',
21 dpavlin 1.3 'Queuing' => '255,255,0',
22 dpavlin 1.4 'Aborted' => '255,0,0',
23     'Failed' => '255,0,0',
24     'Completed' => '64,255,64',
25     'Completed/Errors' => '255,128,0',
26     'Completed/Failure' => '128,0,128',
27     'Mount Request' => '128,128,255',
28 dpavlin 1.9 'Mount/Errors' => '255,64,128',
29 dpavlin 1.3 );
30    
31 dpavlin 1.6 my $int_t = (12 * 60 * 60); # interval to display on one screen
32     my $min_l = 3; # min length of bar segment (in pixels)
33    
34 dpavlin 1.4 #--- no user servicable parts below this line
35    
36     # time range
37    
38 dpavlin 1.9 $int_t = m_round($int_t);
39    
40 dpavlin 1.6 my ($from_t,$to_t) = (time()-$int_t,time());
41 dpavlin 1.4
42     $to_t = param('to_t') if (param('to_t'));
43     $from_t = param('from_t') if (param('from_t'));
44    
45 dpavlin 1.6 # round to nearest minute
46 dpavlin 1.9 sub m_round {
47     my $t = shift @_;
48     return ($t - ($t % 60));
49     }
50    
51     $to_t = m_round($to_t);
52     $from_t = m_round($from_t);
53 dpavlin 1.6
54     my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t));
55     my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t));
56 dpavlin 1.4
57    
58     # keep count of each status
59     my %count;
60 dpavlin 1.3
61     if (param('pic')) {
62 dpavlin 1.4 print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
63 dpavlin 1.3 # create picture using GD
64     use GD;
65 dpavlin 1.6 my $im = new GD::Image(1,$height);
66 dpavlin 1.3 my $back = $im->colorAllocate(255,255,255);
67     $im->transparent($back);
68     my ($r,$g,$b) = split(/,/,param('pic'));
69     my $col = $im->colorAllocate($r,$g,$b);
70     $im->fill(0,0,$col);
71     binmode STDOUT;
72     print $im->png;
73     exit;
74     }
75 dpavlin 1.1
76 dpavlin 1.4 print "Content-type: text/html
77    
78     <html>
79     <head>
80     <title>OmniBack Gantt: $from - $to</title>";
81     if ($use_js) {
82     print '
83     <script type="text/javascript" language="javascript" src="1k.js"></script>
84     <script type="text/javascript" language="javascript" src="tooltip.js"></script>
85     <script language="javascript" type="text/javascript">
86     onload=function(){
87     T.init()
88     T.follows = false // false by default
89     T.delay = .3 // any nonnegative value (0.7 by default)
90     }
91     </script>
92     ';
93     }
94     print "</head><body>";
95 dpavlin 1.1
96     # all vars ending in *_t have utime in them.
97     #
98     my $len_t = $to_t - $from_t;
99    
100     die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
101    
102     my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
103 dpavlin 1.3 my $q=new CGI;
104 dpavlin 1.1
105    
106 dpavlin 1.4 sub mknav {
107     my $f = shift @_; # from_t
108     my $t = shift @_; # to_t
109     my $ch = shift @_; # char
110    
111     return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";
112     }
113    
114 dpavlin 1.1 print "<table>";
115 dpavlin 1.4 print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
116 dpavlin 1.6 print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;
117     print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);
118 dpavlin 1.4 print "</td><td align=right>";
119 dpavlin 1.6 print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);
120     print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
121 dpavlin 1.4
122     my $fix_d = 0; # used to fix graph len
123 dpavlin 1.3
124 dpavlin 1.4 sub bar {
125     my $l = shift @_; # lenght of event utime
126     my $status = shift @_ || undef; # what to draw
127     my $alt = shift @_ || undef;
128 dpavlin 1.1
129 dpavlin 1.4 my $size = int($l / ($len_t / $width));
130     if ($size < $min_l) {
131 dpavlin 1.8 $fix_d += ($min_l - $size);
132     print STDERR "fix_d: $fix_d\n" if ($debug);
133 dpavlin 1.4 $size = $min_l;
134     }
135     if ($fix_d && $size > $fix_d+$min_l) {
136     $size -= $fix_d;
137     $fix_d = 0;
138 dpavlin 1.8 print STDERR "fix_d: $fix_d\n" if ($debug);
139 dpavlin 1.4 }
140 dpavlin 1.1
141 dpavlin 1.6 print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug);
142 dpavlin 1.2
143 dpavlin 1.4 my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
144 dpavlin 1.1
145 dpavlin 1.4 if ($status) {
146 dpavlin 1.8 if ($cols{$status}) {
147     $html .= $cols{$status};
148     } else {
149     $html .= "0,0,0"; # unknown status, black
150     }
151 dpavlin 1.4 $count{$status}++;
152     } else {
153     # $html .= '240,240,240';
154     $html .= '220,220,220';
155     }
156 dpavlin 1.1
157 dpavlin 1.6 $html .= "\" width=\"$size\" height=\"$height\"";
158 dpavlin 1.4 if ($use_js && $alt) {
159     $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
160     } elsif ($alt) {
161     $html .= " alt=\"$alt\"";
162     }
163     $html .= ">";
164    
165     return($html);
166 dpavlin 1.1 }
167    
168 dpavlin 1.6 my $sql = "select start,finish,specification,status,user_group_host,
169     type,sessionid,device,host
170 dpavlin 1.1 from gantt
171     where (start < '$from' and finish > '$from') or
172     (start > '$from' and start < '$to')
173 dpavlin 1.6 order by device,specification
174 dpavlin 1.1 ";
175    
176     my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
177    
178     my %spec; # specification hash
179    
180     my $curr_spec;
181     my $curr_t = $from_t;
182    
183     $sth->execute() || die "sql: $sql ".$dbh->errstr;
184 dpavlin 1.2
185 dpavlin 1.1 while(my $row = $sth->fetchrow_hashref) {
186 dpavlin 1.6 if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
187 dpavlin 1.1
188 dpavlin 1.3 if ($curr_t < $to_t && $curr_spec) {
189 dpavlin 1.1 my $t = $to_t - $curr_t;
190 dpavlin 1.6 print STDERR "[end filler $curr_t:$t]" if ($debug);
191 dpavlin 1.4 print bar($t);
192 dpavlin 1.1 }
193    
194 dpavlin 1.6 print "</td></tr>\n" if ($curr_t != $from_t);
195 dpavlin 1.1 print "<tr><td>", $row->{specification},"</td><td colspan=2>";
196    
197     $curr_t = $from_t; # init timeline
198     $curr_spec = $row->{specification};
199    
200     }
201    
202 dpavlin 1.9 my $start_t = m_round(str2time($row->{start}));
203     my $fin_t = m_round(str2time($row->{finish}));
204 dpavlin 1.1
205 dpavlin 1.9 if ($start_t > $curr_t + 60) {
206 dpavlin 1.1 my $t = $start_t - $curr_t;
207 dpavlin 1.6 print STDERR "[middle filler $curr_t:$t]" if ($debug);
208 dpavlin 1.4 print bar($t);
209 dpavlin 1.1 $curr_t = $start_t;
210     }
211    
212     my $len = $fin_t - $start_t;
213     # $len = $len_t if ($len > $len_t);
214     my $less = '';
215     my $more = '';
216    
217     if ($start_t < $from_t) {
218     # $len += ($from_t - $start_t);
219     $len = ($fin_t - $curr_t);
220     $less = "<<";
221     }
222 dpavlin 1.4
223 dpavlin 1.1 if ($fin_t > $to_t) {
224     # $len -= ($fin_t - $to_t);
225     $len = ($to_t - $curr_t);
226     $more = ">>"; # event now shown whole
227     }
228    
229     print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
230 dpavlin 1.5
231 dpavlin 1.6 my $alt = $row->{start}." - ".$row->{finish}."<br>";
232 dpavlin 1.5 $alt =~ s/:\d\d\.\d+//g;
233 dpavlin 1.6 $alt =~ s/\s+/&nbsp;/g;
234     $alt .= $row->{type}." <b>".$row->{status}."</b><br>".
235     $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
236     $row->{device}."&nbsp;on&nbsp;".$row->{host};
237 dpavlin 1.5 print bar($len,$row->{status},$alt);
238 dpavlin 1.1
239     $curr_t += $len;
240    
241     # print Dumper($row);
242    
243     }
244    
245 dpavlin 1.6 if ($curr_t == $from_t) { # no entries in database!
246     print "<tr><td></td><td colspan=2>";
247     }
248    
249 dpavlin 1.1 if ($curr_t < $to_t ) {
250     my $t = $to_t - $curr_t;
251 dpavlin 1.6 print STDERR "[last_line filler $curr_t:$t]" if ($debug);
252 dpavlin 1.4 print bar($t);
253 dpavlin 1.1 }
254    
255     undef $sth;
256     $dbh->disconnect;
257    
258 dpavlin 1.3 print "</td></tr>\n</table>";
259 dpavlin 1.4
260    
261     # label and usage
262     $len_t = 50; # disable bar scaling
263    
264     print "<hr>\nColors for statuses and usage (#):\n";
265     print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n";
266     foreach my $status (keys %count) {
267     #foreach my $status (keys %cols) {
268 dpavlin 1.8 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 "");
269     # *1 in line above is a cludge to display correct number on
270     # occurences on graph and without one on legend! If you remove * op
271     # it will first evaluate bar sub (thus increasing number by one) and
272     # then display number (wrongly).
273 dpavlin 1.4 }
274 dpavlin 1.7 print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";
275 dpavlin 1.1

  ViewVC Help
Powered by ViewVC 1.1.26