/[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

Annotation of /db2gantt.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations)
Fri Sep 13 14:03:47 2002 UTC (17 years, 2 months ago) by dpavlin
Branch: MAIN
Changes since 1.7: +13 -5 lines
display unknown statuses in black

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5     use Data::Dumper;
6     use Date::Parse;
7 dpavlin 1.3 use CGI qw/:standard/;
8 dpavlin 1.4 use POSIX qw(strftime);
9 dpavlin 1.3
10 dpavlin 1.6 my $debug = 0;
11    
12     my $width = 600; # width of bar
13     my $height = 12; # height of bar
14     my $use_js = 1; # use JavaScript pop-up
15 dpavlin 1.3
16 dpavlin 1.4 # status colors
17 dpavlin 1.3 my %cols = (
18     'In Progress' => '0,255,0',
19 dpavlin 1.4 'In Progress/Failure' => '255,64,255',
20     'In Progress/Errors' => '255,64,0',
21 dpavlin 1.3 'Queuing' => '255,255,0',
22 dpavlin 1.4 'Aborted' => '255,0,0',
23     'Failed' => '255,0,0',
24     'Completed' => '64,255,64',
25     'Completed/Errors' => '255,128,0',
26     'Completed/Failure' => '128,0,128',
27     'Mount Request' => '128,128,255',
28 dpavlin 1.3 );
29    
30 dpavlin 1.6 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 dpavlin 1.4 #--- no user servicable parts below this line
34    
35     # time range
36    
37 dpavlin 1.6 my ($from_t,$to_t) = (time()-$int_t,time());
38 dpavlin 1.4
39     $to_t = param('to_t') if (param('to_t'));
40     $from_t = param('from_t') if (param('from_t'));
41    
42 dpavlin 1.6 # 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 dpavlin 1.4
49    
50     # keep count of each status
51     my %count;
52 dpavlin 1.3
53     if (param('pic')) {
54 dpavlin 1.4 print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
55 dpavlin 1.3 # create picture using GD
56     use GD;
57 dpavlin 1.6 my $im = new GD::Image(1,$height);
58 dpavlin 1.3 my $back = $im->colorAllocate(255,255,255);
59     $im->transparent($back);
60     my ($r,$g,$b) = split(/,/,param('pic'));
61     my $col = $im->colorAllocate($r,$g,$b);
62     $im->fill(0,0,$col);
63     binmode STDOUT;
64     print $im->png;
65     exit;
66     }
67 dpavlin 1.1
68 dpavlin 1.4 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 dpavlin 1.1
88     # all vars ending in *_t have utime in them.
89     #
90     my $len_t = $to_t - $from_t;
91    
92     die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
93    
94     my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
95 dpavlin 1.3 my $q=new CGI;
96 dpavlin 1.1
97    
98 dpavlin 1.4 sub mknav {
99     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 dpavlin 1.1 print "<table>";
107 dpavlin 1.4 print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
108 dpavlin 1.6 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 dpavlin 1.4 print "</td><td align=right>";
111 dpavlin 1.6 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 dpavlin 1.4
114     my $fix_d = 0; # used to fix graph len
115 dpavlin 1.3
116 dpavlin 1.4 sub bar {
117     my $l = shift @_; # lenght of event utime
118     my $status = shift @_ || undef; # what to draw
119     my $alt = shift @_ || undef;
120 dpavlin 1.1
121 dpavlin 1.4 my $size = int($l / ($len_t / $width));
122     if ($size < $min_l) {
123 dpavlin 1.8 $fix_d += ($min_l - $size);
124     print STDERR "fix_d: $fix_d\n" if ($debug);
125 dpavlin 1.4 $size = $min_l;
126     }
127     if ($fix_d && $size > $fix_d+$min_l) {
128     $size -= $fix_d;
129     $fix_d = 0;
130 dpavlin 1.8 print STDERR "fix_d: $fix_d\n" if ($debug);
131 dpavlin 1.4 }
132 dpavlin 1.1
133 dpavlin 1.6 print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug);
134 dpavlin 1.2
135 dpavlin 1.4 my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
136 dpavlin 1.1
137 dpavlin 1.4 if ($status) {
138 dpavlin 1.8 if ($cols{$status}) {
139     $html .= $cols{$status};
140     } else {
141     $html .= "0,0,0"; # unknown status, black
142     }
143 dpavlin 1.4 $count{$status}++;
144     } else {
145     # $html .= '240,240,240';
146     $html .= '220,220,220';
147     }
148 dpavlin 1.1
149 dpavlin 1.6 $html .= "\" width=\"$size\" height=\"$height\"";
150 dpavlin 1.4 if ($use_js && $alt) {
151     $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
152     } elsif ($alt) {
153     $html .= " alt=\"$alt\"";
154     }
155     $html .= ">";
156    
157     return($html);
158 dpavlin 1.1 }
159    
160 dpavlin 1.6 my $sql = "select start,finish,specification,status,user_group_host,
161     type,sessionid,device,host
162 dpavlin 1.1 from gantt
163     where (start < '$from' and finish > '$from') or
164     (start > '$from' and start < '$to')
165 dpavlin 1.6 order by device,specification
166 dpavlin 1.1 ";
167    
168     my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
169    
170     my %spec; # specification hash
171    
172     my $curr_spec;
173     my $curr_t = $from_t;
174    
175     $sth->execute() || die "sql: $sql ".$dbh->errstr;
176 dpavlin 1.2
177 dpavlin 1.1 while(my $row = $sth->fetchrow_hashref) {
178 dpavlin 1.6 if (!defined $curr_spec || $row->{specification} ne $curr_spec) {
179 dpavlin 1.1
180 dpavlin 1.3 if ($curr_t < $to_t && $curr_spec) {
181 dpavlin 1.1 my $t = $to_t - $curr_t;
182 dpavlin 1.6 print STDERR "[end filler $curr_t:$t]" if ($debug);
183 dpavlin 1.4 print bar($t);
184 dpavlin 1.1 }
185    
186 dpavlin 1.6 print "</td></tr>\n" if ($curr_t != $from_t);
187 dpavlin 1.1 print "<tr><td>", $row->{specification},"</td><td colspan=2>";
188    
189     $curr_t = $from_t; # init timeline
190     $curr_spec = $row->{specification};
191    
192     }
193    
194     my $start_t = str2time($row->{start});
195     my $fin_t = str2time($row->{finish});
196    
197     if ($start_t > $curr_t) {
198     my $t = $start_t - $curr_t;
199 dpavlin 1.6 print STDERR "[middle filler $curr_t:$t]" if ($debug);
200 dpavlin 1.4 print bar($t);
201 dpavlin 1.1 $curr_t = $start_t;
202     }
203    
204     my $len = $fin_t - $start_t;
205     # $len = $len_t if ($len > $len_t);
206     my $less = '';
207     my $more = '';
208    
209     if ($start_t < $from_t) {
210     # $len += ($from_t - $start_t);
211     $len = ($fin_t - $curr_t);
212     $less = "<<";
213     }
214 dpavlin 1.4
215 dpavlin 1.1 if ($fin_t > $to_t) {
216     # $len -= ($fin_t - $to_t);
217     $len = ($to_t - $curr_t);
218     $more = ">>"; # event now shown whole
219     }
220    
221     print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
222 dpavlin 1.5
223 dpavlin 1.6 my $alt = $row->{start}." - ".$row->{finish}."<br>";
224 dpavlin 1.5 $alt =~ s/:\d\d\.\d+//g;
225 dpavlin 1.6 $alt =~ s/\s+/&nbsp;/g;
226     $alt .= $row->{type}." <b>".$row->{status}."</b><br>".
227     $row->{user_group_host}." <i>".$row->{sessionid}."</i><br>".
228     $row->{device}."&nbsp;on&nbsp;".$row->{host};
229 dpavlin 1.5 print bar($len,$row->{status},$alt);
230 dpavlin 1.1
231     $curr_t += $len;
232    
233     # print Dumper($row);
234    
235     }
236    
237 dpavlin 1.6 if ($curr_t == $from_t) { # no entries in database!
238     print "<tr><td></td><td colspan=2>";
239     }
240    
241 dpavlin 1.1 if ($curr_t < $to_t ) {
242     my $t = $to_t - $curr_t;
243 dpavlin 1.6 print STDERR "[last_line filler $curr_t:$t]" if ($debug);
244 dpavlin 1.4 print bar($t);
245 dpavlin 1.1 }
246    
247     undef $sth;
248     $dbh->disconnect;
249    
250 dpavlin 1.3 print "</td></tr>\n</table>";
251 dpavlin 1.4
252    
253     # label and usage
254     $len_t = 50; # disable bar scaling
255    
256     print "<hr>\nColors for statuses and usage (#):\n";
257     print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n";
258     foreach my $status (keys %count) {
259     #foreach my $status (keys %cols) {
260 dpavlin 1.8 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 "");
261     # *1 in line above is a cludge to display correct number on
262     # occurences on graph and without one on legend! If you remove * op
263     # it will first evaluate bar sub (thus increasing number by one) and
264     # then display number (wrongly).
265 dpavlin 1.4 }
266 dpavlin 1.7 print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";
267 dpavlin 1.1

  ViewVC Help
Powered by ViewVC 1.1.26