/[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.9 by dpavlin, Fri Sep 13 14:34:02 2002 UTC
# Line 7  use Date::Parse; Line 7  use Date::Parse;
7  use CGI qw/:standard/;  use CGI qw/:standard/;
8  use POSIX qw(strftime);  use POSIX qw(strftime);
9    
10  my $debug = 1;  my $debug = 0;
11  my $width = 600;  
12  my $use_js = 1;  my $width = 600;        # width of bar
13    my $height = 12;        # height of bar
14    my $use_js = 1;         # use JavaScript pop-up
15    
16  # status colors  # status colors
17  my %cols = (  my %cols = (
# Line 23  my %cols = ( Line 25  my %cols = (
25          'Completed/Errors'      => '255,128,0',          'Completed/Errors'      => '255,128,0',
26          'Completed/Failure'     => '128,0,128',          'Completed/Failure'     => '128,0,128',
27          'Mount Request'         => '128,128,255',          'Mount Request'         => '128,128,255',
28            'Mount/Errors'          => '255,64,128',
29          );          );
30    
31    my $int_t = (12 * 60 * 60);     # interval to display on one screen
32    my $min_l = 3;                  # min length of bar segment (in pixels)
33    
34  #--- no user servicable parts below this line  #--- no user servicable parts below this line
35    
36  # time range  # time range
37    
38  my $day_t = (24 * 60 * 60);     # 24h interval  $int_t = m_round($int_t);
39    
40  my ($from_t,$to_t) = (time()-$day_t,time());  my ($from_t,$to_t) = (time()-$int_t,time());
41    
42  $to_t = param('to_t') if (param('to_t'));  $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    
45  my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t));  # round to nearest minute
46  my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t));  sub m_round {
47            my $t = shift @_;
48            return ($t - ($t % 60));
49    }
50    
51    $to_t = m_round($to_t);
52    $from_t = m_round($from_t);
53    
54    my $to=strftime("%Y-%m-%d %H:%M",localtime ($to_t));
55    my $from=strftime("%Y-%m-%d %H:%M",localtime ($from_t));
56    
57    
58  # keep count of each status  # keep count of each status
# Line 47  if (param('pic')) { Line 62  if (param('pic')) {
62          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";
63          # create picture using GD          # create picture using GD
64          use GD;          use GD;
65          my $im = new GD::Image(1,8);          my $im = new GD::Image(1,$height);
66          my $back = $im->colorAllocate(255,255,255);          my $back = $im->colorAllocate(255,255,255);
67          $im->transparent($back);          $im->transparent($back);
68          my ($r,$g,$b) = split(/,/,param('pic'));          my ($r,$g,$b) = split(/,/,param('pic'));
# Line 98  sub mknav { Line 113  sub mknav {
113    
114  print "<table>";  print "<table>";
115  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
116  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;
117  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);
118  print "</td><td align=right>";  print "</td><td align=right>";
119  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);
120  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";
121    
122  my $fix_d = 0;  # used to fix graph len  my $fix_d = 0;  # used to fix graph len
 my $min_l = 3;  # min length;  
