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 |
|
|
9 |
print "Content-type: text/html\n\n"; |
# default range |
10 |
|
my $from="2002-09-11 18:00"; |
|
my $from="2002-09-11 20:00:00"; |
|
11 |
my $to="2002-09-13 00:00:00"; |
my $to="2002-09-13 00:00:00"; |
12 |
|
|
13 |
|
my $debug = 1; |
14 |
|
my $width = 800; |
15 |
|
|
16 |
|
#--- no user servicable parts below this line |
17 |
|
|
18 |
|
my %cols = ( |
19 |
|
'In Progress' => '0,255,0', |
20 |
|
'In Progress/Failure' => '255,128,128', |
21 |
|
'In Progress/Errors' => '255,128,128', |
22 |
|
'Queuing' => '255,255,0', |
23 |
|
'Aborted', => '255,0,0', |
24 |
|
'Failed', => '255,0,0', |
25 |
|
'Completed', => '0,255,0', |
26 |
|
'Completed/Errors' => '0,255,255', |
27 |
|
'Completed/Failure', => '0,255,255' |
28 |
|
); |
29 |
|
|
30 |
|
|
31 |
|
if (param('pic')) { |
32 |
|
print "Content-type: image/png\n\n"; |
33 |
|
# create picture using GD |
34 |
|
use GD; |
35 |
|
my $im = new GD::Image(1,8); |
36 |
|
my $back = $im->colorAllocate(255,255,255); |
37 |
|
$im->transparent($back); |
38 |
|
my ($r,$g,$b) = split(/,/,param('pic')); |
39 |
|
my $col = $im->colorAllocate($r,$g,$b); |
40 |
|
$im->fill(0,0,$col); |
41 |
|
binmode STDOUT; |
42 |
|
print $im->png; |
43 |
|
exit; |
44 |
|
} |
45 |
|
|
46 |
|
print "Content-type: text/html\n\n"; |
47 |
|
|
48 |
# all vars ending in *_t have utime in them. |
# all vars ending in *_t have utime in them. |
49 |
# |
# |
50 |
my $from_t = str2time($from); |
my $from_t = str2time($from); |
53 |
|
|
54 |
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); |
55 |
|
|
|
my $debug = 1; |
|
|
|
|
56 |
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
57 |
|
my $q=new CGI; |
58 |
|
|
|
#--- no user servicable parts below this line |
|
59 |
|
|
60 |
print "<table>"; |
print "<table>"; |
61 |
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>$from</td><td align=right>$to</td></tr>\n"; |
62 |
|
|
63 |
|
|
|
my $width = 900; |
|
64 |
|
|
65 |
sub draw { |
sub draw { |
66 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; # lenght of event utime |
67 |
my $type = shift @_; # what to draw |
my $status = shift @_; # what to draw |
68 |
|
my $alt = shift @_; |
69 |
|
|
70 |
my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1) |
my $size = int($l / ($len_t / $width)) || 1; # dump size (min. size=1) |
71 |
|
|
72 |
print STDERR "l[$type]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug); |
print STDERR "l[$status]:$l scale:",($len_t/$width)," size:$size<br>\n" if ($debug); |
73 |
|
|
74 |
print "<img src=$type.png width=$size height=8>"; |
my $col = $cols{$status} || '240,240,240'; |
75 |
|
print "<img src=".$q->url(-relative=>1)."?pic=$col width=$size height=8 alt=\"$alt\">"; |
76 |
} |
} |
77 |
|
|
78 |
my $sql = "select start,finish,specification,status |
my $sql = "select start,finish,specification,status |
90 |
my $curr_t = $from_t; |
my $curr_t = $from_t; |
91 |
|
|
92 |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
93 |
|
|
94 |
while(my $row = $sth->fetchrow_hashref) { |
while(my $row = $sth->fetchrow_hashref) { |
95 |
if ($row->{specification} ne $curr_spec) { |
if ($row->{specification} ne $curr_spec) { |
96 |
|
|
97 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t && $curr_spec) { |
98 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
99 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
100 |
draw($t,"gray"); |
draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status}); |
101 |
} |
} |
102 |
|
|
103 |
print "</td></tr>\n" if ($curr_t != 0); |
print "</td></tr>\n" if ($curr_t != 0); |
114 |
if ($start_t > $curr_t) { |
if ($start_t > $curr_t) { |
115 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
116 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
117 |
draw($t,"gray"); |
draw($t,undef,$row->{start}." - ".$row->{finish}." ".$row->{status}); |
118 |
$curr_t = $start_t; |
$curr_t = $start_t; |
119 |
} |
} |
120 |
|
|
135 |
} |
} |
136 |
|
|
137 |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
print STDERR "[$less",$row->{status}," $curr_t:$len$more]" if ($debug); |
138 |
draw($len,"red"); |
draw($len,$row->{status},$row->{start}." - ".$row->{finish}." ".$row->{status}); |
139 |
|
|
140 |
$curr_t += $len; |
$curr_t += $len; |
141 |
|
|
146 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t ) { |
147 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
148 |
print STDERR "[filler $curr_t:$t]" if ($debug); |
print STDERR "[filler $curr_t:$t]" if ($debug); |
149 |
draw($t,"white"); |
draw($t); |
150 |
} |
} |
151 |
|
|
152 |
undef $sth; |
undef $sth; |
153 |
$dbh->disconnect; |
$dbh->disconnect; |
154 |
|
|
155 |
print "</td></tr></table>"; |
print "</td></tr>\n</table>"; |
156 |
|
|