aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Sund <arnels@stortinget.samfundet.no>2015-04-03 06:32:28 +0200
committerroot <root@einstein.tg15.gathering.org>2015-04-03 06:33:26 +0200
commitf64dff431f8c2d79d2c611defd115c39132d1ce0 (patch)
tree81eeb29abdbc8be9c438f460344b6c1417344875
parent247524e087a9d44eba3cca6f5f2e50764027e45c (diff)
Added tempmap from tg09 and updated it
-rw-r--r--web/nms.gathering.org/index.html2
-rwxr-xr-xweb/nms.gathering.org/stempmap.pl89
2 files changed, 90 insertions, 1 deletions
diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html
index cd5055d..fada227 100644
--- a/web/nms.gathering.org/index.html
+++ b/web/nms.gathering.org/index.html
@@ -78,12 +78,12 @@
<br /><i>Se og håndter kommandoer som er utført og fortsatt i køen</i>
</li>
-<!--
<br />
<li><a href="stempmap.pl">Temperaturkart</a>
<br /><i>Temperaturkart for switchene</i>
</li>
+<!--
<br />
<li><a href="mbd-status.pl">MBD-status</a>
<br /><i>Hva spiller folk mest?</i>
diff --git a/web/nms.gathering.org/stempmap.pl b/web/nms.gathering.org/stempmap.pl
new file mode 100755
index 0000000..ccd44fd
--- /dev/null
+++ b/web/nms.gathering.org/stempmap.pl
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+#
+#
+use strict;
+use warnings;
+
+use CGI;
+use GD;
+use DBI;
+use File::Basename;
+use lib '../../include';
+use nms;
+
+GD::Image->trueColor(1);
+
+my $cwd = dirname($0);
+my $img = GD::Image->new($cwd.'/tg15-salkart.png');
+my $cgi = CGI->new;
+
+my $dbh = nms::db_connect();
+
+my $max_update_age = '\'8 min\'::interval';
+
+# Henter ut de som er oppdatert for mindre enn $max_update_age siden
+my $sgetpoll = $dbh->prepare('select switch,sysname,(select temp from switch_temp where switches.switch = switch_temp.switch AND temp != 0 order by time desc limit 1) AS temp,placement from switches natural join placements where now()-'.$max_update_age.' < last_updated');
+
+my $black = $img->colorAllocate(0,0,0);
+my $white = $img->colorAllocate(255,255,255);
+my $grey = $img->colorAllocate(192,192,192);
+my $green = $img->colorAllocate(0,255,0);
+my $blue = $img->colorAllocate(0,0,255);
+
+my $mintemp = 10.0;
+my $maxtemp = 55.0;
+my $steps = 100;
+
+for (my $i = 0; $i < $steps; $i++) {
+ my $diff = $maxtemp - $mintemp;
+ my $temp = $mintemp + ($maxtemp - $mintemp) * ((($diff / $steps) * $i)/$diff);
+ $img->line(5, $i, 45, $i, &getcolor($temp));
+}
+
+$img->stringFT($black, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 50, 10, "Freezing!");
+$img->stringFT($black, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 50, 22, "$mintemp C");
+$img->stringFT($black, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 50, $steps - 12, "$maxtemp C");
+$img->stringFT($black, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 50, $steps, "Too hot!");
+
+$sgetpoll->execute();
+while (my $ref = $sgetpoll->fetchrow_hashref()) {
+ next if (!defined($ref->{'temp'}));
+
+ my $sysname = $ref->{'sysname'};
+ $sysname =~ s/sw$//;
+
+ my $temp = $ref->{'temp'};
+ my $color = getcolor($temp);
+
+ $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
+ my ($x2, $y2, $x1, $y1) = ($1, $2, $3, $4);
+ $img->filledRectangle($x1,$y1,$x2,$y2,$color);
+ $img->rectangle($x1,$y1,$x2,$y2,$black);
+ my $max_textlen = ($x2-$x1) > ($y2-$y1) ? $x2-$x1 : $y2-$y1;
+ while (length($sysname) * 6 > $max_textlen) {
+ # Try to abbreviate sysname if it is too long for the box
+ $sysname =~ s/^(.*)[a-z]~?([0-9-]+)$/$1~$2/ or last;
+ }
+ if (($x2-$x1) > ($y2-$y1)) {
+ $img->string(gdSmallFont,$x1+2,$y1,$sysname,$white);
+ } else {
+ $img->stringUp(gdSmallFont,$x1,$y2-3,$sysname,$white);
+ }
+ $img->string(gdGiantFont, $x2-(length("$temp") * 9), $y1, "$temp", $white);
+}
+
+print $cgi->header(-type=>'image/png');
+print $img->png;
+
+sub getcolor {
+ my ($temp) = @_;
+
+ my $t = ($temp - $mintemp) / ($maxtemp - $mintemp);
+ $t = 0 if ($t < 0);
+ $t = 1 if ($t > 1);
+
+ my $colorred = 65025 * $t;
+ my $colorblue = 65025 - $colorred;
+
+ return $img->colorResolve(sqrt($colorred), 0, sqrt($colorblue) );
+}