#!/usr/bin/perl # # postingstats.pl # # This script will create a posting statistic for de.admin.lists # from NewsStats output. # # It is part of the NewsStats package. # # Copyright (c) 2010-2012 Thomas Hochstein # # It can be redistributed and/or modified under the same terms under # which Perl itself is published. # # $~ groupstats.pl --nocomments --sums --format dump | postingstats.pl xxxx-xx # use strict; use constant TABLEWIDTH => 28; # width of table without newsgroup name our $VERSION = '0.01'; ##### ----- subroutines ----- sub percentage { # calculate percentage rate from base value and percentage my ($base,$percentage) = @_; return ($percentage * 100 / $base); } sub divider { # build a divider line of $symbol as wide as the table is my ($symbol,$maxlength) = @_; return ':' . $symbol x ($maxlength+TABLEWIDTH) . ":\n"; } ##### ----- main loop ----- # get $month from ARGV my $month = shift; # read from STDIN my (%postings, $hierarchy, $maxlength); while(<>) { my ($group, $postings) = split; $hierarchy = $postings if $group eq 'de.ALL'; next if $group =~ /ALL$/; $postings{$group} = $postings; $maxlength = length($group) if length($group) > $maxlength; } # print to STDOUT my $heading = ' Postingstatistik fuer de.* im Monat '.$month; my $padding = ' ' x (($maxlength+TABLEWIDTH-2-length($heading))/2); my $timestamp = time; my $counter = 0; print < Newsgroups: de.admin.news.misc Subject: Postingstatistik fuer de.* im Monat $month Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit User-Agent: postingstats.pl/$VERSION (NewsStats) HEADER print ÷r('=',$maxlength); printf(": %s%s%s :\n",$padding,$heading,$padding); print ÷r('=',$maxlength); printf(": Nr. : Anzahl : Prozent : %-*s :\n",$maxlength,'Newsgroup'); print ÷r('-',$maxlength); foreach my $group (sort { $postings{$b} <=> $postings {$a}} keys %postings) { $counter++; printf(": %3u. : %6u : %6.2f%% : %-*s :\n",$counter,$postings{$group},&percentage($hierarchy,$postings{$group}),$maxlength,$group); } print ÷r('-',$maxlength); printf(": : %6u : %s : %-*s :\n",$hierarchy,'100.00%',$maxlength,'de.*'); print ÷r('=',$maxlength); print < zur Verfuegung. LEADOUT