/[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

Diff of /db2gantt.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by dpavlin, Fri Sep 13 11:17:20 2002 UTC revision 1.21 by dpavlin, Mon Sep 16 15:29:00 2002 UTC
# Line 5  use DBI; Line 5  use DBI;
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 = 1;  my $debug = 0;
12  my $width = 600;  
13  my $use_js = 1;  my $width = 600;        # width of bar
14    my $height = 15;        # height of bar
15    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',
27          'Completed/Errors'      => '255,128,0',          'Completed/Errors'      => '255,128,0',
28          'Completed/Failure'     => '128,0,128',          'Completed/Failure'     => '128,0,128',
29          'Mount Request'         => '128,128,255',          'Mount Request'         => '128,128,255',
30            'Mount/Errors'          => '255,64,128',
31          );          );
32    
33    my $int_t = (12 * 60 * 60);     # interval to display on one screen
34    my $min_l = 3;                  # min length of bar segment (in pixels)
35    
36  #--- no user servicable parts below this line  #--- no user servicable parts below this line
37    
38  # time range  # time range
39    
40  my $day_t = (24 * 60 * 60);     # 24h interval  $int_t = m_round($int_t);
41    
42  my ($from_t,$to_t) = (time()-$day_t,time());  my ($from_t,$to_t) = (time()-$int_t,time());
43    
44  $to_t = param('to_t') if (param('to_t'));  $to_t = param('to_t') if (param('to_t'));
45  $from_t = param('from_t') if (param('from_t'));  $from_t = param('from_t') if (param('from_t'));
46    
47  my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t));  # round to nearest minute
48  my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t));  sub m_round {
49            my $t = shift @_;
50            return ($t - ($t % 60));
51    }
52    
53    $to_t = m_round($to_t);
54    $from_t = m_round($from_t);
55    
56    my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t));
57    my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t));
58    
59    
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,8);          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>
# Line 96  sub mknav { Line 117  sub mknav {
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-$day_t),$to_t,'<small>&lt;&lt;</small>'),$from;  print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;
123  print mknav(($from_t+$day_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$day_t < $to_t);  print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);
124  print "</td><td align=right>";  print "</td><td align=right>";
125  print mknav($from_t,($to_t-$day_t),'<small>&lt;&lt;</small>') if ($to_t-$day_t > $from_t);  print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);
126  print $to,mknav($from_t,($to_t+$day_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";  print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
127    
128    # draw hour grid
129    sub hour_grid {
130            print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";
131            my @c = ("255,255,128","255,192,128");
132            my $hr=strftime("%H",localtime ($from_t));
133            sub hour_bar {
134                    my ($t,$c,$hr) = @_;
135                    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    }
153    
154    hour_grid();
155    
156  my $fix_d = 0;  # used to fix graph len  my $fix_d = 0;  # used to fix graph len (in pixels)
157  my $min_l = 3;  # min length;  my $fix_s = 0;  # used to collect round errors of size
158    
159  sub bar {  sub bar {
160          my $l = shift @_;       # lenght of event utime          my $l = shift @_;
161          my $status = shift @_ || undef; # what to draw          my $status = shift @_;
162            my $alt = shift @_;
163    
164            my $col;
165    
166            if ($status) {
167                    if ($cols{$status}) {
168                            $col .= $cols{$status};
169                    } else {
170                            $col .= "0,0,0";        # unknown status, black
171                    }
172                    $count{$status}++;
173            } else {
174    #               $col .= '240,240,240';
175                    $col .= '220,220,220';
176            }
177            return color_bar($l,$col,$alt,$min_l);
178    }
179    
180    sub color_bar {
181            my $l = shift @_;                       # lenght of event utime
182            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 = int($l / ($len_t / $width));          my $size = $l / ($len_t / $width);
188          if ($size < $min_l) {          $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            if ($alt && $size < $min_l) {
198                    $fix_d += ($min_l - $size);
199                    print STDERR "fix_d: $fix_d\n" if ($debug);
200                  $size = $min_l;                  $size = $min_l;
                 $fix_d += $min_l;  
201          }          }
202          if ($fix_d && $size > $fix_d+$min_l) {          if ($fix_d && $size > $fix_d+$min_l) {
203                  $size -= $fix_d;                  $size -= $fix_d;
204                  $fix_d = 0;                  $fix_d = 0;
205                    print STDERR "fix_d: $fix_d\n" if ($debug);
206          }          }
207    
208          print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<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);
   
         my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";  
209    
210          if ($status) {          my $html = "<img src=\"".$q->url(-relative=>1)."/$col\" width=\"$size\" height=\"$h\"";
                 $html .= $cols{$status};  
                 $count{$status}++;  
         } else {  
 #               $html .= '240,240,240';  
                 $html .= '220,220,220';  
         }  
211    
         $html .= "\" width=\"$size\" height=\"12\"";  
212          if ($use_js && $alt) {          if ($use_js && $alt) {
213                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
214          } elsif ($alt) {          } elsif ($alt) {
# Line 145  sub bar { Line 219  sub bar {
219          return($html);          return($html);
220  }  }
221    
222  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,
223                    type,sessionid,device,host
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 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;
# Line 161  my $curr_t = $from_t; Line 236  my $curr_t = $from_t;
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  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
273          if ($row->{specification} ne $curr_spec) {          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
274    
275                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
276                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
277                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
278                          print bar($t);                          print bar($t);
279                  }                  }
280    
281                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != $from_t);
282    
283                    if ($dev && @dev_t && $dev ne $row->{device}) {
284                            sum_bar("summary for $dev",@dev_t);
285                            $dev = $row->{device};
286                            @dev_t = ();
287                    } elsif (! $dev) {
288                            $dev = $row->{device};
289                    }
290    
291                    # init vars for next line
292                    ($fix_s,$fix_d) = (0,0); # init fix vars for bar
293                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
294    
295                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 181  while(my $row = $sth->fetchrow_hashref) Line 300  while(my $row = $sth->fetchrow_hashref)
300          my $start_t = str2time($row->{start});          my $start_t = str2time($row->{start});
301          my $fin_t = str2time($row->{finish});          my $fin_t = str2time($row->{finish});
302    
303          if ($start_t > $curr_t) {          # Can I squeeze here 1 pixel of time (many seconds) ?
304            if ($start_t > $curr_t + ($len_t / $width)) {
305                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
306                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
307                  print bar($t);                  print bar($t);
308                  $curr_t = $start_t;                  $curr_t = $start_t;
309            } else {
310                    # prepend too few seconds to next event
311                    $start_t = $curr_t;
312          }          }
313    
314          my $len = $fin_t - $start_t;          my $len = $fin_t - $start_t;
# Line 199  while(my $row = $sth->fetchrow_hashref) Line 322  while(my $row = $sth->fetchrow_hashref)
322                  $less = "<<";                  $less = "<<";
323          }          }
324    
         next if ($fin_t > $to_t);  
           
