/[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.12 by dpavlin, Fri Sep 13 19:06:46 2002 UTC revision 1.26 by dpavlin, Mon Dec 2 17:14:48 2002 UTC
# Line 11  use POSIX qw(strftime); Line 11  use POSIX qw(strftime);
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',
# Line 27  my %cols = ( Line 28  my %cols = (
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',          'Mount/Errors'          => '255,64,128',
31            'Mount/Failures'        => '255,128,192',
32          );          );
33    
34  my $int_t = (12 * 60 * 60);     # interval to display on one screen  my $int_t = (12 * 60 * 60);     # interval to display on one screen
# Line 34  my $min_l = 3;                 # min length of bar seg Line 36  my $min_l = 3;                 # min length of bar seg
36    
37  #--- no user servicable parts below this line  #--- no user servicable parts below this line
38    
39  # time range  my $q=new CGI;
   
 $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    
 $to_t = param('to_t') if (param('to_t'));  
43  $from_t = param('from_t') if (param('from_t'));  $from_t = param('from_t') if (param('from_t'));
44    $to_t = param('to_t') if (param('to_t'));
45    
46    if (param('f-1')) {
47            $from_t = $from_t - param('int_f-1') || $int_t;
48    } elsif (param('f+1')) {
49            $from_t = $from_t + param('int_f+1') || $int_t;
50    } elsif (param('t-1')) {
51            $to_t = $from_t - param('int_t-1') || $int_t;
52    } elsif (param('t+1')) {
53            $to_t = $from_t + $int_t;
54    }
55    
56    # time range
57    $int_t = m_round($int_t);
58    
59  # round to nearest minute  # round to nearest minute
60  sub m_round {  sub m_round {
# Line 59  my $from=strftime("%Y-%m-%d %H:%M",local Line 72  my $from=strftime("%Y-%m-%d %H:%M",local
72  # keep count of each status  # keep count of each status
73  my %count;        my %count;      
74    
75  if (param('pic')) {  if (path_info()) {
76          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";
77          # create picture using GD          # create picture using GD
78          use GD;          use GD;
79          my $im = new GD::Image(1,$height);          my $im = new GD::Image(1,$height);
80          my $back = $im->colorAllocate(255,255,255);          my $back = $im->colorAllocate(255,255,255);
81          $im->transparent($back);          $im->transparent($back);
82          my ($r,$g,$b) = split(/,/,param('pic'));          my $col = path_info(); $col =~ s,/,,g;
83          my $col = $im->colorAllocate($r,$g,$b);          my ($r,$g,$b) = split(/,/,$col);
84            $col = $im->colorAllocate($r,$g,$b);
85          $im->fill(0,0,$col);          $im->fill(0,0,$col);
86            print "Content-Length: ",length($im->png),"\n\n";
87          binmode STDOUT;          binmode STDOUT;
88          print $im->png;          print $im->png;
89          exit;          exit;
90  }  }
91    
92    # open DBI connection
93    my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
94    
95  print "Content-type: text/html  print "Content-type: text/html
96    Cache-Control: max-age=60, must-revalidate
97    
98  <html>  <html>
99  <head>  <head>
100  <title>OmniBack Gantt: $from - $to</title>";  <title>OmniBack Gantt: $from - $to</title>
101    <meta HTTP-EQUIV=\"Refresh\" CONTENT=600>";
102  if ($use_js) {  if ($use_js) {
103  print '  print '
104  <script type="text/javascript" language="javascript" src="1k.js"></script>  <script type="text/javascript" language="javascript" src="1k.js"></script>
# Line 92  print ' Line 112  print '
112  </script>  </script>
113  ';  ';
114  }  }
115  print "</head><body>";  print "</head><body>
116            <form action=".$q->url(-relative=>1)." method=get>
117            <input type=hidden name=from_t value=$from_t>
118            <input type=hidden name=to_t value=$to_t>
119    ";
120    
121  # all vars ending in *_t have utime in them.  # all vars ending in *_t have utime in them.
122  #  #
123  my $len_t = $to_t - $from_t;  my $len_t = $to_t - $from_t;
124    
125  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 (abs($len_t) < 1);
   
 my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;  
 my $q=new CGI;  
126    
127    
128  sub mknav {  sub mknav {
129          my $f = shift @_;       # from_t          my $f = shift @_;       # from_t
130          my $t = shift @_;       # to_t          my $t = shift @_;       # to_t
131            my $d = shift @_;       # delta
132          my $ch = shift @_;      # char          my $ch = shift @_;      # char
133    
134          return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";          return "
135            <select name=int_${d}>
136            <option value=".(12*60*60).">12h</option>
137            <option value=".(24*60*60).">day</option>
138            <option value=".(7*24*60*60).">week</option>
139            </select>
140            <input type=submit name=$d value=\"$ch\">
141            ";
142            #return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";
143  }  }
144    
145  print "<table cellspacing=0 cellpadding=0>";  print "<table cellspacing=0 cellpadding=0>";
146  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
147  print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;  print mknav($from_t,$to_t,'f-1','&lt;&lt;'),$from;
148  print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);  print mknav($from_t,$to_t,'f+1','&gt;&gt;') if ($from_t+$int_t < $to_t);
149  print "</td><td align=right>";  print "</td><td align=right>";
150  print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);  print mknav($from_t,$to_t,'t-1','&lt;&lt;') if ($to_t+$int_t > $from_t);
151  print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";  print $to,mknav($from_t,$to_t,'t+1','&gt;&gt;'),"</td></tr>\n";
152    
153  # draw hour grid  # draw hour grid
154  sub hour_grid {  sub hour_grid {
155          print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";          print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";
156          my @c = ("255,255,128","255,192,128");          my @c = ("255,255,128","255,192,128");
157          my $hr=strftime("%H",localtime ($from_t));          my $hr=strftime("%H",localtime ($from_t));
158          print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24));          sub hour_bar {
159                    my ($t,$c,$hr) = @_;
160                    my $clock_hr = $hr % 24;
161                    my $alt = sprintf("%02d:00",$clock_hr);
162                    if ($clock_hr == 0) {
163                            my $pix_hr = int(1 / $width);
164                            print color_bar($pix_hr,"0,0,0",strftime("%Y-%m-%d", localtime($from_t + $hr*3600)));
165                            print color_bar($t-$pix_hr,$c,$alt);
166                    } else {
167                            print color_bar($t,$c,$alt);
168                    }
169            }
170            hour_bar(3600 - $from_t % 3600,$c[0],$hr++);
171          for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {          for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {
172                  print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24));                  hour_bar(3600,$c[1],$hr++);
173                  push @c, shift @c;                  push @c, shift @c;
174          }          }
175          print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24));          hour_bar($from_t % 3600,$c[1],$hr);
176          print "</td></tr>\n";          print "</td></tr>\n";
177  }  }
178    
# Line 157  sub bar { Line 199  sub bar {
199  #               $col .= '240,240,240';  #               $col .= '240,240,240';
200                  $col .= '220,220,220';                  $col .= '220,220,220';
201          }          }
202          return color_bar($l,$col,$alt);          return color_bar($l,$col,$alt,$min_l);
203  }  }
204    
205  sub color_bar {  sub color_bar {
206          my $l = shift @_;                       # lenght of event utime          my $l = shift @_;                       # lenght of event utime
207          my $col = shift @_ || '240,240,240';    # default color (filler)          my $col = shift @_ || '240,240,240';    # default color (filler)
208          my $alt = shift @_ || undef;          my $alt = shift @_ || undef;
209            my $min_l = shift @_ || 1;
210            my $h = shift @_ || $height;
211    
212          my $size = $l / ($len_t / $width);          my $size = $l / ($len_t / $width);
213          $fix_s += $size - int($size);          $fix_s += $size - int($size);
214          $size=int($size);          $size=int($size);
215            # add rounding error to size
216          if ($fix_s > 1) {          if ($fix_s > 1) {
217                  $fix_s -= 1;                  my $i = $fix_s ; $i = int($i);
218                  $size++;                  $fix_s -= $i;
219                    $size += $i;
220          }          }
221    
222          if ($alt && $size < $min_l) {          if ($alt && $size < $min_l) {
# Line 186  sub color_bar { Line 232  sub color_bar {
232    
233          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);
234    
235          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\"";
236    
237          if ($use_js && $alt) {          if ($use_js && $alt) {
238                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
# Line 203  my $sql = "select start,finish,specifica Line 249  my $sql = "select start,finish,specifica
249          from gantt          from gantt
250          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
251          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
252          order by device,specification          order by device,specification,start
253          ";          ";
254    
255  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
256    print STDERR "sql: $sql\n" if ($debug);
257    
258  my %spec;       # specification hash  my %spec;       # specification hash
259    
260  my $curr_spec;  my $curr_spec = "";
261  my $curr_t = $from_t;  my $curr_t = $from_t;
262    
263  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
264    
265    my $dev;        # current device
266    my @dev_t;      # all minutes in one hour [1440]
267    my @dev_sum_t;
268    
269    sub sum_bar {
270            my $label = shift @_;
271            my @dev_t = @_;
272            # display device summary
273            my $max_use = 0;
274            for (my $i=0; $i < $len_t; $i++) {
275                    $max_use = $dev_t[$i] if (defined $dev_t[$i] && $dev_t[$i] > $max_use);
276            }
277            print "<tr><td align=right><small>$label [$max_use]</small></td><td colspan=2>";
278            my $last_var = 0;
279            my $len = 0;
280            for (my $i=1; $i<= ($to_t-$from_t); $i++) {
281                    my $v = $dev_t[$i] || 0;
282                    if ($v == $last_var) {
283                            $len++;
284                    } else {
285                            my $h = $last_var / $max_use * $height;
286                            my $c = 255 - int (255 * $last_var / $max_use);
287                            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1);
288                            $len = 0;
289                            $last_var = $v;
290                    }
291            }
292            my $h = $last_var / $max_use * $height;
293            my $c = 255 - int (255 * $last_var / $max_use);
294            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len);
295            print "</td></tr>";
296    }
297    
298    my @line_t;     # all seconds for this specification
299    my @line_arr = ("");    # all segments on line which are not fillers
300    
301    sub html_spec {
302            print "<tr><td>$curr_spec</td><td colspan=2>";
303    
304            my $last_var = 0;
305            my $len = 0;
306            my $i;
307            for (my $t=0; $t<=$len_t; $t++) {
308                    $i = $line_t[$t] || 0;
309                    if ($i == $last_var) {
310                            $len++;
311                    } else {
312                            if ($last_var == 0) {
313                                    print bar($len);
314                            } else {
315                                    print bar($len,split(/\t/,$line_arr[$last_var],2));
316                            }
317                            $len = 0;
318                            $last_var = $i;
319                    }
320            }
321            print bar($len,split(/\t/,$line_arr[$i],2));
322    
323            print "</td></tr>\n";
324    }
325    
326  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
327          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {          if ($row->{specification} ne $curr_spec) {
328    
329                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
330                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
331                          print STDERR "[end filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
332                          print bar($t);  #                       print bar($t);
333                  }                  }
334    
335                  print "</td></tr>\n" if ($curr_t != $from_t);  #               print "</td></tr>\n" if ($curr_t != $from_t);
336                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";  
337    
338                    # init vars for next line
339                    ($fix_s,$fix_d) = (0,0); # init fix vars for bar
340    
341                    if ($curr_spec ne "") {
342                            $curr_spec =~ s/ +/&nbsp;/g;
343                            html_spec;
344                    }
345    
346                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
347                  $curr_spec = $row->{specification};                  $curr_spec = $row->{specification};
348    
349                    @line_t = ();
350                    @line_arr = ( "" );
351    
352                    if ($dev && @dev_t && $dev ne $row->{device}) {
353                            sum_bar("summary for $dev",@dev_t);
354                            $dev = $row->{device};
355                            @dev_t = ();
356                    } elsif (! $dev) {
357                            $dev = $row->{device};
358                    }
359          }          }
360    
361          my $start_t = m_round(str2time($row->{start}));          my $start_t = str2time($row->{start});
362          my $fin_t = m_round(str2time($row->{finish}));          my $fin_t = str2time($row->{finish});
363    
364          if ($start_t > $curr_t + 60) {          # Can I squeeze here 1 pixel of time (many seconds) ?
365            if ($start_t > $curr_t + ($len_t / $width)) {
366                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
367                  print STDERR "[middle filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
368                  print bar($t);  #               print bar($t);
369                  $curr_t = $start_t;                  $curr_t = $start_t;
370            } else {
371                    # prepend too few seconds to next event
372                    $start_t = $curr_t;
373          }          }
374    
375          my $len = $fin_t - $start_t;          my $len = $fin_t - $start_t;
# Line 264  while(my $row = $sth->fetchrow_hashref) Line 394  while(my $row = $sth->fetchrow_hashref)
394          my $alt = $row->{start}." - ".$row->{finish}."<br>";          my $alt = $row->{start}." - ".$row->{finish}."<br>";
395          $alt =~ s/:\d\d\.\d+//g;          $alt =~ s/:\d\d\.\d+//g;
396          $alt =~ s/\s+/&nbsp;/g;          $alt =~ s/\s+/&nbsp;/g;
397          $alt .= $row->{type}." <b>".$row->{status}."</b><br>".          $alt .= $row->{specification}."<br>".
398          $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".                  $row->{type}." <b>".$row->{status}."</b><br>".
399          $row->{device}."&nbsp;on&nbsp;".$row->{host};                  $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
400          print bar($len,$row->{status},$alt);                  $row->{device}."&nbsp;on&nbsp;".$row->{host};
401    #       print bar($len,$row->{status},$alt);
402    
403            push @line_arr,$row->{status}."\t".$alt;
404            # store use of devices for each minute
405            for (my $s=0; $s<$len; $s++) {
406                    $line_t[$curr_t-$from_t+$s] = $#line_arr;
407                    $dev_t[$curr_t-$from_t+$s]++;
408                    $dev_sum_t[$curr_t-$from_t+$s]++;
409            }
410    
411          $curr_t += $len;          $curr_t += $len;
412    
# Line 276  while(my $row = $sth->fetchrow_hashref) Line 415  while(my $row = $sth->fetchrow_hashref)
415  }  }
416    
417  if ($curr_t == $from_t) {       # no entries in database!  if ($curr_t == $from_t) {       # no entries in database!
418          print "<tr><td></td><td colspan=2>";  #       print "<tr><td></td><td colspan=2>";
419  }  }
420    
421  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
422          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
423          print STDERR "[last_line filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
         print bar($t);  
