9 my $dbh = nms::db_connect();
11 GD::Image->trueColor(1);
12 $img = GD::Image->new('bg2.png');
14 my $blk = $img->colorResolve(0, 0, 0);
17 my $i = 2.0 * ($y - 236.0) / (42.0 - 237.0);
18 my $clr = get_color($i);
20 $img->filledRectangle(32,$y,53,$y+1,$clr);
23 my $q = $dbh->prepare('select switch,port,bytes_in,bytes_out,placement,switchtype from switches natural join placements natural join get_current_datarate() where switchtype in (\'es3024\')');
25 while (my $ref = $q->fetchrow_hashref()) {
28 # 100kbit/port = all green
29 # 1gbit/port = all red
33 if (defined($ref->{'bytes_in'})) {
35 my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'}; # average and convert to bits (should be about the same in practice)
37 my $max = 20_000_000.0; # 100mbit
38 my $min = 100_000.0; # 100kbit
39 if ($traffic >= $min) {
40 $intensity = 2.0 * (log($traffic / $min) / log(10)) / (log($max / $min) / log(10));
41 $intensity = 2.0 if ($intensity > 2.0);
43 $clr = get_color($intensity);
45 $clr = $img->colorResolve(0, 0, 255);
48 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
49 my $npo = ($ref->{'switchtype'} eq 'es3024') ? 26 : 25;
50 my $f = ($ref->{'port'} - 1) % 2;
51 my $po = ($ref->{'port'} - 1 - $f)/2;
52 my $h = 2*($2-$4)/$npo;
55 $img->filledRectangle($3+$w*$f,$4+$po*$h,$3+$w+$w*$f,$4+$h*($po+1),$clr);
56 # $img->rectangle($3+$w*$f,$4+$po*$h,$3+$w+$w*$f,$4+$h*($po+1),$blk);
57 $img->rectangle($3,$4,$1,$2,$blk);
61 print $cgi->header(-type=>'image/png');
65 my $intensity = shift;
67 if ($intensity > 1.0) {
68 return $img->colorResolve(255.0, 255.0 * ((2.0 - $intensity) ** $gamma), 0);
70 return $img->colorResolve(255.0 * ($intensity ** $gamma), 255, 0);