123    
124  sub bar {  sub bar {
125          my $l = shift @_;       # lenght of event utime          my $l = shift @_;       # lenght of event utime
# Line 114  sub bar { Line 128  sub bar {
128    
129          my $size = int($l / ($len_t / $width));          my $size = int($l / ($len_t / $width));
130          if ($size < $min_l) {          if ($size < $min_l) {
131                    $fix_d += ($min_l - $size);
132                    print STDERR "fix_d: $fix_d\n" if ($debug);
133                  $size = $min_l;                  $size = $min_l;
                 $fix_d += $min_l;  
134          }          }
135          if ($fix_d && $size > $fix_d+$min_l) {          if ($fix_d && $size > $fix_d+$min_l) {
136                  $size -= $fix_d;                  $size -= $fix_d;
137                  $fix_d = 0;                  $fix_d = 0;
138                    print STDERR "fix_d: $fix_d\n" if ($debug);
139          }          }
140    
141          print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br> alt:$alt\n" if ($debug);          print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug);
142    
143          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
144    
145          if ($status) {          if ($status) {
146                  $html .= $cols{$status};                  if ($cols{$status}) {
147                            $html .= $cols{$status};
148                    } else {
149                            $html .= "0,0,0";       # unknown status, black
150                    }
151                  $count{$status}++;                  $count{$status}++;
152          } else {          } else {
153  #               $html .= '240,240,240';  #               $html .= '240,240,240';
154                  $html .= '220,220,220';                  $html .= '220,220,220';
155          }          }
156    
157          $html .= "\" width=\"$size\" height=\"12\"";          $html .= "\" width=\"$size\" height=\"$height\"";
158          if ($use_js && $alt) {          if ($use_js && $alt) {
159                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
160          } elsif ($alt) {          } elsif ($alt) {
# Line 145  sub bar { Line 165  sub bar {
165          return($html);          return($html);
166  }  }
167    
168  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,
169                    type,sessionid,device,host
170          from gantt          from gantt
171          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
172          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
173          order by specification          order by device,specification
174          ";          ";
175    
176  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;  my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
# Line 162  my $curr_t = $from_t; Line 183  my $curr_t = $from_t;
183  $sth->execute() || die "sql: $sql ".$dbh->errstr;  $sth->execute() || die "sql: $sql ".$dbh->errstr;
184    
185  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
186          if ($row->{specification} ne $curr_spec) {          if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
187    
188                  if ($curr_t < $to_t && $curr_spec) {                  if ($curr_t < $to_t && $curr_spec) {
189                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
190                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[end filler $curr_t:$t]" if ($debug);
191                          print bar($t);                          print bar($t);
192                  }                  }
193    
194                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != $from_t);
195                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
196    
197                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 178  while(my $row = $sth->fetchrow_hashref) Line 199  while(my $row = $sth->fetchrow_hashref)
199    
200          }          }
201    
202          my $start_t = str2time($row->{start});          my $start_t = m_round(str2time($row->{start}));
203          my $fin_t = str2time($row->{finish});          my $fin_t = m_round(str2time($row->{finish}));
204    
205          if ($start_t > $curr_t) {          if ($start_t > $curr_t + 60) {
206                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
207                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
208                  print bar($t);                  print bar($t);
209                  $curr_t = $start_t;                  $curr_t = $start_t;
210          }          }
# Line 199  while(my $row = $sth->fetchrow_hashref) Line 220  while(my $row = $sth->fetchrow_hashref)
220                  $less = "<<";                  $less = "<<";
221          }          }
222    
         next if ($fin_t > $to_t);  
           
223          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
224  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
225                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 208  while(my $row = $sth->fetchrow_hashref) Line 227  while(my $row = $sth->fetchrow_hashref)
227          }          }
228    
229          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
230          print bar($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});  
231            my $alt = $row->{start}." - ".$row->{finish}."<br>";
232            $alt =~ s/:\d\d\.\d+//g;
233            $alt =~ s/\s+/&nbsp;/g;
234            $alt .= $row->{type}." <b>".$row->{status}."</b><br>".
235            $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
236            $row->{device}."&nbsp;on&nbsp;".$row->{host};
237            print bar($len,$row->{status},$alt);
238    
239          $curr_t += $len;          $curr_t += $len;
240    
# Line 216  while(my $row = $sth->fetchrow_hashref) Line 242  while(my $row = $sth->fetchrow_hashref)
242                    
243  }  }
244    
245    if ($curr_t == $from_t) {       # no entries in database!
246            print "<tr><td></td><td colspan=2>";
247    }
248    
249  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
250          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
251          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[last_line filler $curr_t:$t]" if ($debug);
252          print bar($t);          print bar($t);
253  }  }
254    
# Line 235  print "<hr>\nColors for statuses and usa Line 265  print "<hr>\nColors for statuses and usa
265  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";
266  foreach my $status (keys %count) {  foreach my $status (keys %count) {
267  #foreach my $status (keys %cols) {  #foreach my $status (keys %cols) {
268          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 "");
269            # *1 in line above is a cludge to display correct number on
270            # occurences on graph and without one on legend! If you remove * op
271            # it will first evaluate bar sub (thus increasing number by one) and
272            # then display number (wrongly).
273  }  }
274  print "</table>\n</body></html>";  print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";
275    

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

  ViewVC Help
Powered by ViewVC 1.1.26