diff --git a/bin/postingstats.pl b/bin/postingstats.pl index f74d89e..a9d1e9a 100644 --- a/bin/postingstats.pl +++ b/bin/postingstats.pl @@ -16,6 +16,7 @@ # Usage: # $~ groupstats.pl --nocomments --sums --format dump | postingstats.pl -t groups # $~ hoststats.pl --nocomments --sums --format dump | postingstats.pl -t hosts +# $~ clientstats.pl --nocomments --sums --versions --format dump | postingstats.pl -t clients # BEGIN { @@ -53,19 +54,22 @@ if (!$Type) { $Type = 'GroupStats'; } elsif ($Type =~ /(host|server)s?/i) { $Type = 'HostStats'; +} elsif ($Type =~ /(client|reader)s?/i) { + $Type = 'ClientStats'; }; my $Timestamp = time; ##### ----- configuration -------------------------------------------- my $TLH = 'de'; -my %Heading = ('GroupStats' => 'Postingstatistik fuer de.* im Monat '.$Month, - 'HostStats' => 'Serverstatistik fuer de.* im Monat '.$Month +my %Heading = ('GroupStats' => 'Postingstatistik fuer de.* im Monat '.$Month, + 'HostStats' => 'Serverstatistik fuer de.* im Monat '.$Month, + 'ClientStats' => 'Newsreaderstatistik fuer de.* im Monat '.$Month ); my %TH = ('counter' => 'Nr.', 'value' => 'Anzahl', 'percentage' => 'Prozent' ); -my %LeadIn = ('GroupStats' => < < < < < Newsgroups: local.test Subject: Postingstatistik fuer de.* im Monat $Month @@ -88,7 +92,18 @@ Content-Transfer-Encoding: 7bit User-Agent: postingstats.pl/$VERSION (NewsStats) HOSTSIN -my %LeadOut = ('GroupStats' => < < +Newsgroups: local.test +Subject: Newsreaderstatistik fuer de.* im Monat $Month +Message-ID: +Approved: thh\@thh.name +Mime-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: 8bit +User-Agent: postingstats.pl/$VERSION (NewsStats) + +CLIENTSIN +my %LeadOut = ('GroupStats' => < < < $$RMaxLength; + + # delete single version + delete($$RSubValue{$LastName}); +} + ##### ----- main loop ------------------------------------------------ -my (%Value, $SumName, $SumTotal, $MaxLength); -$MaxLength = 0; +my (%Value, %SubValue, $SubCounter, $LastName, $SumName, $SumTotal, + $MaxLength); + if ($Type eq 'GroupStats') { $SumName = "$TLH.ALL"; $TH{'name'} = 'Newsgroup' } elsif ($Type eq 'HostStats') { $SumName = 'ALL'; - $TH{'name'} = 'Server' + $TH{'name'} = 'Postingserver' +} elsif ($Type eq 'ClientStats') { + $SumName = 'ALL'; + $TH{'name'} = 'Newsreader / Client' } -# read from STDIN +### read from STDIN +$MaxLength = 0; while(<>) { - my ($Name, $Value) = split; + my ($Name, $Value) = $_ =~ /(.+) (\d+)$/; $SumTotal = $Value if $Name eq $SumName; next if $Name =~ /ALL$/; - $Value{$Name} = $Value; - $MaxLength = length($Name) if length($Name) > $MaxLength; -} -# print to STDOUT + # handle client versions + if ($Type eq 'ClientStats' and $Name =~ /^- /) { + $SubValue{$LastName}{$Name} = $Value; + $SubCounter++; + } else { + # clients with just one version + &SingleVersion($LastName,\%SubValue,\%Value,\$MaxLength) + if ($LastName && $SubCounter == 1); + + # reset version counter and client name + $SubCounter = 0; + $LastName = $Name; + + $Value{$Name} = $Value; + $MaxLength = length($Name) if length($Name) > $MaxLength; + } +} +# clients with just one version (last iteration) +&SingleVersion($LastName,\%SubValue,\%Value,\$MaxLength) + if ($LastName && $SubCounter == 1); + +### print to STDOUT +# calculate padding for $Heading my $PaddingLeft = ' ' x int((($MaxLength+TABLEWIDTH-2-length($Heading{$Type}))/2)); my $PaddingRight = $PaddingLeft; -$PaddingLeft .= ' ' if (length($Heading{$Type}) + (length($PaddingLeft) * 2) < $MaxLength+TABLEWIDTH); -my $Counter = 0; +$PaddingLeft .= ' ' if (length($Heading{$Type}) + (length($PaddingLeft) * 2) +2 < $MaxLength+TABLEWIDTH); print $LeadIn{$Type}; +# print table header print &Divider('=',$MaxLength); printf(": %s%s%s :\n",$PaddingLeft,$Heading{$Type},$PaddingRight); print &Divider('=',$MaxLength); @@ -163,11 +232,26 @@ printf(": %-3s : %-6s : %-7s : %-*s :\n", $MaxLength,$TH{'name'}); print &Divider('-',$MaxLength); -foreach my $Name (sort { $Value{$b} <=> $Value {$a}} keys %Value) { +# print table +my $Counter = 0; +foreach my $Name (sort { $Value{$b} <=> $Value{$a} } keys %Value) { $Counter++; - printf(": %3u. : %6u : %6.2f%% : %-*s :\n",$Counter,$Value{$Name},&Percentage($SumTotal,$Value{$Name}),$MaxLength,$Name); + printf(": %3u. : %6u : %6.2f%% : %-*s :\n", + $Counter,$Value{$Name},&Percentage($SumTotal,$Value{$Name}), + $MaxLength,$Name); + # handle client versions + if ($SubValue{$Name}) { + foreach my $SubName (sort { $SubValue{$Name}{$b} <=> $SubValue{$Name}{$a} } + keys %{$SubValue{$Name}}) { + printf(": : %6u : %6.2f%% : %-*s :\n", + $SubValue{$Name}{$SubName}, + &Percentage($SumTotal,$SubValue{$Name}{$SubName}), + $MaxLength,$SubName); + } + } } +# print table footer print &Divider('-',$MaxLength); printf(": : %6u : %s : %-*s :\n",$SumTotal,'100.00%',$MaxLength,''); print &Divider('=',$MaxLength); @@ -184,7 +268,7 @@ postingstats - format and post reports =head1 SYNOPSIS -B B<-t> I [B<-Vh> [B<-m> I] +B B<-t> I [B<-Vh> [B<-m> I] =head1 REQUIREMENTS @@ -193,8 +277,8 @@ See L. =head1 DESCRIPTION This script will re-format reports on newsgroup usage created by -B or B and create a message that can -be posted to Usenet. +B, B or B and create a +message that can be posted to Usenet. =head2 Features and options @@ -228,8 +312,8 @@ sum total. =item C<%Heading> -Hash with keys for I and I. Used to display a -heading. +Hash with keys for I, I and I. +Used to display a heading. =item C<%TH> @@ -242,14 +326,14 @@ Output will be truncated otherwise. =item C<%LeadIn> -Hash with keys for I and I. Used to create the -headers for our posting. Can contain other text that will be shown -before C<%Heading>. +Hash with keys for I, I and I. +Used to create the headers for our posting. Can contain other text +that will be shown before C<%Heading>. =item C<%LeadOut> -Hash with keys for I and I. Will be shown at the -end of our posting. +Hash with keys for I, I and I. +Will be shown at the end of our posting. =back @@ -265,9 +349,10 @@ Print out version and copyright information and exit. Print this man page and exit. -=item B<-t>, B<--type> I +=item B<-t>, B<--type> I -Set report type to posting statistics or hosts statistics accordingly. +Set report type to posting statistics, hosts statistics or client +statistics accordingly. =item B<-m>, B<--month> I @@ -293,6 +378,10 @@ Create a posting from a host statistics report for last month: hoststats.pl --nocomments --sums --format dump | postingstats.pl -t hosts +Create a posting from a client statistics report for last month: + + clientstats.pl --nocomments --sums --versions --format dump | postingstats.pl -t clients + =head1 FILES =over 4 @@ -336,6 +425,10 @@ groupstats -h hoststats -h +=item - + +clientstats -h + =back This script is part of the B package. diff --git a/doc/ChangeLog b/doc/ChangeLog index 309ff60..f230009 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -7,6 +7,7 @@ NewsStats 0.4.0 (unreleased) * Add ClientStats to gatherstats. * Move cliservstats to hoststats. * Add clientstats (for clients). + * Add ClientStats to postingstats. NewsStats 0.3.0 (2025-05-18) * Extract GroupStats (in gatherstats) to subroutine.