#!/usr/bin/perl # This script generates the trend graphs for the pressure reading. It takes # parameters "unit" (naming the unit) and "length" with values 0...4, # for day/week/month/quarter/year as arguments, passed by via GET method. # Directories where the log files reside in #$logdir="/home/chris/BTUmetering/log"; #$gnudir="/home/chris/BTUmetering/gnuplot"; $logdir="MAINPROGROOT/log"; $gnudir="MAINPROGROOT/gnuplot"; # Image directory: # $imgdir="/srv/www/htdocs/img2"; $imgdir="HTDOCROOT/img2"; @allowedcores = ("AHU1", "AHU2"); # Following http://www.tutorialspoint.com/perl/perl_cgi.htm, we extract the # parameters sent via get: local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } # sanitize input $buffer =~ s/[^\w =&%+-:]//g; # Split information into name/value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $value =~ s/[^\w +-:]//g; $FORM{$name} = $value; } # Extract the interesting ones $core = $FORM{unit}; $timespan = $FORM{length}; # Generate page header print "content-type: text/html\n\n"; print " CQT utility consumption server \n"; # Now, we need to check for validity of the core/timespan entry # test if unit exists $matches = grep $core eq $_, @allowedcores; if ($matches != 1) { print "

Logging failure

Sorry, logging for this unit is not (yet) implemented.

\n"; } else { # test if we have proper value 0...3 for length if ($timespan !~ /[0123]/) { # by default, take a week $timespan=1; } # For debugging # $timespan=1; # $core="AHU2"; # Prepare flexible arguments for gnuplot for different sizes @datapoints = ( 1500, 10800, 46000, 120000); @samplingdensity = (1, 10, 30, 120); @outputformat = ("%m/%d\\n%H:%M", "%a\\n%m/%d\\n%H:%M", "%m/%d", "%d.%b"); $imagename = $core."_p_".$datapoints[$timespan].".png"; # compose parameter set for gnuplot $parset="core=\"$core\"; num=$datapoints[$timespan]; evr=$samplingdensity[$timespan]; ofmt=\"$outputformat[$timespan]\"; outfilename=\"$imagename\"; logdir=\"$logdir\"; imgdir=\"$imgdir\" \n"; # generate image open GNUPLOT, "| gnuplot - $gnudir/pressure.gnu >/dev/null"; print GNUPLOT $parset; close GNUPLOT; # generate volume image $imagename2 = $core."_v_".$datapoints[$timespan].".png"; # compose parameter set for gnuplot $parset="core=\"$core\"; num=$datapoints[$timespan]; evr=$samplingdensity[$timespan]; ofmt=\"$outputformat[$timespan]\"; outfilename=\"$imagename2\"; logdir=\"$logdir\"; imgdir=\"$imgdir\" \n"; # generate image open GNUPLOT, "| gnuplot - $gnudir/volume.gnu >/dev/null"; print GNUPLOT $parset; close GNUPLOT; # Generate web page print "

CQT S15 CHW differential pressure history / CHW flow

\n"; print "\n"; print "\n"; # Some comment print "

Disclaimer: The flow rate is not measured directly, but calculated\n"; print "from the power reading and the difference in chilled water\n"; print "temperature difference ΔT through (dV/dt) = P/(ΔT * 4.19kJ/l/K).

\n"; # Select other resolutions/ units print "

Show other time span: day | week | month | quarter

"; } # Link to instantaneous reading print "

Show instantaneous Δp sensor values

"; # Link to main page of this server print "

Back to main page.

"; # Finish html page print "\n\n";