325          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
326  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
327                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 208  while(my $row = $sth->fetchrow_hashref) Line 329  while(my $row = $sth->fetchrow_hashref)
329          }          }
330    
331          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
332          print bar($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});  
333            my $alt = $row->{start}." - ".$row->{finish}."<br>";
334            $alt =~ s/:\d\d\.\d+//g;
335            $alt =~ s/\s+/&nbsp;/g;
336            $alt .= $row->{specification}."<br>".
337                    $row->{type}." <b>".$row->{status}."</b><br>".
338                    $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
339                    $row->{device}."&nbsp;on&nbsp;".$row->{host};
340            print bar($len,$row->{status},$alt);
341    
342            # store use of devices for each minute
343            for (my $s=0; $s<$len; $s++) {
344                    $dev_t[$curr_t-$from_t+$s]++;
345                    $dev_sum_t[$curr_t-$from_t+$s]++;
346            }
347    
348          $curr_t += $len;          $curr_t += $len;
349    
# Line 216  while(my $row = $sth->fetchrow_hashref) Line 351  while(my $row = $sth->fetchrow_hashref)
351                    
352  }  }
353    
354    if ($curr_t == $from_t) {       # no entries in database!
355            print "<tr><td></td><td colspan=2>";
356    }
357    
358  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
359          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
360          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
361          print bar($t);          print bar($t);
362  }  }
363    
364  undef $sth;  undef $sth;
365  $dbh->disconnect;  $dbh->disconnect;
366    
367  print "</td></tr>\n</table>";  print "</td></tr>\n";
368    sum_bar("summary for $dev",@dev_t);
369    hour_grid();
370    sum_bar("summary for all devices",@dev_sum_t);
371    print "</table>";
372    
373    
374  # label and usage  # label and usage
# Line 235  print "<hr>\nColors for statuses and usa Line 378  print "<hr>\nColors for statuses and usa
378  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";
379  foreach my $status (keys %count) {  foreach my $status (keys %count) {
380  #foreach my $status (keys %cols) {  #foreach my $status (keys %cols) {
381          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 "");          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 "");
382            # *1 in line above is a cludge to display correct number on
383            # occurences on graph and without one on legend! If you remove * op
384            # it will first evaluate bar sub (thus increasing number by one) and
385            # then display number (wrongly).
386  }  }
387  print "</table>\n</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>";
388    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.26