#!PERL_COMMAND -w
-# $Cambridge: exim/src/src/eximstats.src,v 1.4 2004/12/21 11:33:55 steve Exp $
+# $Cambridge: exim/src/src/eximstats.src,v 1.5 2005/02/16 15:49:36 steve Exp $
# Copyright (c) 2001 University of Cambridge.
# See the file NOTICE for conditions of use and distribution.
#
# 2004-12-20 V1.35 Wouter Verhelst
# Pie charts by volume were actually generated by count. Fixed.
+#
+# 2005-02-07 V1.36 Gregor Herrmann / Steve Campbell
+# Added average sizes to HTML Top tables.
=head1 NAME
@days_per_month = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$gig = 1024 * 1024 * 1024;
-$VERSION = '1.35';
+$VERSION = '1.36';
# How much space do we allow for the Hosts/Domains/Emails/Edomains column headers?
$COLUMN_WIDTHS = 8;
print "<table border=0 width=\"100%\">\n";
print "<tr><td>\n";
print "<table border=1>\n";
- print "<tr><th>Messages</th><th>Bytes</th><th>\u$text</th>\n";
+ print "<tr><th>Messages</th><th>Bytes</th><th>Average</th><th>\u$text</th>\n";
# Align non-local addresses to the right (so all the .com's line up).
# Local addresses are aligned on the left as they are userids.
my $align = ($text !~ /local/i) ? 'right' : 'left';
- $format = "<tr><td align=\"right\">%d</td><td align=\"right\">%s</td><td align=\"$align\" nowrap>%s</td>\n";
+ $format = "<tr><td align=\"right\">%d</td><td align=\"right\">%s</td><td align=\"right\">%s</td><td align=\"$align\" nowrap>%s</td>\n";
}
else {
printf("%s\n%s\n\n", $temp, "-" x length($temp));
$format = "%7d %10s %s\n";
}
-my($key,$htmlkey);
+my($key,$htmlkey,$rounded_volume,$rounded_average,$count,$data,$gigs);
foreach $key (top_n_sort($topcount,$m_count,$m_data_gigs,$m_data)) {
if ($html) {
$htmlkey = $key;
$htmlkey =~ s/>/\>\;/g;
$htmlkey =~ s/</\<\;/g;
- printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $htmlkey);
+
+ # When displaying the average figures, we calculate the average of
+ # the rounded data, as the user would calculate it. This reduces
+ # the accuracy slightly, but we have to do it this way otherwise
+ # when using -merge to convert results from text to HTML and
+ # vice-versa discrepencies would occur.
+ $rounded_volume = volume_rounded($$m_data{$key},$$m_data_gigs{$key});
+ $data = $gigs = 0;
+ un_round($rounded_volume,\$data,\$gigs);
+ $count = $$m_count{$key};
+ $rounded_average = volume_rounded($data/$count,$gigs/$count);
+ printf($format, $count, $rounded_volume, $rounded_average, $htmlkey);
}
else {
printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $key);
print "<table border=0 width=\"100%\">\n";
print "<tr><td>\n";
print "<table border=1>\n";
- print "<tr><th>Messages</th><th>Bytes</th><th>\u$text</th>\n";
+ print "<tr><th>Messages</th><th>Bytes</th><th>Average</th><th>\u$text</th>\n";
}
else {
printf("%s\n%s\n\n", $temp, "-" x length($temp));
$htmlkey = $key;
$htmlkey =~ s/>/\>\;/g;
$htmlkey =~ s/</\<\;/g;
- printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $htmlkey);
+
+ $rounded_volume = volume_rounded($$m_data{$key},$$m_data_gigs{$key});
+ $data = $gigs = 0;
+ un_round($rounded_volume,\$data,\$gigs);
+ $count = $$m_count{$key};
+ $rounded_average = volume_rounded($data/$count,$gigs/$count);
+ printf($format, $count, $rounded_volume, $rounded_average, $htmlkey);
}
else {
printf($format, $$m_count{$key}, volume_rounded($$m_data{$key},$$m_data_gigs{$key}), $key);
#-------------------------------------
#
# 48 1468KB local
+# Could also have average values for HTML output.
+# 48 1468KB 30KB local
+
my($category,$by_count_or_volume) = ($1,$2);
#As we show 2 views of each table (by count and by volume),
$_ = html2txt($_); #Convert general HTML markup to text.
$reached_table = 1 if (/^\s*\d/);
next unless $reached_table;
+
+ # Remove optional 'average value' column.
+ s/^\s*(\d+)\s+(\S+)\s+(\d+(KB|MB|GB|\b)\s+)/$1 $2 /;
+
if (/^\s*(\d+)\s+(\S+)\s*(.*?)\s*$/) {
my($count,$rounded_volume,$entry) = ($1,$2,$3);
#Note: $entry fields can be both null and can contain spaces.