/[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.5 - (hide annotations)
Fri Sep 13 11:59:08 2002 UTC (16 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +7 -2 lines
much nicer pop-ups

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     my $debug = 1;
11 dpavlin 1.4 my $width = 600;
12     my $use_js = 1;
13 dpavlin 1.3
14 dpavlin 1.4 # status colors
15 dpavlin 1.3 my %cols = (
16     'In Progress' => '0,255,0',
17 dpavlin 1.4 'In Progress/Failure' => '255,64,255',
18     'In Progress/Errors' => '255,64,0',
19 dpavlin 1.3 'Queuing' => '255,255,0',
20 dpavlin 1.4 '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 dpavlin 1.3 );
27    
28 dpavlin 1.4 #--- 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 $to=strftime("%Y-%m-%d %H:%M:%S",localtime ($to_t));
40     my $from=strftime("%Y-%m-%d %H:%M:%S",localtime ($from_t));
41    
42    
43     # keep count of each status
44     my %count;
45 dpavlin 1.3
46     if (param('pic')) {
47 dpavlin 1.4 print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n";
48 dpavlin 1.3 # 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 dpavlin 1.1
61 dpavlin 1.4 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 dpavlin 1.1
81     # all vars ending in *_t have utime in them.
82     #
83     my $len_t = $to_t - $from_t;
84    
85     die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
86    
87     my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
88 dpavlin 1.3 my $q=new CGI;
89 dpavlin 1.1
90    
91 dpavlin 1.4 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 dpavlin 1.1 print "<table>";
100 dpavlin 1.4 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 $fix_d = 0; # used to fix graph len
108     my $min_l = 3; # min length;
109 dpavlin 1.3
110 dpavlin 1.4 sub bar {
111     my $l = shift @_; # lenght of event utime
112     my $status = shift @_ || undef; # what to draw
113     my $alt = shift @_ || undef;
114 dpavlin 1.1
115 dpavlin 1.4 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 dpavlin 1.1
125 dpavlin 1.4 print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br> alt:$alt\n" if ($debug);
126 dpavlin 1.2
127 dpavlin 1.4 my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";
128 dpavlin 1.1
129 dpavlin 1.4 if ($status) {
130     $html .= $cols{$status};
131     $count{$status}++;
132     } else {
133     # $html .= '240,240,240';
134     $html .= '220,220,220';
135     }
136 dpavlin 1.1
137 dpavlin 1.4 $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     return($html);
146 dpavlin 1.1 }
147    
148 dpavlin 1.5 my $sql = "select start,finish,specification,status,user_group_host,type,sessionid
149 dpavlin 1.1 from gantt
150     where (start < '$from' and finish > '$from') or
151     (start > '$from' and start < '$to')
152     order by specification
153     ";
154    
155     my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
156    
157     my %spec; # specification hash
158    
159     my $curr_spec;
160     my $curr_t = $from_t;
161    
162     $sth->execute() || die "sql: $sql ".$dbh->errstr;
163 dpavlin 1.2
164 dpavlin 1.1 while(my $row = $sth->fetchrow_hashref) {
165     if ($row->{specification} ne $curr_spec) {
166    
167 dpavlin 1.3 if ($curr_t < $to_t && $curr_spec) {
168 dpavlin 1.1 my $t = $to_t - $curr_t;
169     print STDERR "[filler $curr_t:$t]" if ($debug);
170 dpavlin 1.4 print bar($t);
171 dpavlin 1.1 }
172    
173     print "</td></tr>\n" if ($curr_t != 0);
174     print "<tr><td>", $row->{specification},"</td><td colspan=2>";
175    
176     $curr_t = $from_t; # init timeline
177     $curr_spec = $row->{specification};
178    
179     }
180    
181     my $start_t = str2time($row->{start});
182     my $fin_t = str2time($row->{finish});
183    
184     if ($start_t > $curr_t) {
185     my $t = $start_t - $curr_t;
186     print STDERR "[filler $curr_t:$t]" if ($debug);
187 dpavlin 1.4 print bar($t);
188 dpavlin 1.1 $curr_t = $start_t;
189     }
190    
191     my $len = $fin_t - $start_t;
192     # $len = $len_t if ($len > $len_t);
193     my $less = '';
194     my $more = '';
195    
196     if ($start_t < $from_t) {
197     # $len += ($from_t - $start_t);
198     $len = ($fin_t - $curr_t);
199     $less = "<<";
200     }
201 dpavlin 1.4
202     next if ($fin_t > $to_t);
203    
204 dpavlin 1.1 if ($fin_t > $to_t) {
205     # $len -= ($fin_t - $to_t);
206     $len = ($to_t - $curr_t);
207     $more = ">>"; # event now shown whole
208     }
209    
210     print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
211 dpavlin 1.5
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 dpavlin 1.1
218     $curr_t += $len;
219    
220     # print Dumper($row);
221    
222     }
223    
224     if ($curr_t < $to_t ) {
225     my $t = $to_t - $curr_t;
226     print STDERR "[filler $curr_t:$t]" if ($debug);
227 dpavlin 1.4 print bar($t);
228 dpavlin 1.1 }
229    
230     undef $sth;
231     $dbh->disconnect;
232    
233 dpavlin 1.3 print "</td></tr>\n</table>";
234 dpavlin 1.4
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 dpavlin 1.1

  ViewVC Help
Powered by ViewVC 1.1.26