#!/usr/bin/perl # This script generates the trend graphs for the electricity reading of all # installed units. It takes "length" as a parameter, with values 0...4, # for day/week/month/quarter 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"; # 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'}; } # 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; $FORM{$name} = $value; } # Extract the interesting ones $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 timespan entry # test if we have proper value 0...3 for length if ($timespan !~ /[0123]/) { # by default, take a week $timespan=1; } # For debugging # $timespan=1; # Prepare flexible arguments for gnuplot for different sizes @datapoints = ( 750, 5400, 23000, 60000); @samplingdensity = (1, 5, 10, 30); @outputformat = ("%m/%d\\n%H:%M", "%a\\n%m/%d\\n%H:%M", "%m/%d", "%d.%b"); $imagename = "emeter_".$datapoints[$timespan].".png"; # compose parameter set for gnuplot $parset="num=$datapoints[$timespan]; evr=$samplingdensity[$timespan]; ofmt=\"$outputformat[$timespan]\"; outfilename=\"$imagename\"; logdir=\"$logdir\"; imgdir=\"$imgdir\" \n"; # generate image open GNUPLOT, "| gnuplot - $gnudir/combined_emeter.gnu >/dev/null"; print GNUPLOT $parset; close GNUPLOT; # Generate web page print "

Electrical load trend

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

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

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

Back to main page.

"; # Some explanatory text print "

Explanations

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