/[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.2 by dpavlin, Thu Sep 12 12:52:38 2002 UTC revision 1.5 by dpavlin, Fri Sep 13 11:59:08 2002 UTC
# Line 4  use strict; Line 4  use strict;
4  use DBI;  use DBI;
5  use Data::Dumper;  use Data::Dumper;
6  use Date::Parse;  use Date::Parse;
7    use CGI qw/:standard/;
8    use POSIX qw(strftime);
9    
10  print "Content-type: text/html\n\n";  my $debug = 1;
11    my $width = 600;
12    my $use_js = 1;
13    
14    # status colors
15    my %cols = (
16            'In Progress'           => '0,255,0',
17            'In Progress/Failure'   => '255,64,255',
18            'In Progress/Errors'    => '255,64,0',
19            'Queuing'               => '255,255,0',
20            'Aborted'               => '255,0,0',
21            'Failed'                => '255,0,0',
22            'Completed'             => '64,255,64',
23            'Completed/Errors'      => '255,128,0',
24            'Completed/Failure'     => '128,0,128',
25            'Mount Request'         => '128,128,255',
26            );
27    
28    #--- no user servicable parts below this line
29    
30    # time range
31    
32    my $day_t = (24 * 60 * 60);     # 24h interval
33    
34    my ($from_t,$to_t) = (time()-$day_t,time());
35    
36    $to_t = param('to_t') if (param('to_t'));
37    $from_t = param('from_t') if (param('from_t'));
38    
39  my $from="2002-09-11 20:00:00";  my $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t));
40  my $to="2002-09-13 00:00:00";  my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t));
41    
42    
43    # keep count of each status
44    my %count;      
45    
46    if (param('pic')) {
47            print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
48            # create picture using GD
49            use GD;
50            my $im = new GD::Image(1,8);
51            my $back = $im->colorAllocate(255,255,255);
52            $im->transparent($back);
53            my ($r,$g,$b) = split(/,/,param('pic'));
54            my $col = $im->colorAllocate($r,$g,$b);
55            $im->fill(0,0,$col);
56            binmode STDOUT;
57            print $im->png;
58            exit;
59    }
60    
61    print "Content-type: text/html
62    
63    <html>
64    <head>
65    <title>OmniBack Gantt: $from - $to</title>";
66    if ($use_js) {
67    print '
68    <script type="text/javascript" language="javascript" src="1k.js"></script>
69    <script type="text/javascript" language="javascript" src="tooltip.js"></script>
70    <script language="javascript" type="text/javascript">
71        onload=function(){
72            T.init()
73            T.follows = false // false by default
74            T.delay = .3     // any nonnegative value (0.7 by default)
75        }
76    </script>
77    ';
78    }
79    print "</head><body>";
80    
81  # all vars ending in *_t have utime in them.  # all vars ending in *_t have utime in them.
82  #  #
 my $from_t = str2time($from);  
 my $to_t = str2time($to);  
83  my $len_t = $to_t - $from_t;  my $len_t = $to_t - $from_t;
84    
85  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);
86    
 my $debug = 1;  
   
