/[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.13 by dpavlin, Fri Sep 13 22:48:19 2002 UTC revision 1.24 by dpavlin, Mon Nov 18 08:09:58 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 = 19;        # 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 59  my $from=strftime("%Y-%m-%d %H:%M",local Line 61  my $from=strftime("%Y-%m-%d %H:%M",local
61  # keep count of each status  # keep count of each status
62  my %count;        my %count;      
63    
64  if (param('pic')) {  if (path_info()) {
65          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";
66          # create picture using GD          # create picture using GD
67          use GD;          use GD;
68          my $im = new GD::Image(1,$height);          my $im = new GD::Image(1,$height);
69          my $back = $im->colorAllocate(255,255,255);          my $back = $im->colorAllocate(255,255,255);
70          $im->transparent($back);          $im->transparent($back);
71          my ($r,$g,$b) = split(/,/,param('pic'));          my $col = path_info(); $col =~ s,/,,g;
72          my $col = $im->colorAllocate($r,$g,$b);          my ($r,$g,$b) = split(/,/,$col);
73            $col = $im->colorAllocate($r,$g,$b);
74          $im->fill(0,0,$col);          $im->fill(0,0,$col);
75            print "Content-Length: ",length($im->png),"\n\n";
76          binmode STDOUT;          binmode STDOUT;
77          print $im->png;          print $im->png;
78          exit;          exit;
79  }  }
80    
81  print "Content-type: text/html  print "Content-type: text/html
82    Cache-Control: max-age=60, must-revalidate
83    
84  <html>  <html>
85  <head>  <head>
86  <title>OmniBack Gantt: $from - $to</title>";  <title>OmniBack Gantt: $from - $to</title>
87    <meta HTTP-EQUIV=\"Refresh\" CONTENT=600>";
88  if ($use_js) {  if ($use_js) {
89  print '  print '
90  <script type="text/javascript" language="javascript" src="1k.js"></script>  <script type="text/javascript" language="javascript" src="1k.js"></script>
# Line 125  sub hour_grid { Line 131  sub hour_grid {
131          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>";
132          my @c = ("255,255,128","255,192,128");          my @c = ("255,255,128","255,192,128");
133          my $hr=strftime("%H",localtime ($from_t));          my $hr=strftime("%H",localtime ($from_t));
134          my $min_l=1;          sub hour_bar {
135          print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24));                  my ($t,$c,$hr) = @_;
136                    my $clock_hr = $hr % 24;
137                    my $alt = sprintf("%02d:00",$clock_hr);
138                    if ($clock_hr == 0) {
139                            my $pix_hr = int(1 / $width);
140                            print color_bar($pix_hr,"0,0,0",strftime("%Y-%m-%d", localtime($from_t + $hr*3600)));
141                            print color_bar($t-$pix_hr,$c,$alt);
142                    } else {
143                            print color_bar($t,$c,$alt);
144                    }
145            }
146            hour_bar(3600 - $from_t % 3600,$c[0],$hr++);
147          for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {          for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {
148                  print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24));                  hour_bar(3600,$c[1],$hr++);
149                  push @c, shift @c;                  push @c, shift @c;
150          }          }
151          print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24));          hour_bar($from_t % 3600,$c[1],$hr);
152          print "</td></tr>\n";          print "</td></tr>\n";
153  }  }
154    
# Line 166  sub color_bar { Line 183  sub color_bar {
183          my $col = shift @_ || '240,240,240';    # default color (filler)          my $col = shift @_ || '240,240,240';    # default color (filler)
184          my $alt = shift @_ || undef;          my $alt = shift @_ || undef;
185          my $min_l = shift @_ || 1;          my $min_l = shift @_ || 1;
186            my $h = shift @_ || $height;
187    
188          my $size = $l / ($len_t / $width);          my $size = $l / ($len_t / $width);
189          $fix_s += $size - int($size);          $fix_s += $size - int($size);
# Line 190  sub color_bar { Line 208  sub color_bar {
208    
209          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);
210    
211          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\"";
212    
213          if ($use_js && $alt) {          if ($use_js && $alt) {
214                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
# Line 207  my $sql = "select start,finish,specifica Line 225  my $sql = "select start,finish,specifica
225          from gantt          from gantt
226          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
227          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
228          order by device,specification          order by device,specification,start
229          ";          ";
230    
231  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
232    
233  my %spec;       # specification hash  my %spec;       # specification hash
234    
235  my $curr_spec;  my $curr_spec = "";
236  my $curr_t = $from_t;  my $curr_t = $from_t;
237    
238  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
239    
240    my $dev;        # current device
241    my @dev_t;      # all minutes in one hour [1440]
242    my @dev_sum_t;
243    
244    sub sum_bar {
245            my $label = shift @_;
246            my @dev_t = @_;
247            # display device summary
248            my $max_use = 0;
249            for (my $i=0; $i < $len_t; $i++) {
250                    $max_use = $dev_t[$i] if (defined $dev_t[$i] && $dev_t[$i] > $max_use);
251            }
252            print "<tr><td align=right><small>$label [$max_use]</small></td><td colspan=2>";
253            my $last_var = 0;
254            my $len = 0;
255            for (my $i=1; $i<= ($to_t-$from_t); $i++) {
256                    my $v = $dev_t[$i] || 0;
257                    if ($v == $last_var) {
258                            $len++;
259                    } else {
260                            my $h = $last_var / $max_use * $height;
261                            my $c = 255 - int (255 * $last_var / $max_use);
262                            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1);
263                            $len = 0;
264                            $last_var = $v;
265                    }
266            }
267            my $h = $last_var / $max_use * $height;
268            my $c = 255 - int (255 * $last_var / $max_use);
269            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len);
270            print "</td></tr>";
271    }
272    
273    my @line_t;     # all seconds for this specification
274    my @line_arr = ("");    # all segments on line which are not fillers
275    
276    sub html_spec {
277            print "<tr><td>$curr_spec</td><td colspan=2>";
278    
279            my $last_var = 0;
280            my $len = 0;
281            my $i;
282            for (my $t=0; $t<=$len_t; $t++) {
283                    $i = $line_t[$t] || 0;
284                    if ($i == $last_var) {
285                            $len++;
286                    } else {
287                            if ($last_var == 0) {
288                                    print bar($len);
289                            } else {
290                                    print bar($len,split(/\t/,$line_arr[$last_var],2));
291                            }
292                            $len = 0;
293                            $last_var = $i;
294                    }
295            }
296            print bar($len,split(/\t/,$line_arr[$i],2));
297    
298            print "</td></tr>\n";
299    }
300    
301  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
302          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {          if ($row->{specification} ne $curr_spec) {
303    
304                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
305                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
306                          print STDERR "[end filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
307                          print bar($t);  #                       print bar($t);
308                  }                  }
309    
310                  print "</td></tr>\n" if ($curr_t != $from_t);  #               print "</td></tr>\n" if ($curr_t != $from_t);
311    
312    
313                    # init vars for next line
314                  ($fix_s,$fix_d) = (0,0); # init fix vars for bar                  ($fix_s,$fix_d) = (0,0); # init fix vars for bar
315                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";  
316                    html_spec if ($curr_spec ne "");
317    
318                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
319                  $curr_spec = $row->{specification};                  $curr_spec = $row->{specification};
320    
321                    @line_t = ();
322                    @line_arr = ( "" );
323    
324                    if ($dev && @dev_t && $dev ne $row->{device}) {
325                            sum_bar("summary for $dev",@dev_t);
326                            $dev = $row->{device};
327                            @dev_t = ();
328                    } elsif (! $dev) {
329                            $dev = $row->{device};
330                    }
331          }          }
332    
333          my $start_t = str2time($row->{start});          my $start_t = str2time($row->{start});
# Line 244  while(my $row = $sth->fetchrow_hashref) Line 337  while(my $row = $sth->fetchrow_hashref)
337          if ($start_t > $curr_t + ($len_t / $width)) {          if ($start_t > $curr_t + ($len_t / $width)) {
338                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
339                  print STDERR "[middle filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
340                  print bar($t);  #               print bar($t);
341                  $curr_t = $start_t;                  $curr_t = $start_t;
342            } else {
343                    # prepend too few seconds to next event
344                    $start_t = $curr_t;
345          }          }
346    
347          my $len = $fin_t - $start_t;          my $len = $fin_t - $start_t;
# Line 270  while(my $row = $sth->fetchrow_hashref) Line 366  while(my $row = $sth->fetchrow_hashref)
366          my $alt = $row->{start}." - ".$row->{finish}."<br>";          my $alt = $row->{start}." - ".$row->{finish}."<br>";
367          $alt =~ s/:\d\d\.\d+//g;          $alt =~ s/:\d\d\.\d+//g;
368          $alt =~ s/\s+/&nbsp;/g;          $alt =~ s/\s+/&nbsp;/g;
369          $alt .= $row->{type}." <b>".$row->{status}."</b><br>".          $alt .= $row->{specification}."<br>".
370          $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".                  $row->{type}." <b>".$row->{status}."</b><br>".
371          $row->{device}."&nbsp;on&nbsp;".$row->{host};                  $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
372          print bar($len,$row->{status},$alt);                  $row->{device}."&nbsp;on&nbsp;".$row->{host};
373    #       print bar($len,$row->{status},$alt);
374    
375            push @line_arr,$row->{status}."\t".$alt;
376            # store use of devices for each minute
377            for (my $s=0; $s<$len; $s++) {
378                    $line_t[$curr_t-$from_t+$s] = $#line_arr;
379                    $dev_t[$curr_t-$from_t+$s]++;
380                    $dev_sum_t[$curr_t-$from_t+$s]++;
381            }
382    
383          $curr_t += $len;          $curr_t += $len;
384    
# Line 282  while(my $row = $sth->fetchrow_hashref) Line 387  while(my $row = $sth->fetchrow_hashref)
387  }  }
388    
389  if ($curr_t == $from_t) {       # no entries in database!  if ($curr_t == $from_t) {       # no entries in database!
390          print "<tr><td></td><td colspan=2>";  #       print "<tr><td></td><td colspan=2>";
391  }  }
392    
393  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
394          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
395          print STDERR "[last_line filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
         print bar($t);  
396  }  }
397    
398  undef $sth;  undef $sth;
399  $dbh->disconnect;  $dbh->disconnect;
400    
401  print "</td></tr>\n";  html_spec();
402    sum_bar("summary for $dev",@dev_t);
403  hour_grid();  hour_grid();
404    sum_bar("summary for all devices",@dev_sum_t);
405  print "</table>";  print "</table>";
406    
407    
# Line 312  foreach my $status (keys %count) { Line 418  foreach my $status (keys %count) {
418          # it will first evaluate bar sub (thus increasing number by one) and          # it will first evaluate bar sub (thus increasing number by one) and
419          # then display number (wrongly).          # then display number (wrongly).
420  }  }
421  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> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>";
422    

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.26