/[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.6 by dpavlin, Fri Sep 13 13:55:27 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 POSIX qw(strftime);
9    
10  # default range  my $debug = 0;
 my $from="2002-09-11 18:00";  
 my $to="2002-09-13 00:00:00";  
11    
12  my $debug = 1;  my $width = 600;        # width of bar
13  my $width = 800;  my $height = 12;        # height of bar
14    my $use_js = 1;         # use JavaScript pop-up
 #--- no user servicable parts below this line  
15    
16    # status colors
17  my %cols = (  my %cols = (
18          'In Progress'           => '0,255,0',          'In Progress'           => '0,255,0',
19          'In Progress/Failure'   => '255,128,128',          'In Progress/Failure'   => '255,64,255',
20          'In Progress/Errors'    => '255,128,128',          'In Progress/Errors'    => '255,64,0',
21          'Queuing'               => '255,255,0',          'Queuing'               => '255,255,0',
22          'Aborted',              => '255,0,0',          'Aborted'               => '255,0,0',
23          'Failed',               => '255,0,0',          'Failed'                => '255,0,0',
24          'Completed',            => '0,255,0',          'Completed'             => '64,255,64',
25          'Completed/Errors'      => '0,255,255',          'Completed/Errors'      => '255,128,0',
26          'Completed/Failure',    => '0,255,255'          'Completed/Failure'     => '128,0,128',
27            'Mount Request'         => '128,128,255',
28          );          );
29    
30    my $int_t = (12 * 60 * 60);     # interval to display on one screen
31    my $min_l = 3;                  # min length of bar segment (in pixels)
32    
33    #--- no user servicable parts below this line
34    
35    # time range
36    
37    my ($from_t,$to_t) = (time()-$int_t,time());
38    
39    $to_t = param('to_t') if (param('to_t'));
40    $from_t = param('from_t') if (param('from_t'));
41    
42    # round to nearest minute
43    $to_t = $to_t - ($to_t % 60);
44    $from_t = $from_t - ($from_t % 60) + 60;
45    
46    my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t));
47    my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t));
48    
49    
50    # keep count of each status
51    my %count;      
52    
53  if (param('pic')) {  if (param('pic')) {
54          print "Content-type: image/png\n\n";          print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
55          # create picture using GD          # create picture using GD
56          use GD;          use GD;
57          my $im = new GD::Image(1,8);          my $im = new GD::Image(1,$height);
58          my $back = $im->colorAllocate(255,255,255);          my $back = $im->colorAllocate(255,255,255);
59          $im->transparent($back);          $im->transparent($back);
60          my ($r,$g,$b) = split(/,/,param('pic'));          my ($r,$g,$b) = split(/,/,param('pic'));
# Line 43  if (param('pic')) { Line 65  if (param('pic')) {
65          exit;          exit;
66  }  }
67    
68  print "Content-type: text/html\n\n";  print "Content-type: text/html
69    
70    <html>
71    <head>
72    <title>OmniBack Gantt: $from - $to</title>";
73    if ($use_js) {
74    print '
75    <script type="text/javascript" language="javascript" src="1k.js"></script>
76    <script type="text/javascript" language="javascript" src="tooltip.js"></script>
77    <script language="javascript" type="text/javascript">
78        onload=function(){
79            T.init()
80            T.follows = false // false by default
81            T.delay = .3     // any nonnegative value (0.7 by default)
82        }
83    </script>
84    ';
85    }
86    print "</head><body>";
87    
88  # all vars ending in *_t have utime in them.  # all vars ending in *_t have utime in them.
89  #  #
 my $from_t = str2time($from);  
 my $to_t = str2time($to);  
