Some work on Userdetails, minor changes/fixes in Core, Conversations and Bignumbers..
authorocto <octo>
Mon, 11 Apr 2005 13:32:30 +0000 (13:32 +0000)
committerocto <octo>
Mon, 11 Apr 2005 13:32:30 +0000 (13:32 +0000)
lib/Onis/Plugins/Bignumbers.pm
lib/Onis/Plugins/Conversations.pm
lib/Onis/Plugins/Core.pm
lib/Onis/Plugins/Userdetails.pm

index 9b5c889..3146f5d 100644 (file)
@@ -82,14 +82,14 @@ sub calculate
                
                if (!defined ($CalcData->{$main}))
                {
                
                if (!defined ($CalcData->{$main}))
                {
-                       my ($lines, $words, $chars) = get_core_nick_counters ($main);
-                       next unless (defined ($chars));
+                       my $core_data = get_core_nick_counters ($main);
+                       next unless (%$core_data);
 
                        $CalcData->{$main} =
                        {
 
                        $CalcData->{$main} =
                        {
-                               lines => $lines,
-                               words => $words,
-                               chars => $chars,
+                               lines => $core_data->{'lines_total'},
+                               words => $core_data->{'words_total'},
+                               chars => $core_data->{'chars_total'},
                                questions    => 0,
                                uppercase    => 0,
                                smiley_happy => 0,
                                questions    => 0,
                                uppercase    => 0,
                                smiley_happy => 0,
index 5af0717..21ea588 100644 (file)
@@ -241,3 +241,17 @@ EOF
 
        print $fh "</table>\n\n";
 }
 
        print $fh "</table>\n\n";
 }
+
+sub get_conversations
+{
+       my $nick = shift;
+
+       if (!defined ($ConversationData->{$nick}))
+       {
+               return ({});
+       }
+       else
+       {
+               return ($ConversationData->{$nick});
+       }
+}
index 5294483..c80359a 100644 (file)
@@ -24,7 +24,7 @@ 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;
 
 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::EXPORT_OK = (qw(get_core_nick_counters get_sorted_nicklist));
 @Onis::Plugins::Core::ISA = ('Exporter');
 
 our $NickLinesCounter = Onis::Data::Persistent->new ('NickLinesCounter', 'nick',
 @Onis::Plugins::Core::ISA = ('Exporter');
 
 our $NickLinesCounter = Onis::Data::Persistent->new ('NickLinesCounter', 'nick',
@@ -49,6 +49,7 @@ 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 $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 $SortedNicklist = [];
 
 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 $QuoteCacheSize = 10;
 
 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 $QuoteCacheSize = 10;
@@ -557,10 +558,14 @@ EOF
        print $fh "    <th>$trans</th>\n",
        "  </tr>\n";
 
        print $fh "    <th>$trans</th>\n",
        "  </tr>\n";
 
-       for (sort
+       @$SortedNicklist = sort
        {
                $NickData->{$b}{"${sort_field}_total"} <=> $NickData->{$a}{"${sort_field}_total"}
        {
                $NickData->{$b}{"${sort_field}_total"} <=> $NickData->{$a}{"${sort_field}_total"}
-       } (@nicks))
+       } (@nicks);
+
+       @nicks = ();
+
+       for (@$SortedNicklist)
        {
                my $nick = $_;
                my $ident = nick_to_ident ($nick);
        {
                my $nick = $_;
                my $ident = nick_to_ident ($nick);
@@ -831,8 +836,17 @@ sub bar
 
 =item B<get_core_nick_counters> (I<$nick>)
 
 
 =item B<get_core_nick_counters> (I<$nick>)
 
-Returns the total I<lines>, I<words> and I<characters> written by the given
-nick.
+Returns a hash-ref that containes all the nick-counters available. It looks
+like this:
+
+    {
+        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)],
+       lines_total => 0,
+       words_total => 0,
+       chars_total => 0
+    }
 
 =cut
 
 
 =cut
 
@@ -840,14 +854,24 @@ sub get_core_nick_counters
 {
        my $nick = shift;
 
 {
        my $nick = shift;
 
-       if (defined ($NickData->{$nick}))
+       if (!defined ($NickData->{$nick}))
        {
        {
-               return ($NickData->{$nick}{'lines_total'},
-                       $NickData->{$nick}{'words_total'},
-                       $NickData->{$nick}{'chars_total'});
+               return ({});
        }
 
        }
 
-       return (qw());
+       return ($NickData->{$nick});
+}
+
+=item B<get_sorted_nicklist> ()
+
+Returns an array-ref that containes all nicks, sorted by the field given in the
+config-file.
+
+=cut
+
+sub get_sorted_nicklist
+{
+       return ($SortedNicklist);
 }
 
 =back
 }
 
 =back
index 75f91e2..920881f 100644 (file)
@@ -9,6 +9,9 @@ use Onis::Language (qw(translate));
 use Onis::Data::Core (qw(get_main_nick register_plugin));
 use Onis::Users (qw(ident_to_name get_link get_image));
 
 use Onis::Data::Core (qw(get_main_nick register_plugin));
 use Onis::Users (qw(ident_to_name get_link get_image));
 
+use Onis::Plugin::Core (qw(get_core_nick_counters));
+use Onis::Plugin::Conversations (qw(get_conversations));
+
 our $DISPLAY_IMAGES = 0;
 our $DEFAULT_IMAGE = '';
 
 our $DISPLAY_IMAGES = 0;
 our $DEFAULT_IMAGE = '';
 
@@ -129,15 +132,7 @@ return (1);
 
 sub output
 {
 
 sub output
 {
-       my @names = sort
-       {
-               $DATA->{'byname'}{$b}{$SORT_BY} <=> $DATA->{'byname'}{$a}{$SORT_BY}
-       } grep
-       {
-               defined ($DATA->{'byname'}{$_}{'words'})
-       } (keys (%{$DATA->{'byname'}}));
-
-       return (undef) unless (@names);
+       my $nicks_ref = get_sorted_nicklist ();
        
        my $max = $PLUGIN_MAX;
        
        
        my $max = $PLUGIN_MAX;
        
@@ -149,9 +144,15 @@ sub output
        my $max_time = 0;
        my $max_conv = 0;
 
        my $max_time = 0;
        my $max_conv = 0;
 
-       for (@names)
+       my @nicks = $nicks_ref->[0 .. ($max - 1)];
+       my $nick_data = {};
+
+       for (@nicks)
        {
        {
-               my $name = $_;
+               my $nick = $_;
+
+               $nick_data->{$nick} = get_core_nick_counters ($nick);
+               $nick_data->{$nick}{'conversations'} = get_conversations ($nick);
                
                if (defined ($DATA->{'byname'}{$name}{'chars_time'}))
                {
                
                if (defined ($DATA->{'byname'}{$name}{'chars_time'}))
                {