/[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.20 by dpavlin, Mon Sep 16 15:09:19 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          'Aborted'               => '255,0,0',          'Aborted'               => '255,0,0',
24          'Failed'                => '255,0,0',          'Failed'                => '255,0,0',
# Line 23  my %cols = ( Line 26  my %cols = (
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
33    my $min_l = 3;                  # min length of bar segment (in pixels)
34    
35  #--- no user servicable parts below this line  #--- no user servicable parts below this line
36    
37  # time range  # time range
38    
39  my $day_t = (24 * 60 * 60);     # 24h interval  $int_t = m_round($int_t);
40    
41  my ($from_t,$to_t) = (time()-$day_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  my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t));  # round to nearest minute
47  my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t));  sub m_round {
48            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));
56    my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t));
57    
58    
59  # keep count of each status  # keep count of each status
# Line 47  if (param('pic')) { Line 63  if (param('pic')) {
63          print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";          print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
64          # create picture using GD          # create picture using GD
65          use GD;          use GD;
66          my $im = new GD::Image(1,8);          my $im = new GD::Image(1,$height);
67          my $back = $im->colorAllocate(255,255,255);          my $back = $im->colorAllocate(255,255,255);
68          $im->transparent($back);          $im->transparent($back);
69          my ($r,$g,$b) = split(/,/,param('pic'));          my ($r,$g,$b) = split(/,/,param('pic'));
# Line 59  if (param('pic')) { Line 75  if (param('pic')) {
75  }  }
76    
77  print "Content-type: text/html  print "Content-type: text/html
78    Cache-Control: max-age=60, must-revalidate
79    
80  <html>  <html>
81  <head>  <head>
82  <title>OmniBack Gantt: $from - $to</title>";  <title>OmniBack Gantt: $from - $to</title>
83    <meta HTTP-EQUIV=\"Refresh\" CONTENT=60>";
84  if ($use_js) {  if ($use_js) {
85  print '  print '
86  <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 114  sub mknav {
114          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>";
115  }  }
116    
117  print "<table>";  print "<table cellspacing=0 cellpadding=0>";
118  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
119  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;
120  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);
121  print "</td><td align=right>";  print "</td><td align=right>";
122  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);
123  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";
124    
125    # draw hour grid
126    sub hour_grid {
127            print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";
128            my @c = ("255,255,128","255,192,128");
129            my $hr=strftime("%H",localtime ($from_t));
130            sub hour_bar {
131                    my ($t,$c,$hr) = @_;
132                    my $clock_hr = $hr % 24;
133                    my $alt = sprintf("%02d:00",$clock_hr);
134                    if ($clock_hr == 0) {
135                            my $pix_hr = int(1 / $width);
136                            print color_bar($pix_hr,"0,0,0",strftime("%Y-%m-%d", localtime($from_t + $hr*3600)));
137                            print color_bar($t-$pix_hr,$c,$alt);
138                    } else {
139                            print color_bar($t,$c,$alt);
140                    }
141            }
142            hour_bar(3600 - $from_t % 3600,$c[0],$hr++);
143            for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {
144                    hour_bar(3600,$c[1],$hr++);
145                    push @c, shift @c;
146            }
147            hour_bar($from_t % 3600,$c[1],$hr);
148            print "</td></tr>\n";
149    }
150    
151    hour_grid();
152    
153  my $fix_d = 0;  # used to fix graph len  my $fix_d = 0;  # used to fix graph len (in pixels)
154  my $min_l = 3;  # min length;  my $fix_s = 0;  # used to collect round errors of size
155    
156  sub bar {  sub bar {
157          my $l = shift @_;       # lenght of event utime          my $l = shift @_;
158          my $status = shift @_ || undef; # what to draw          my $status = shift @_;
159            my $alt = shift @_;
160    
161            my $col;
162    
163            if ($status) {
164                    if ($cols{$status}) {
165                            $col .= $cols{$status};
166                    } else {
167                            $col .= "0,0,0";        # unknown status, black
168                    }
169                    $count{$status}++;
170            } else {
171    #               $col .= '240,240,240';
172                    $col .= '220,220,220';
173            }
174            return color_bar($l,$col,$alt,$min_l);
175    }
176    
177    sub color_bar {
178            my $l = shift @_;                       # lenght of event utime
179            my $col = shift @_ || '240,240,240';    # default color (filler)
180          my $alt = shift @_ || undef;          my $alt = shift @_ || undef;
181            my $min_l = shift @_ || 1;
182            my $h = shift @_ || $height;
183    
184          my $size = int($l / ($len_t / $width));          my $size = $l / ($len_t / $width);
185          if ($size < $min_l) {          $fix_s += $size - int($size);
186            $size=int($size);
187            # add rounding error to size
188            if ($fix_s > 1) {
189                    my $i = $fix_s ; $i = int($i);
190                    $fix_s -= $i;
191                    $size += $i;
192            }
193    
194            if ($alt && $size < $min_l) {
195                    $fix_d += ($min_l - $size);
196                    print STDERR "fix_d: $fix_d\n" if ($debug);
197                  $size = $min_l;                  $size = $min_l;
                 $fix_d += $min_l;  
198          }          }
199          if ($fix_d && $size > $fix_d+$min_l) {          if ($fix_d && $size > $fix_d+$min_l) {
200                  $size -= $fix_d;                  $size -= $fix_d;
201                  $fix_d = 0;                  $fix_d = 0;
202                    print STDERR "fix_d: $fix_d\n" if ($debug);
203          }          }
204    
205          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=";  
206    
207          if ($status) {          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$h\"";
                 $html .= $cols{$status};  
                 $count{$status}++;  
         } else {  
 #               $html .= '240,240,240';  
                 $html .= '220,220,220';  
         }  
208    
         $html .= "\" width=\"$size\" height=\"12\"";  
209          if ($use_js && $alt) {          if ($use_js && $alt) {
210                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
211          } elsif ($alt) {          } elsif ($alt) {
# Line 145  sub bar { Line 216  sub bar {
216          return($html);          return($html);
217  }  }
218    
219  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,
220                    type,sessionid,device,host
221          from gantt          from gantt
222          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
223          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
224          order by specification          order by device,specification,start
225          ";          ";
226    
227  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 233  my $curr_t = $from_t;
233    
234  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
235    
236    my $dev;        # current device
237    my @dev_t;      # all minutes in one hour [1440]
238    my @dev_sum_t;
239    
240    sub sum_bar {
241            my $label = shift @_;
242            my @dev_t = @_;
243            # display device summary
244            my $max_use = 0;
245            for (my $i=0; $i < $len_t; $i++) {
246                    $max_use = $dev_t[$i] if (defined $dev_t[$i] && $dev_t[$i] > $max_use);
247            }
248            print "<tr><td align=right><small>$label [$max_use]</small></td><td colspan=2>";
249            my $last_var = 0;
250            my $len = 0;
251            for (my $i=1; $i<= ($to_t-$from_t); $i++) {
252                    my $v = $dev_t[$i] || 0;
253                    if ($v == $last_var) {
254                            $len++;
255                    } else {
256                            my $h = $last_var / $max_use * $height;
257                            my $c = 255 - 255 * $last_var / $max_use;
258                            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1);
259                            $len = 0;
260                            $last_var = $v;
261                    }
262            }
263            my $h = $last_var / $max_use * $height;
264            my $c = 255 - 255 * $last_var / $max_use;
265            print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len);
266            print "</td></tr>";
267    }
268    
269  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
270          if ($row->{specification} ne $curr_spec) {          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
271    
272                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
273                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
274                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
275                          print bar($t);                          print bar($t);
276                  }                  }
277    
278                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != $from_t);
279    
280                    if ($dev && @dev_t && $dev ne $row->{device}) {
281                            sum_bar("summary for $dev",@dev_t);
282                            $dev = $row->{device};
283                            @dev_t = ();
284                    } elsif (! $dev) {
285                            $dev = $row->{device};
286                    }
287    
288                    # init vars for next line
289                    ($fix_s,$fix_d) = (0,0); # init fix vars for bar
290                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
291    
292                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 181  while(my $row = $sth->fetchrow_hashref) Line 297  while(my $row = $sth->fetchrow_hashref)
297          my $start_t = str2time($row->{start});          my $start_t = str2time($row->{start});
298          my $fin_t = str2time($row->{finish});          my $fin_t = str2time($row->{finish});
299    
300          if ($start_t > $curr_t) {          # Can I squeeze here 1 pixel of time (many seconds) ?
301            if ($start_t > $curr_t + ($len_t / $width)) {
302                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
303                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
304                  print bar($t);                  print bar($t);
305                  $curr_t = $start_t;                  $curr_t = $start_t;
306            } else {
307                    # prepend too few seconds to next event
308                    $start_t = $curr_t;
309          }          }
310    
311          my $len = $fin_t - $start_t;          my $len = $fin_t - $start_t;
# Line 199  while(my $row = $sth->fetchrow_hashref) Line 319  while(my $row = $sth->fetchrow_hashref)
319                  $less = "<<";                  $less = "<<";
320          }          }
321    
         next if ($fin_t > $to_t);  
           
