#!/usr/bin/perl # # Copyright 2004 by Gray Watson # # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the # above copyright notice and this permission notice appear in all # copies, and that the name of Gray Watson not be used in advertising # or publicity pertaining to distribution of the document or software # without specific, written prior permission. # # Gray Watson makes no representations about the suitability of the # software described herein for any purpose. It is provided "as is" # without express or implied warranty. # # The author may be contacted via http://256.com/gray/ # # $Id: plot.cgi,v 1.13 2005/04/29 20:00:06 gray Exp $ # # # Solar Power Graphing CGI Script # use strict; use DBI; use GD::Graph::bars; use GD::Graph::lines; use POSIX qw(strftime); # some defaults and constants my $SECS_IN_HOUR = 60 * 60; my $SECS_IN_DAY = 24 * $SECS_IN_HOUR; my $MAX_PERIOD = 90 * $SECS_IN_DAY; my $DEFAULT_WIDTH = 600; my $DEFAULT_HEIGHT = 300; my $MAX_WIDTH = 1024; my $MAX_HEIGHT = 768; # how many pixels between two x-labels my $X_LABEL_WIDTH = 80; # my name my $PLOT_HTML = "plot.html"; my $PLOT_CGI = "plot.cgi"; # time periods: seconds => label my %periods = ( $SECS_IN_DAY * 30 => "Last 1 Month", $SECS_IN_DAY * 7 => "Last 1 Week", $SECS_IN_DAY * 3 => "Last 3 Days", $SECS_IN_DAY => "Last 1 Day", 12 * 3600 => "Last 12 Hours", 6 * 3600 => "Last 6 Hours", 3 * 3600 => "Last 3 Hours", 3600 => "Last 1 Hour", 1800 => "Last 30 Minutes", 600 => "Last 10 Minutes", ); # channels to monitor: db-field => label my %channel_list = ( "Pac" => [ 0, 0, 0, "Power Fed to Grid" ], "Ipv" => [ 0, 0, 0, "Current from PV-panels" ], "Vpv" => [ 0, 0, 0, "Voltage from PV-panels" ], "E-Total" => [ 0, 0, 0, "Energy Yield" ], "E-Total.dct" => [ 1, 1, 1, "Energy Yield Per Day" ], "h-Total" => [ 0, 0, 0, "Operating Hours" ], "h-Total.dct" => [ 1, 1, 1, "Operating Hours Per Day" ], "Temperature" => [ 0, 0, 0, "Temperature of Unit" ], "Vac" => [ 0, 0, 0, "Grid Voltage" ], "Fac" => [ 0, 0, 0, "Grid Frequency" ], ); # connect to the DB my $PG_CONN = DBI->connect("dbi:Pg:dbname=sma", "sma", "", { RaiseError => 0, PrintError => 0, AutoCommit => 1 }); if (not $PG_CONN) { my $errstr = $DBI::errstr; print qq[Content-type: text/html