90  my $len_t = $to_t - $from_t;  my $len_t = $to_t - $from_t;
91    
92  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 95  my $dbh = DBI->connect("DBI:Pg:dbname=ga
95  my $q=new CGI;  my $q=new CGI;
96    
97    
98  print "<table>";  sub mknav {
99  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>\n";          my $f = shift @_;       # from_t
100            my $t = shift @_;       # to_t
101            my $ch = shift @_;      # char
102    
103            return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";
104    }
105    
106    print "<table>";
107    print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
108    print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;
109    print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);
110    print "</td><td align=right>";
111    print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);
112    print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
113    
114    my $fix_d = 0;  # used to fix graph len
115    
116  sub draw {  sub bar {
117          my $l = shift @_;       # lenght of event utime          my $l = shift @_;       # lenght of event utime
118          my $status = shift @_;  # what to draw          my $status = shift @_ || undef; # what to draw
119          my $alt = shift @_;          my $alt = shift @_ || undef;
120    
121            my $size = int($l / ($len_t / $width));
122            if ($size < $min_l) {
123                    $size = $min_l;
124                    $fix_d += $min_l;
125            }
126            if ($fix_d && $size > $fix_d+$min_l) {
127                    $size -= $fix_d;
128                    $fix_d = 0;
129            }
130    
131          my $size = int($l / ($len_t / $width)) || 1;    # dump size (min. size=1)          print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug);
132    
133          print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug);          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
134    
135            if ($status) {
136                    $html .= $cols{$status};
137                    $count{$status}++;
138            } else {
139    #               $html .= '240,240,240';
140                    $html .= '220,220,220';
141            }
142    
143            $html .= "\" width=\"$size\" height=\"$height\"";
144            if ($use_js && $alt) {
145                    $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
146            } elsif ($alt) {
147                    $html .= " alt=\"$alt\"";
148            }
149            $html .= ">";
150    
151          my $col = $cols{$status} || '240,240,240';          return($html);
         print "<img src=".$q->url(-relative=>1)."?pic=$col width=$size height=8 alt=\"$alt\">";  
152  }  }
153    
154  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,
155                    type,sessionid,device,host
156          from gantt          from gantt
157          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
158          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
159          order by specification          order by device,specification
160          ";          ";
161    
162  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 169  my $curr_t = $from_t;
169  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
170    
171  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
172          if ($row->{specification} ne $curr_spec) {          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
173    
174                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
175                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
176                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
177                          draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});                          print bar($t);
178                  }                  }
179    
180                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != $from_t);
181                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
182    
183                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 113  while(my $row = $sth->fetchrow_hashref) Line 190  while(my $row = $sth->fetchrow_hashref)
190    
191          if ($start_t > $curr_t) {          if ($start_t > $curr_t) {
192                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
193                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
194                  draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});                  print bar($t);
195                  $curr_t = $start_t;                  $curr_t = $start_t;
196          }          }
197    
# Line 128  while(my $row = $sth->fetchrow_hashref) Line 205  while(my $row = $sth->fetchrow_hashref)
205                  $len = ($fin_t - $curr_t);                  $len = ($fin_t - $curr_t);
206                  $less = "<<";                  $less = "<<";
207          }          }
208    
209          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
210  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
211                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 135  while(my $row = $sth->fetchrow_hashref) Line 213  while(my $row = $sth->fetchrow_hashref)
213          }          }
214    
215          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
216          draw($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});  
217            my $alt = $row->{start}." - ".$row->{finish}."<br>";
218            $alt =~ s/:\d\d\.\d+//g;
219            $alt =~ s/\s+/&nbsp;/g;
220            $alt .= $row->{type}." <b>".$row->{status}."</b><br>".
221            $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
222            $row->{device}."&nbsp;on&nbsp;".$row->{host};
223            print bar($len,$row->{status},$alt);
224    
225          $curr_t += $len;          $curr_t += $len;
226    
# Line 143  while(my $row = $sth->fetchrow_hashref) Line 228  while(my $row = $sth->fetchrow_hashref)
228                    
229  }  }
230    
231    if ($curr_t == $from_t) {       # no entries in database!
232            print "<tr><td></td><td colspan=2>";
233    }
234    
235  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
236          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
237          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
238          draw($t);          print bar($t);
239  }  }
240    
241  undef $sth;  undef $sth;
# Line 154  $dbh->disconnect; Line 243  $dbh->disconnect;
243    
244  print "</td></tr>\n</table>";  print "</td></tr>\n</table>";
245    
246    
247    # label and usage
248    $len_t = 50; # disable bar scaling
249    
250    print "<hr>\nColors for statuses and usage (#):\n";
251    print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n";
252    foreach my $status (keys %count) {
253    #foreach my $status (keys %cols) {
254            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 "");
255            # -1 in line above is a cludge to display correct number on
256            # occurences on graph and without one on legend!
257    }
258    print "</table>\n</body></html>";
259    

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

  ViewVC Help
Powered by ViewVC 1.1.26