424  }  }
425    
426  undef $sth;  undef $sth;
427  $dbh->disconnect;  $dbh->disconnect;
428    
429  print "</td></tr>\n";  html_spec();
430    sum_bar("summary for $dev",@dev_t);
431  hour_grid();  hour_grid();
432    sum_bar("summary for all devices",@dev_sum_t);
433  print "</table>";  print "</table>";
434    
435    
436  # label and usage  # label and usage
 $len_t = 50; # disable bar scaling  
437    
438  print "<hr>\nColors for statuses and usage (#):\n";  print "<hr>\nColors for statuses and usage (#):\n";
439  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";
440    my $max = 0;
441    foreach my $status (keys %count) {
442            $max = $count{$status} if ($count{$status} > $max);
443    }
444    $len_t = $max ; # disable bar scaling
445    
446  foreach my $status (keys %count) {  foreach my $status (keys %count) {
447  #foreach my $status (keys %cols) {  #foreach my $status (keys %cols) {
448          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 "");
# Line 306  foreach my $status (keys %count) { Line 451  foreach my $status (keys %count) {
451          # it will first evaluate bar sub (thus increasing number by one) and          # it will first evaluate bar sub (thus increasing number by one) and
452          # then display number (wrongly).          # then display number (wrongly).
453  }  }
454  print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";  print "</table></form>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>";
   

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.26