/[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.2 - (hide annotations)
Thu Sep 12 12:52:38 2002 UTC (21 years, 6 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +8 -5 lines
added alt

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5     use Data::Dumper;
6     use Date::Parse;
7    
8     print "Content-type: text/html\n\n";
9    
10     my $from="2002-09-11 20:00:00";
11     my $to="2002-09-13 00:00:00";
12    
13     # all vars ending in *_t have utime in them.
14     #
15     my $from_t = str2time($from);
16     my $to_t = str2time($to);
17     my $len_t = $to_t - $from_t;
18    
19     die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
20    
21     my $debug = 1;
22    
23     my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
24    
25     #--- no user servicable parts below this line
26    
27     print "<table>";
28     print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>$from</td><td align=right>$to</td></tr>";
29    
30     my $width = 900;
31    
32     sub draw {
33     my $l = shift @_; # lenght of event utime
34     my $type = shift @_; # what to draw
35 dpavlin 1.2 my $alt = shift @_;
36    
37 dpavlin 1.1 my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1)
38    
39     print STDERR "l[$type]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug);
40    
41 dpavlin 1.2 print "<img src=$type.png width=$size height=8 alt=\"$alt\">";
42 dpavlin 1.1 }
43    
44     my $sql = "select start,finish,specification,status
45     from gantt
46     where (start < '$from' and finish > '$from') or
47     (start > '$from' and start < '$to')
48     order by specification
49     ";
50    
51     my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr;
52    
53     my %spec; # specification hash
54    
55     my $curr_spec;
56     my $curr_t = $from_t;
57    
58     $sth->execute() || die "sql: $sql ".$dbh->errstr;
59 dpavlin 1.2
60 dpavlin 1.1 while(my $row = $sth->fetchrow_hashref) {
61     if ($row->{specification} ne $curr_spec) {
62    
63     if ($curr_t < $to_t ) {
64     my $t = $to_t - $curr_t;
65     print STDERR "[filler $curr_t:$t]" if ($debug);
66 dpavlin 1.2 draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});
67 dpavlin 1.1 }
68    
69     print "</td></tr>\n" if ($curr_t != 0);
70     print "<tr><td>", $row->{specification},"</td><td colspan=2>";
71    
72     $curr_t = $from_t; # init timeline
73     $curr_spec = $row->{specification};
74    
75     }
76    
77     my $start_t = str2time($row->{start});
78     my $fin_t = str2time($row->{finish});
79    
80     if ($start_t > $curr_t) {
81     my $t = $start_t - $curr_t;
82     print STDERR "[filler $curr_t:$t]" if ($debug);
83 dpavlin 1.2 draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});
84 dpavlin 1.1 $curr_t = $start_t;
85     }
86    
87     my $len = $fin_t - $start_t;
88     # $len = $len_t if ($len > $len_t);
89     my $less = '';
90     my $more = '';
91    
92     if ($start_t < $from_t) {
93     # $len += ($from_t - $start_t);
94     $len = ($fin_t - $curr_t);
95     $less = "<<";
96     }
97     if ($fin_t > $to_t) {
98     # $len -= ($fin_t - $to_t);
99     $len = ($to_t - $curr_t);
100     $more = ">>"; # event now shown whole
101     }
102    
103     print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
104 dpavlin 1.2 draw($len,"red",$row->{start}." - ".$row->{finish}." ".$row->{status});
105 dpavlin 1.1
106     $curr_t += $len;
107    
108     # print Dumper($row);
109    
110     }
111    
112     if ($curr_t < $to_t ) {
113     my $t = $to_t - $curr_t;
114     print STDERR "[filler $curr_t:$t]" if ($debug);
115 dpavlin 1.2 draw($t,"gray");
116 dpavlin 1.1 }
117    
118     undef $sth;
119     $dbh->disconnect;
120    
121     print "</td></tr></table>";
122    

  ViewVC Help
Powered by ViewVC 1.1.26