/[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.3 by dpavlin, Thu Sep 12 16:35:35 2002 UTC revision 1.13 by dpavlin, Fri Sep 13 22:48: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);
10    
11  # default range  my $debug = 0;
 my $from="2002-09-11 18:00";  
 my $to="2002-09-13 00:00:00";  
12    
13  my $debug = 1;  my $width = 600;        # width of bar
14  my $width = 800;  my $height = 19;        # height of bar
15    my $use_js = 1;         # use JavaScript pop-up
 #--- no user servicable parts below this line  
16    
17    # status colors
18  my %cols = (  my %cols = (
19          'In Progress'           => '0,255,0',          'In Progress'           => '0,255,0',
20          'In Progress/Failure'   => '255,128,128',          'In Progress/Failure'   => '255,64,255',
21          'In Progress/Errors'    => '255,128,128',          'In Progress/Errors'    => '255,64,0',
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',
25          'Completed',            => '0,255,0',          'Completed'             => '64,255,64',
26          'Completed/Errors'      => '0,255,255',          'Completed/Errors'      => '255,128,0',
27          'Completed/Failure',    => '0,255,255'          'Completed/Failure'     => '128,0,128',
28            '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
36    
37    # time range
38    
39    $int_t = m_round($int_t);
40    
41    my ($from_t,$to_t) = (time()-$int_t,time());
42    
43    $to_t = param('to_t') if (param('to_t'));
44    $from_t = param('from_t') if (param('from_t'));
45    
46    # round to nearest minute
47    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
60    my %count;      
61    
62  if (param('pic')) {  if (param('pic')) {
63          print "Content-type: image/png\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 43  if (param('pic')) { Line 74  if (param('pic')) {
74          exit;          exit;
75  }  }
76    
77  print "Content-type: text/html\n\n";  print "Content-type: text/html
78    
79    <html>
80    <head>
81    <title>OmniBack Gantt: $from - $to</title>";
82    if ($use_js) {
83    print '
84    <script type="text/javascript" language="javascript" src="1k.js"></script>
85    <script type="text/javascript" language="javascript" src="tooltip.js"></script>
86    <script language="javascript" type="text/javascript">
87        onload=function(){
88            T.init()
89            T.follows = false // false by default
90            T.delay = .3     // any nonnegative value (0.7 by default)
91        }
92    </script>
93    ';
94    }
95    print "</head><body>";
96    
97  # all vars ending in *_t have utime in them.  # all vars ending in *_t have utime in them.
98  #  #
 my $from_t = str2time($from);  
 my $to_t = str2time($to);  
99  my $len_t = $to_t - $from_t;  my $len_t = $to_t - $from_t;
100    
101  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 ($len_t < 1);
# Line 57  my $dbh = DBI->connect("DBI:Pg:dbname=ga Line 104  my $dbh = DBI->connect("DBI:Pg:dbname=ga
104  my $q=new CGI;  my $q=new CGI;
105    
106    
107  print "<table>";  sub mknav {
108  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>\n";          my $f = shift @_;       # from_t
109            my $t = shift @_;       # to_t
110            my $ch = shift @_;      # char
111    
112            return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";
113    }
114    
115    print "<table cellspacing=0 cellpadding=0>";
116    print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
117    print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;
118    print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);
119    print "</td><td align=right>";
120    print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);
121    print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
122    
123    # draw hour grid
124    sub hour_grid {
125            print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";
126            my @c = ("255,255,128","255,192,128");
127            my $hr=strftime("%H",localtime ($from_t));
128            my $min_l=1;
129            print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24));
130            for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {
131                    print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24));
132                    push @c, shift @c;
133            }
134            print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24));
135            print "</td></tr>\n";
136    }
137    
138    hour_grid();
139    
140    my $fix_d = 0;  # used to fix graph len (in pixels)
141    my $fix_s = 0;  # used to collect round errors of size
142    
143  sub draw {  sub bar {
144          my $l = shift @_;       # lenght of event utime          my $l = shift @_;
145          my $status = shift @_;  # what to draw          my $status = shift @_;
146          my $alt = shift @_;          my $alt = shift @_;
147    
148          my $size = int($l / ($len_t / $width)) || 1;    # dump size (min. size=1)          my $col;
149    
150            if ($status) {
151                    if ($cols{$status}) {
152                            $col .= $cols{$status};
153                    } else {
154                            $col .= "0,0,0";        # unknown status, black
155                    }
156                    $count{$status}++;
157            } else {
158    #               $col .= '240,240,240';
159                    $col .= '220,220,220';
160            }
161            return color_bar($l,$col,$alt,$min_l);
162    }
163    
164    sub color_bar {
165            my $l = shift @_;                       # lenght of event utime
166            my $col = shift @_ || '240,240,240';    # default color (filler)
167            my $alt = shift @_ || undef;
168            my $min_l = shift @_ || 1;
169    
170            my $size = $l / ($len_t / $width);
171            $fix_s += $size - int($size);
172            $size=int($size);
173            # add rounding error to size
174            if ($fix_s > 1) {
175                    my $i = $fix_s ; $i = int($i);
176                    $fix_s -= $i;
177                    $size += $i;
178            }
179    
180          print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug);          if ($alt && $size < $min_l) {
181                    $fix_d += ($min_l - $size);
182                    print STDERR "fix_d: $fix_d\n" if ($debug);
183                    $size = $min_l;
184            }
185            if ($fix_d && $size > $fix_d+$min_l) {
186                    $size -= $fix_d;
187                    $fix_d = 0;
188                    print STDERR "fix_d: $fix_d\n" if ($debug);
189            }
190    
191          my $col = $cols{$status} || '240,240,240';          print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug);
192          print "<img src=".$q->url(-relative=>1)."?pic=$col width=$size height=8 alt=\"$alt\">";  
193            my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\"";
194    
195            if ($use_js && $alt) {
196                    $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
197            } elsif ($alt) {
198                    $html .= " alt=\"$alt\"";
199            }
200            $html .= ">";
201    
202            return($html);
203  }  }
204    
205  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,
206                    type,sessionid,device,host
207          from gantt          from gantt
208          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
209          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
210          order by specification          order by device,specification
211          ";          ";
212    
213  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
# Line 92  my $curr_t = $from_t; Line 220  my $curr_t = $from_t;
220  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
221    
222  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
223          if ($row->{specification} ne $curr_spec) {          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
224    
225                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
226                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
227                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
228                          draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});                          print bar($t);
229                  }                  }
230    
231                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != $from_t);
232                    ($fix_s,$fix_d) = (0,0); # init fix vars for bar
233                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
234    
235                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 111  while(my $row = $sth->fetchrow_hashref) Line 240  while(my $row = $sth->fetchrow_hashref)
240          my $start_t = str2time($row->{start});          my $start_t = str2time($row->{start});
241          my $fin_t = str2time($row->{finish});          my $fin_t = str2time($row->{finish});
242    
243          if ($start_t > $curr_t) {          # Can I squeeze here 1 pixel of time (many seconds) ?
244            if ($start_t > $curr_t + ($len_t / $width)) {
245                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
246                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
247                  draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});                  print bar($t);
248                  $curr_t = $start_t;                  $curr_t = $start_t;
249          }          }
250    
# Line 128  while(my $row = $sth->fetchrow_hashref) Line 258  while(my $row = $sth->fetchrow_hashref)
258                  $len = ($fin_t - $curr_t);                  $len = ($fin_t - $curr_t);
259                  $less = "<<";                  $less = "<<";
260          }          }
261    
262          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
263  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
264                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 135  while(my $row = $sth->fetchrow_hashref) Line 266  while(my $row = $sth->fetchrow_hashref)
266          }          }
267    
268          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
269          draw($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});  
270            my $alt = $row->{start}." - ".$row->{finish}."<br>";
271            $alt =~ s/:\d\d\.\d+//g;
272            $alt =~ s/\s+/&nbsp;/g;
273            $alt .= $row->{type}." <b>".$row->{status}."</b><br>".
274            $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
275            $row->{device}."&nbsp;on&nbsp;".$row->{host};
276            print bar($len,$row->{status},$alt);
277    
278          $curr_t += $len;          $curr_t += $len;
279    
# Line 143  while(my $row = $sth->fetchrow_hashref) Line 281  while(my $row = $sth->fetchrow_hashref)
281                    
282  }  }
283    
284    if ($curr_t == $from_t) {       # no entries in database!
285            print "<tr><td></td><td colspan=2>";
286    }
287    
288  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
289          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
290          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
291          draw($t);          print bar($t);
292  }  }
293    
294  undef $sth;  undef $sth;
295  $dbh->disconnect;  $dbh->disconnect;
296    
297  print "</td></tr>\n</table>";  print "</td></tr>\n";
298    hour_grid();
299    print "</table>";
300    
301    
302    # label and usage
303    $len_t = 50; # disable bar scaling
304    
305    print "<hr>\nColors for statuses and usage (#):\n";
306    print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n";
307    foreach my $status (keys %count) {
308    #foreach my $status (keys %cols) {
309            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 "");
310            # *1 in line above is a cludge to display correct number on
311            # occurences on graph and without one on legend! If you remove * op
312            # it will first evaluate bar sub (thus increasing number by one) and
313            # then display number (wrongly).
314    }
315    print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";
316    

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

  ViewVC Help
Powered by ViewVC 1.1.26