87  my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;  my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
88    my $q=new CGI;
89    
90  #--- no user servicable parts below this line  
91    sub mknav {
92            my $f = shift @_;       # from_t
93            my $t = shift @_;       # to_t
94            my $ch = shift @_;      # char
95    
96            return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>";
97    }
98    
99  print "<table>";  print "<table>";
100  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>";  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
101    print mknav(($from_t-$day_t),$to_t,'<small>&lt;&lt;</small>'),$from;
102    print mknav(($from_t+$day_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$day_t < $to_t);
103    print "</td><td align=right>";
104    print mknav($from_t,($to_t-$day_t),'<small>&lt;&lt;</small>') if ($to_t-$day_t > $from_t);
105    print $to,mknav($from_t,($to_t+$day_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
106    
107  my $width = 900;  my $fix_d = 0;  # used to fix graph len
108    my $min_l = 3;  # min length;
109    
110  sub draw {  sub bar {
111          my $l = shift @_;       # lenght of event utime          my $l = shift @_;       # lenght of event utime
112          my $type = shift @_;    # what to draw          my $status = shift @_ || undef; # what to draw
113          my $alt = shift @_;          my $alt = shift @_ || undef;
114    
115            my $size = int($l / ($len_t / $width));
116            if ($size < $min_l) {
117                    $size = $min_l;
118                    $fix_d += $min_l;
119            }
120            if ($fix_d && $size > $fix_d+$min_l) {
121                    $size -= $fix_d;
122                    $fix_d = 0;
123            }
124    
125            print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br> alt:$alt\n" if ($debug);
126    
127          my $size = int($l / ($len_t / $width)) || 1;    # dump size (min. size=1)          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
128    
129            if ($status) {
130                    $html .= $cols{$status};
131                    $count{$status}++;
132            } else {
133    #               $html .= '240,240,240';
134                    $html .= '220,220,220';
135            }
136    
137          print STDERR "l[$type]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug);          $html .= "\" width=\"$size\" height=\"12\"";
138            if ($use_js && $alt) {
139                    $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
140            } elsif ($alt) {
141                    $html .= " alt=\"$alt\"";
142            }
143            $html .= ">";
144    
145          print "<img src=$type.png width=$size height=8 alt=\"$alt\">";          return($html);
146  }  }
147    
148  my $sql = "select start,finish,specification,status  my $sql = "select start,finish,specification,status,user_group_host,type,sessionid
149          from gantt          from gantt
150          where (start < '$from' and finish > '$from') or          where (start < '$from' and finish > '$from') or
151          (start > '$from' and start < '$to')          (start > '$from' and start < '$to')
# Line 60  $sth->execute() || die "sql: $sql ".$dbh Line 164  $sth->execute() || die "sql: $sql ".$dbh
164  while(my $row = $sth->fetchrow_hashref) {  while(my $row = $sth->fetchrow_hashref) {
165          if ($row->{specification} ne $curr_spec) {          if ($row->{specification} ne $curr_spec) {
166    
167                  if ($curr_t < $to_t ) {                  if ($curr_t < $to_t && $curr_spec) {
168                          my $t = $to_t - $curr_t;                          my $t = $to_t - $curr_t;
169                          print STDERR "[filler $curr_t:$t]" if ($debug);                          print STDERR "[filler $curr_t:$t]" if ($debug);
170                          draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});                          print bar($t);
171                  }                  }
172    
173                  print "</td></tr>\n" if ($curr_t != 0);                  print "</td></tr>\n" if ($curr_t != 0);
# Line 80  while(my $row = $sth->fetchrow_hashref) Line 184  while(my $row = $sth->fetchrow_hashref)
184          if ($start_t > $curr_t) {          if ($start_t > $curr_t) {
185                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
186                  print STDERR "[filler $curr_t:$t]" if ($debug);                  print STDERR "[filler $curr_t:$t]" if ($debug);
187                  draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});                  print bar($t);
188                  $curr_t = $start_t;                  $curr_t = $start_t;
189          }          }
190    
# Line 94  while(my $row = $sth->fetchrow_hashref) Line 198  while(my $row = $sth->fetchrow_hashref)
198                  $len = ($fin_t - $curr_t);                  $len = ($fin_t - $curr_t);
199                  $less = "<<";                  $less = "<<";
200          }          }
201    
202            next if ($fin_t > $to_t);
203            
204          if ($fin_t > $to_t) {          if ($fin_t > $to_t) {
205  #               $len -= ($fin_t - $to_t);  #               $len -= ($fin_t - $to_t);
206                  $len = ($to_t - $curr_t);                  $len = ($to_t - $curr_t);
# Line 101  while(my $row = $sth->fetchrow_hashref) Line 208  while(my $row = $sth->fetchrow_hashref)
208          }          }
209    
210          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);          print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
211          draw($len,"red",$row->{start}." - ".$row->{finish}." ".$row->{status});  
212            my $alt = $row->{start}." - ".$row->{finish}."<br>".
213            $row->{type}." <b>".$row->{status}."</b><br>".
214            $row->{user_group_host}." <i>".$row->{sessionid}."</i>";
215            $alt =~ s/:\d\d\.\d+//g;
216            print bar($len,$row->{status},$alt);
217    
218          $curr_t += $len;          $curr_t += $len;
219    
# Line 112  while(my $row = $sth->fetchrow_hashref) Line 224  while(my $row = $sth->fetchrow_hashref)
224  if ($curr_t < $to_t ) {  if ($curr_t < $to_t ) {
225          my $t = $to_t - $curr_t;          my $t = $to_t - $curr_t;
226          print STDERR "[filler $curr_t:$t]" if ($debug);          print STDERR "[filler $curr_t:$t]" if ($debug);
227          draw($t,"gray");          print bar($t);
228  }  }
229    
230  undef $sth;  undef $sth;
231  $dbh->disconnect;  $dbh->disconnect;
232    
233  print "</td></tr></table>";  print "</td></tr>\n</table>";
234    
235    
236    # label and usage
237    $len_t = 50; # disable bar scaling
238    
239    print "<hr>\nColors for statuses and usage (#):\n";
240    print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n";
241    foreach my $status (keys %count) {
242    #foreach my $status (keys %cols) {
243            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 "");
244    }
245    print "</table>\n</body></html>";
246    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26