From: octo Date: Wed, 13 Apr 2005 16:02:48 +0000 (+0000) Subject: - Added lines-counter again. X-Git-Tag: Release-0.8.0~20^2~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ca16504096dbade16df66456ad23a2cc18fd18de;p=onis.git - Added lines-counter again. - Minor bugfixes.. --- diff --git a/lib/Onis/Data/Core.pm b/lib/Onis/Data/Core.pm index 2925756..701e086 100644 --- a/lib/Onis/Data/Core.pm +++ b/lib/Onis/Data/Core.pm @@ -34,7 +34,8 @@ the F defines a mapping of B -E B. =cut -our $Nick2Ident = Onis::Data::Persistent->new ('Nick2Ident', 'nick', 'ident'); +our $GeneralCounters = Onis::Data::Persistent->new ('GeneralCounters', 'key', 'value'); +our $NickToIdentCache = Onis::Data::Persistent->new ('NickToIdentCache', 'nick', 'ident'); our $ChatterList = Onis::Data::Persistent->new ('ChatterList', 'chatter', 'counter'); our $ChannelNames = Onis::Data::Persistent->new ('ChannelNames', 'channel', 'counter'); @@ -47,6 +48,8 @@ qw( ); @Onis::Data::Core::ISA = ('Exporter'); +our $LinesThisRun = 0; + our $PluginCallbacks = {}; our $OutputCallbacks = []; our @AllNicks = (); @@ -132,14 +135,14 @@ sub store $data->{'user'} = $user; $data->{'ident'} = $ident; - $Nick2Ident->put ($nick, $ident); + $NickToIdentCache->put ($nick, $ident); $chatter = "$nick!$ident"; ($counter) = $ChatterList->get ($chatter); $counter ||= 0; $counter++; $ChatterList->put ($chatter, $counter); } - elsif (($ident) = $Nick2Ident->get ($nick)) + elsif (($ident) = $NickToIdentCache->get ($nick)) { my $chatter = "$nick!$ident"; my $counter; @@ -190,8 +193,14 @@ sub store } } - # TODO - #$DATA->{'total_lines'}++; + { + my ($counter) = $GeneralCounters->get ('lines_total'); + $counter ||= 0; + $counter++; + $GeneralCounters->put ('lines_total', $counter); + + $LinesThisRun++; + } if (defined ($PluginCallbacks->{$type})) { @@ -572,7 +581,7 @@ sub nick_to_ident } else { - ($ident) = $Nick2Ident->get ($nick); + ($ident) = $NickToIdentCache->get ($nick); $ident ||= ''; } @@ -629,8 +638,11 @@ Returns the total number of lines parsed so far. sub get_total_lines { - # TODO - #return ($DATA->{'total_lines'}); + my ($total) = $GeneralCounters->get ('lines_total'); + + return (qw()) unless ($total); + + return ($total, $LinesThisRun); } =item B (I<$old_nick>, I<$new_nick>) @@ -645,11 +657,11 @@ sub nick_rename my $new_nick = shift; my $ident; - ($ident) = $Nick2Ident->get ($old_nick); + ($ident) = $NickToIdentCache->get ($old_nick); if (defined ($ident) and ($ident)) { - $Nick2Ident->put ($new_nick, $ident); + $NickToIdentCache->put ($new_nick, $ident); } } @@ -662,7 +674,7 @@ Print the output. Should be called only once.. sub print_output { # FIXME FIXME FIXME - if (!get_total_lines () and 0) + if (!get_total_lines ()) { print STDERR <<'MESSAGE'; @@ -704,7 +716,7 @@ sub register_plugin return (undef); } - if ($type eq 'OutputCallbacks') + if ($type eq 'OUTPUT') { push (@$OutputCallbacks, $sub_ref); } diff --git a/lib/Onis/Html.pm b/lib/Onis/Html.pm index 5e11740..077138d 100644 --- a/lib/Onis/Html.pm +++ b/lib/Onis/Html.pm @@ -171,19 +171,22 @@ sub close_file { my $runtime = time () - $time_start; my $now = scalar (localtime ()); - my $total_lines = get_total_lines () || 0; + my ($total_lines, $lines_this_time) = get_total_lines (); my $lines_per_sec = 'infinite'; + $total_lines ||= 0; + $lines_this_time ||= 0; + my $hp = translate ("onis' homepage"); my $gen = translate ('This page was generated on %s with %s'); - my $stats = translate ('%u lines processed in %u seconds (%s lines per second)'); + my $stats = translate ('%u lines processed in %u seconds (%s lines per second, %u lines total)'); my $by = translate ('onis is written %s by %s'); my $link = translate ('Get the latest version from %s'); my $lps = translate ('infinite'); if ($runtime) { - $lps = sprintf ("%.1f", ($total_lines / $runtime)); + $lps = sprintf ("%.1f", ($lines_this_time / $runtime)); } print $fh <'; printf $fh ($gen, $now, "onis $::VERSION ("onis not irc stats")"); print $fh "
\n "; - printf $fh ($stats, $total_lines, $runtime, $lps); + printf $fh ($stats, $lines_this_time, $runtime, $lps, $total_lines); print $fh qq#\n \n \n #; - printf $fh ($by, '2000-2004', 'Florian octo Forster <octo@nospam.verplant.org>'); + printf $fh ($by, '2000-2005', 'Florian octo Forster <octo@nospam.verplant.org>'); print $fh qq## if ($PUBLIC_PAGE); print $fh "
\n "; printf $fh ($link, sprintf (qq#%s#, $hp));