Added Longterm-stats to userdetails
[onis.git] / lib / Onis / Plugins / Conversations.pm
index 5af0717..9c39ef1 100644 (file)
@@ -3,13 +3,28 @@ package Onis::Plugins::Conversations;
 use strict;
 use warnings;
 
+use Exporter;
+
 use Onis::Config qw(get_config);
 use Onis::Html qw(get_filehandle);
 use Onis::Language qw(translate);
-use Onis::Data::Core qw(register_plugin get_main_nick nick_to_ident);
-use Onis::Users qw(ident_to_name);
+use Onis::Data::Core qw(register_plugin get_main_nick nick_to_ident nick_to_name);
 use Onis::Data::Persistent;
 
+=head1 NAME
+
+Onis::Plugins::Conversations - Who talks with who
+
+=head1 DESCRIPTION
+
+This plugins tries to recignise conversations and counts the amount that people
+talk to each other.
+
+=cut
+
+@Onis::Plugins::Conversations::EXPORT_OK = (qw(get_conversations));
+@Onis::Plugins::Conversations::ISA = ('Exporter');
+
 our $ConversationCache = Onis::Data::Persistent->new ('ConversationCache', 'partners', qw(time0 time1 time2 time3));
 our $ConversationData = {};
 
@@ -98,9 +113,10 @@ sub calculate
                $nick_from = get_main_nick ($nick_from);
                $nick_to   = get_main_nick ($nick_to);
 
-               next if (!$nick_from or !$nick_to or ($nick_from eq $nick_to));
+               next if (!$nick_from or !$nick_to);
+               next if ($nick_from eq $nick_to);
 
-               if ($ConversationData->{$nick_from}{$nick_to})
+               if (!defined ($ConversationData->{$nick_from}{$nick_to}))
                {
                        $ConversationData->{$nick_from}{$nick_to} =
                        {
@@ -158,6 +174,7 @@ sub output
 
        my @img = get_config ('horizontal_images');
 
+       # FIXME
        my @data = get_top (10);
        return (undef) unless (@data);
 
@@ -172,8 +189,8 @@ sub output
 
                for (my $i = 0; $i < 4; $i++)
                {
-                       $sum0 += $rec->{'users'}{$nick0}[$i];
-                       $sum1 += $rec->{'users'}{$nick1}[$i];
+                       $sum0 += $rec->{'nicks'}{$nick0}[$i];
+                       $sum1 += $rec->{'nicks'}{$nick1}[$i];
                }
 
                $max_num = $sum0 if ($max_num < $sum0);
@@ -208,7 +225,7 @@ EOF
                for (3, 2, 1, 0)
                {
                        my $i = $img[$_];
-                       my $w = int (0.5 + ($rec->{'users'}{$nick0}[$_] * $factor));
+                       my $w = int (0.5 + ($rec->{'nicks'}{$nick0}[$_] * $factor));
                        my $c = '';
                        $w ||= 1;
 
@@ -225,7 +242,7 @@ EOF
                for (0, 1, 2, 3)
                {
                        my $i = $img[$_];
-                       my $w = int (0.5 + ($rec->{'users'}{$nick1}[$_] * $factor));
+                       my $w = int (0.5 + ($rec->{'nicks'}{$nick1}[$_] * $factor));
                        my $c = '';
                        $w ||= 1;
 
@@ -241,3 +258,52 @@ EOF
 
        print $fh "</table>\n\n";
 }
+
+=head1 EXPORTED FUNCTIONS
+
+=over 4
+
+=item B<get_conversations> (I<$nick>)
+
+Returns a hashref to the conversations this nick was involved with. The layout
+is the following. I<$other> is the nick of the person I<$nick> chattet with.
+The arrays hold the number of characters written by the nick used as the key.
+The first field contains the characters for the hours 0-5, the second field
+holds 6-11 and so on.
+
+  {
+    $other =>
+    {
+      total => 0,
+      nicks =>
+      {
+        $nick  => [0, 0, 0, 0],
+        $other => [0, 0, 0, 0]
+      }
+    },
+    ...
+  }
+
+=cut
+
+sub get_conversations
+{
+       my $nick = shift;
+
+       if (!defined ($ConversationData->{$nick}))
+       {
+               return ({});
+       }
+       else
+       {
+               return ($ConversationData->{$nick});
+       }
+}
+
+=back
+
+=head1 AUTHOR
+
+Florian octo Forster, E<lt>octo at verplant.orgE<gt>
+
+=cut