#!/usr/bin/perl -w
# This code generates some plain HTML code about consumed electricity,
# either for one or several months, depending on the command line parameter.
# By default, the last monthly bill is generated, of a specific date given
# (must be specified in the form mm/dd/yy, where dd=01), or all months if
# "all" is given as parameter.
# Directories where the log files reside in, adjusted by configure script
# $sumdir="/home/chris/construction/BTUmetering/summarize";
$sumdir="MAINPROGROOT/log";
# extract commandline parameters; do first interpretation
if ($#ARGV != 0) {
$shm="last";
} else {
$shm=$ARGV[0];
}
# only leave alpanum and slashes in the string
$shm =~ s/[^\w\/]//g;
# summary file name
$sumfile="$sumdir/e_summaryfile";
# silly date conversion functions
@months=qw(x January February March April May June July August September October November December);
sub mdytoymd { my @a=split '/', $_[0]; return "$a[2]-$a[0]-$a[1]";}
sub ymdtomdy { my @a=split '-', $_[0]; return "$a[1]/$a[2]/$a[0]";}
sub mdytotext { my @a=split '/', $_[0]; return "$months[$a[0]] 20$a[2]";}
#clear hash for readings
%readings = ();
%unithash = ();
%datehash = ();
# read in summary file
open(SUMFH, $sumfile) or die "cannot open file.";
while ($line = Electricity consumption for the $mtx reading
\n";
print "
\n";
# go through all units for a given date and generate table rows
$totalkwh = 0;
foreach $unit (@units) {
if (exists $readings{"$unit:$month"}) {
@rd=split ' ', $readings{"$unit:$month"};
print "Unit
This reading
(kWh)Last reading
(kWh)Consumption
(kWh) \n";
$totalkwh += $rd[4];
$lastread = $rd[1];
}
}
# Generate total sum line and close the table
print "$unit ";
print "$rd[2] $rd[3] $rd[4] \nTotal electricity consumed:
$totalkwh
Measurement time interval was from $lastread to $month.