322          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
323  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
324                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 208  while(my $row = $sth->fetchrow_hashref) Line 326  while(my $row = $sth->fetchrow_hashref)
326          }          }
327    
328          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
329          print bar($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});  
330            my $alt = $row->{start}." - ".$row->{finish}."<br>";
331            $alt =~ s/:\d\d\.\d+//g;
332            $alt =~ s/\s+/&nbsp;/g;
333            $alt .= $row->{specification}."<br>".
334                    $row->{type}." <b>".$row->{status}."</b><br>".
335                    $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
336                    $row->{device}."&nbsp;on&nbsp;".$row->{host};
337            print bar($len,$row->{status},$alt);
338    
339            # store use of devices for each minute
340            for (my $s=0; $s<$len; $s++) {
341                    $dev_t[$curr_t-$from_t+$s]++;
342                    $dev_sum_t[$curr_t-$from_t+$s]++;
343            }
344    
345          $curr_t += $len;          $curr_t += $len;
346    
# Line 216  while(my $row = $sth->fetchrow_hashref) Line 348  while(my $row = $sth->fetchrow_hashref)
348                    
349  }  }
350    
351    if ($curr_t == $from_t) {       # no entries in database!
352            print "<tr><td></td><td colspan=2>";
353    }
354    
355  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
356          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
357          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
358          print bar($t);          print bar($t);
359  }  }
360    
361  undef $sth;  undef $sth;
362  $dbh->disconnect;  $dbh->disconnect;
363    
364  print "</td></tr>\n</table>";  print "</td></tr>\n";
365    sum_bar("summary for $dev",@dev_t);
366    hour_grid();
367    sum_bar("summary for all devices",@dev_sum_t);
368    print "</table>";
369    
370    
371  # label and usage  # label and usage
# Line 235  print "<hr>\nColors for statuses and usa Line 375  print "<hr>\nColors for statuses and usa
375  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";
376  foreach my $status (keys %count) {  foreach my $status (keys %count) {
377  #foreach my $status (keys %cols) {  #foreach my $status (keys %cols) {
378          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 "");
379            # *1 in line above is a cludge to display correct number on
380            # occurences on graph and without one on legend! If you remove * op
381            # it will first evaluate bar sub (thus increasing number by one) and
382            # then display number (wrongly).
383  }  }
384  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>";
385    

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

  ViewVC Help
Powered by ViewVC 1.1.26