X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=lib%2FOnis%2FPlugins%2FCore.pm;h=5294483fa1656b290dd6319c967e2d4981696698;hb=adc61c312d976dbd1789edde652b64a4867c6955;hp=acfdd2e894e0d9efefcdd6b5fe599a3c3d566a1c;hpb=a851b75ed826ff236a498973cb1cda5dba22b61d;p=onis.git diff --git a/lib/Onis/Plugins/Core.pm b/lib/Onis/Plugins/Core.pm index acfdd2e..5294483 100644 --- a/lib/Onis/Plugins/Core.pm +++ b/lib/Onis/Plugins/Core.pm @@ -3,6 +3,9 @@ package Onis::Plugins::Core; use strict; use warnings; +use Carp (qw(confess)); +use Exporter; + =head1 NAME Onis::Plugins::Core @@ -17,10 +20,13 @@ complicated plugin so far. use Onis::Config qw/get_config/; use Onis::Html qw/html_escape get_filehandle/; use Onis::Language qw/translate/; -use Onis::Users qw/get_name get_link get_image nick_to_username/; +use Onis::Users (qw(get_realname get_link get_image ident_to_name)); use Onis::Data::Core qw#get_all_nicks nick_to_ident ident_to_nick get_main_nick register_plugin#; use Onis::Data::Persistent; +@Onis::Plugins::Core::EXPORT_OK = (qw(get_core_nick_counters)); +@Onis::Plugins::Core::ISA = ('Exporter'); + our $NickLinesCounter = Onis::Data::Persistent->new ('NickLinesCounter', 'nick', qw( lines00 lines01 lines02 lines03 lines04 lines05 lines06 lines07 lines08 lines09 lines10 lines11 @@ -42,9 +48,10 @@ our $NickCharsCounter = Onis::Data::Persistent->new ('NickCharsCounter', 'nick', our $QuoteCache = {}; # Saves per-nick information without any modification our $QuoteData = {}; # Is generated before output. Nicks are merged according to Data::Core. +our $NickData = {}; # Same as above, but for nicks rather than quotes. our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#; -our $QuoteCache_SIZE = 10; +our $QuoteCacheSize = 10; our $QuoteMin = 30; our $QuoteMax = 80; our $WORD_LENGTH = 5; @@ -57,14 +64,14 @@ our $DISPLAY_IMAGES = 0; our $DEFAULT_IMAGE = ''; our $BAR_HEIGHT = 130; our $BAR_WIDTH = 100; -our $LONGLINES = 50; -our $SHORTLINES = 10; +our $LongLines = 50; +our $ShortLines = 10; if (get_config ('quote_cache_size')) { my $tmp = get_config ('quote_cache_size'); $tmp =~ s/\D//g; - $QuoteCache_SIZE = $tmp if ($tmp); + $QuoteCacheSize = $tmp if ($tmp); } if (get_config ('quote_min')) { @@ -224,7 +231,7 @@ if (get_config ('longlines')) { my $tmp = get_config ('longlines'); $tmp =~ s/\D//g; - $LONGLINES = $tmp if ($tmp); + $LongLines = $tmp if ($tmp); } if (get_config ('shortlines')) { @@ -232,7 +239,7 @@ if (get_config ('shortlines')) $tmp =~ s/\D//g; if ($tmp or ($tmp == 0)) { - $SHORTLINES = $tmp; + $ShortLines = $tmp; } } @@ -270,7 +277,7 @@ sub add { @counter = qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); } - $counter[$hour]++ + $counter[$hour]++; $NickLinesCounter->put ($nick, @counter); @counter = $NickWordsCounter->get ($nick); @@ -301,7 +308,7 @@ sub add if (defined ($QuoteCache->{$nick})) { - while (scalar (@{$QuoteCache->{$nick}}) > $QuoteCache_SIZE) + while (scalar (@{$QuoteCache->{$nick}}) > $QuoteCacheSize) { shift (@{$QuoteCache->{$nick}}); } @@ -323,35 +330,47 @@ sub calculate { lines => [qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)], words => [qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)], - chars => [qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)] + chars => [qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)], + lines_total => 0, + words_total => 0, + chars_total => 0 }; } my @counter = $NickLinesCounter->get ($nick); if (@counter) { + my $sum = 0; for (my $i = 0; $i < 24; $i++) { $NickData->{$main}{'lines'}[$i] += $counter[$i]; + $sum += $counter[$i]; } + $NickData->{$main}{'lines_total'} = $sum; } @counter = $NickWordsCounter->get ($nick); if (@counter) { + my $sum = 0; for (my $i = 0; $i < 24; $i++) { $NickData->{$main}{'words'}[$i] += $counter[$i]; + $sum += $counter[$i]; } + $NickData->{$main}{'words_total'} = $sum; } @counter = $NickWordsCounter->get ($nick); if (@counter) { + my $sum = 0; for (my $i = 0; $i < 24; $i++) { $NickData->{$main}{'words'}[$i] += $counter[$i]; + $sum += $counter[$i]; } + $NickData->{$main}{'chars_total'} = $sum; } if (!defined ($QuoteData->{$main})) @@ -361,7 +380,7 @@ sub calculate if (defined ($QuoteCache->{$nick})) { my @new = sort (sub { $b->[0] <=> $a->[0] }, @{$QuoteCache->{$nick}}, @{$QuoteData->{$main}}); - splice (@new, $QuoteCache_SIZE) if (scalar (@new) > $QuoteCache_SIZE); + splice (@new, $QuoteCacheSize) if (scalar (@new) > $QuoteCacheSize); $QuoteData->{$main} = \@new; } } @@ -378,11 +397,9 @@ sub activetimes { my $max = 0; # the most lines that were written in one hour.. my $total = 0; # the total amount of lines we wrote.. - my ($i, $j); # used in for-loops my $factor = 0; # used to find a bar's height - my $newline = ''; # buffer variable.. - my @data = @{$DATA->{'byhour'}}; + my @data = qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); my @img_urls = get_config ('vertical_images'); if (!@img_urls) @@ -394,19 +411,20 @@ sub activetimes # this for loop looks for the most amount of lines in one hour and sets # $most_lines - for ($i = 0; $i < 24; $i++) + for (keys %$NickData) { - if (!defined ($data[$i])) + my $nick = shift; + + for (my $i = 0; $i < 24; $i++) { - next; + $data[$i] += $NickData->{$nick}{'chars'}[$i]; } + } + for (my $i = 0; $i < 24; $i++) + { + $max = $data[$i] if ($max < $data[$i]); $total += $data[$i]; - - if ($data[$i] > $max) - { - $max = $data[$i]; - } } if (!$total) @@ -424,9 +442,9 @@ sub activetimes # this for circles through the four colors. Each color represents six hours. # (4 * 6 hours = 24 hours) - for ($i = 0; $i <= 3; $i++) + for (my $i = 0; $i <= 3; $i++) { - for ($j = 0; $j <= 5; $j++) + for (my $j = 0; $j <= 5; $j++) { my $hour = (($i * 6) + $j); if (!defined ($data[$hour])) @@ -455,10 +473,9 @@ sub ranking { my $count = 0; - my @names = grep - { - defined ($DATA->{'byname'}{$_}{'words'}) - } (keys (%{$DATA->{'byname'}})); + my @nicks = keys (%$NickData); + + return unless (@nicks); my $max_lines = 1; my $max_words = 1; @@ -473,15 +490,15 @@ sub ranking my $trans; my $tmp; - ($tmp) = sort { $DATA->{'byname'}{$b}{'lines'} <=> $DATA->{'byname'}{$a}{'lines'} } (@names); - $max_lines = $DATA->{'byname'}{$tmp}{'lines'} || 0; + ($tmp) = sort { $NickData->{$b}{'lines_total'} <=> $NickData->{$a}{'lines_total'} } (@nicks); + $max_lines = $NickData->{$tmp}{'lines_total'} || 0; - ($tmp) = sort { $DATA->{'byname'}{$b}{'words'} <=> $DATA->{'byname'}{$a}{'words'} } (@names); - $max_words = $DATA->{'byname'}{$tmp}{'words'} || 0; + ($tmp) = sort { $NickData->{$b}{'words_total'} <=> $NickData->{$a}{'words_total'} } (@nicks); + $max_words = $NickData->{$tmp}{'words_total'} || 0; + + ($tmp) = sort { $NickData->{$b}{'chars_total'} <=> $NickData->{$a}{'chars_total'} } (@nicks); + $max_chars = $NickData->{$tmp}{'chars_total'} || 0; - ($tmp) = sort { $DATA->{'byname'}{$b}{'chars'} <=> $DATA->{'byname'}{$a}{'chars'} } (@names); - $max_chars = $DATA->{'byname'}{$tmp}{'chars'} || 0; - $trans = translate ('Most active nicks'); print $fh "