X-Git-Url: https://code.th-h.de/?p=usenet%2Fnewsstats.git;a=blobdiff_plain;f=groupstats.pl;h=dbe7730c49e7a70688f0752e96fc05df5f7c2a02;hp=b4ebecaec7a54a80acb1829d85e6bbfc7787c2c2;hb=b2e0fd244430635e295c8c32b1727331924fdae6;hpb=404c1acdc817c4f5dfece1d76f8644a54e4e56d8 diff --git a/groupstats.pl b/groupstats.pl index b4ebeca..dbe7730 100755 --- a/groupstats.pl +++ b/groupstats.pl @@ -73,10 +73,15 @@ if ($Options{'l'}) { ### get time period my ($StartMonth,$EndMonth) = &GetTimePeriod($Options{'m'},$Options{'p'}); -# reset to one month for 'dump' output type +# if time period is more than one month: set output type to '-o pretty' or '-o dumpgroup' if ($Options{'o'} eq 'dump' and $Options{'p'}) { - warn ("$MySelf: W: You cannot combine time periods (-p) with '-o dump', changing output type to '-o pretty'.\n"); - $Options{'o'} = 'pretty'; + if (defined($Options{'n'}) and $Options{'n'} !~ /:|\*/) { + warn ("$MySelf: W: You cannot combine time periods (-p) with '-o dump', changing output type to '-o dumpgroup'.\n"); + $Options{'o'} = 'dumpgroup'; + } else { + warn ("$MySelf: W: You cannot combine time periods (-p) with '-o dump', changing output type to '-o pretty'.\n"); + $Options{'o'} = 'pretty'; + } }; ### init database @@ -155,13 +160,17 @@ if (!defined($Options{'b'}) and !defined($Options{'l'})) { } else { $Level = '>'; }; - # push level and $StartMonth,$EndMonth - again - to Params - # FIXME -- together with the query (see below) - push @Params,$Options{'l'}; - push @Params,$StartMonth,$EndMonth; - # prepare query: get number of postings per group from groups table for given months and - # FIXME -- this query is ... in dire need of impromevent - $DBQuery = $DBHandle->prepare(sprintf("SELECT month,newsgroup,postings FROM %s.%s WHERE newsgroup IN (SELECT newsgroup FROM %s.%s WHERE %s GROUP BY newsgroup HAVING MAX(postings) %s ?) AND %s ORDER BY newsgroup,month",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$WhereClause,$Level,$WhereClause)); + # prepare and execute query: get list of newsgroups meeting level condition + $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroup FROM %s.%s WHERE %s GROUP BY newsgroup HAVING MAX(postings) %s ?",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$WhereClause,$Level)); + $DBQuery->execute($StartMonth,$EndMonth,@GroupList,$Options{'l'}) + or die sprintf("$MySelf: E: Can't get groups data for %s to %s from %s.%s: %s\n",$StartMonth,$EndMonth,$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$DBI::errstr); + # add newsgroups to a comma-seperated list ready for IN(...) query + my $GroupList; + while (my ($Newsgroup) = $DBQuery->fetchrow_array) { + $GroupList .= ',' if (defined($GroupList) and $GroupList ne ''); + $GroupList .= "'$Newsgroup'"; + }; + $DBQuery = $DBHandle->prepare(sprintf("SELECT month,newsgroup,postings FROM %s.%s WHERE newsgroup IN (%s) AND %s ORDER BY newsgroup,month",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$GroupList,$WhereClause)); }; # execute query @@ -170,8 +179,13 @@ $DBQuery->execute($StartMonth,$EndMonth,@GroupList,@Params) # output results # print caption (-c) with time period if -m or -p is set -# FIXME - month or period should handled differently -printf ("----- Report from %s to %s\n",$StartMonth,$EndMonth) if $Options{'c'} and ($Options{'m'} or $Options{'p'}); +if ($Options{'c'}) { + if ($Options{'p'}) { + printf ("----- Report from %s to %s\n",$StartMonth,$EndMonth); + } elsif ($Options{'m'}) { + printf ("----- Report for %s\n",$StartMonth); + }; +}; # print caption (-c) with newsgroup list if -n is set printf ("----- Newsgroups: %s\n",join(',',split(/:/,$Newsgroups))) if $Options{'c'} and $Options{'n'}; # print caption (-c) with threshold if -t is set, taking -i in account @@ -183,16 +197,16 @@ if (!defined($Options{'b'}) and !defined($Options{'l'})) { # -b is set (then -l can't be!) # we have to read in the query results ourselves, as they do not have standard layout while (my ($Newsgroup,$Postings) = $DBQuery->fetchrow_array) { - # we just assign "top x" or "bottom x" instead of a month for the caption - # FIXME - print &FormatOutput($Options{'o'}, ($Options{'i'} ? 'Bottom ' : 'Top ').$Options{'b'}, $Newsgroup, $Postings, $MaxLength); + # we just assign "top x" or "bottom x" instead of a month for the caption and force an output type of pretty + print &FormatOutput('pretty', ($Options{'i'} ? 'Bottom ' : 'Top ').$Options{'b'}, $Newsgroup, $Postings, $MaxLength); }; } else { # -l must be set now, as all other cases have been taken care of + # print caption (-c) with level, taking -i in account + printf ("----- Newsgroups with %s than %u postings over the whole time period\n",$Options{'i'} ? 'less' : 'more',$Options{'l'}) if $Options{'c'}; # we have to read in the query results ourselves, as they do not have standard layout while (my ($Month,$Newsgroup,$Postings) = $DBQuery->fetchrow_array) { # we just switch $Newsgroups and $Month for output generation - # FIXME print &FormatOutput($Options{'o'}, $Newsgroup, $Month, $Postings, 7); }; };