From 53c2032850f427d28d82f71f809d20d680a5da26 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Fri, 4 May 2012 07:42:52 +0200 Subject: [PATCH] Add postingstats to tools. postingstats.pl will parse groupstats output and create a posting ready to post to de.admin.news.misc. Signed-off-by: Thomas Hochstein --- tools/postingstats.pl | 99 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tools/postingstats.pl diff --git a/tools/postingstats.pl b/tools/postingstats.pl new file mode 100644 index 0000000..227f53e --- /dev/null +++ b/tools/postingstats.pl @@ -0,0 +1,99 @@ +#!/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