--- db2gantt.cgi 2002/09/12 12:52:38 1.2
+++ db2gantt.cgi 2002/09/12 16:35:35 1.3
@@ -4,12 +4,47 @@
use DBI;
use Data::Dumper;
use Date::Parse;
+use CGI qw/:standard/;
-print "Content-type: text/html\n\n";
-
-my $from="2002-09-11 20:00:00";
+# default range
+my $from="2002-09-11 18:00";
my $to="2002-09-13 00:00:00";
+my $debug = 1;
+my $width = 800;
+
+#--- no user servicable parts below this line
+
+my %cols = (
+ 'In Progress' => '0,255,0',
+ 'In Progress/Failure' => '255,128,128',
+ 'In Progress/Errors' => '255,128,128',
+ 'Queuing' => '255,255,0',
+ 'Aborted', => '255,0,0',
+ 'Failed', => '255,0,0',
+ 'Completed', => '0,255,0',
+ 'Completed/Errors' => '0,255,255',
+ 'Completed/Failure', => '0,255,255'
+ );
+
+
+if (param('pic')) {
+ print "Content-type: image/png\n\n";
+ # create picture using GD
+ use GD;
+ my $im = new GD::Image(1,8);
+ my $back = $im->colorAllocate(255,255,255);
+ $im->transparent($back);
+ my ($r,$g,$b) = split(/,/,param('pic'));
+ my $col = $im->colorAllocate($r,$g,$b);
+ $im->fill(0,0,$col);
+ binmode STDOUT;
+ print $im->png;
+ exit;
+}
+
+print "Content-type: text/html\n\n";
+
# all vars ending in *_t have utime in them.
#
my $from_t = str2time($from);
@@ -18,27 +53,26 @@
die "interval must be positive and bigger than 1 sec !" if ($len_t < 1);
-my $debug = 1;
-
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
+my $q=new CGI;
-#--- no user servicable parts below this line
print "
";
-print "Specification | $from | $to |
";
+print "Specification | $from | $to |
\n";
+
-my $width = 900;
sub draw {
my $l = shift @_; # lenght of event utime
- my $type = shift @_; # what to draw
+ my $status = shift @_; # what to draw
my $alt = shift @_;
my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1)
- print STDERR "l[$type]:$l scale:",($len_t/$width)," size:$size
\n" if ($debug);
+ print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size
\n" if ($debug);
- print "";
+ my $col = $cols{$status} || '240,240,240';
+ print "";
}
my $sql = "select start,finish,specification,status
@@ -60,10 +94,10 @@
while(my $row = $sth->fetchrow_hashref) {
if ($row->{specification} ne $curr_spec) {
- if ($curr_t < $to_t ) {
+ if ($curr_t < $to_t && $curr_spec) {
my $t = $to_t - $curr_t;
print STDERR "[filler $curr_t:$t]" if ($debug);
- draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});
+ draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});
}
print "\n" if ($curr_t != 0);
@@ -80,7 +114,7 @@
if ($start_t > $curr_t) {
my $t = $start_t - $curr_t;
print STDERR "[filler $curr_t:$t]" if ($debug);
- draw($t,"gray",$row->{start}." - ".$row->{finish}." ".$row->{status});
+ draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status});
$curr_t = $start_t;
}
@@ -101,7 +135,7 @@
}
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug);
- draw($len,"red",$row->{start}." - ".$row->{finish}." ".$row->{status});
+ draw($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status});
$curr_t += $len;
@@ -112,11 +146,11 @@
if ($curr_t < $to_t ) {
my $t = $to_t - $curr_t;
print STDERR "[filler $curr_t:$t]" if ($debug);
- draw($t,"gray");
+ draw($t);
}
undef $sth;
$dbh->disconnect;
-print "
";
+print "\n";