From 70f1b42e11c2420d575afe159bdb552efd29b329 Mon Sep 17 00:00:00 2001 From: octo Date: Mon, 11 Apr 2005 17:32:10 +0000 Subject: [PATCH] Added export-function to Interestingnumbers. Finished converting Userdetails.. --- lib/Onis/Plugins/Interestingnumbers.pm | 20 ++++- lib/Onis/Plugins/Userdetails.pm | 139 ++++++++++++--------------------- 2 files changed, 67 insertions(+), 92 deletions(-) diff --git a/lib/Onis/Plugins/Interestingnumbers.pm b/lib/Onis/Plugins/Interestingnumbers.pm index 935f1de..57becb6 100644 --- a/lib/Onis/Plugins/Interestingnumbers.pm +++ b/lib/Onis/Plugins/Interestingnumbers.pm @@ -3,6 +3,8 @@ package Onis::Plugins::Interestingnumbers; use strict; use warnings; +use Exporter; + use Onis::Config (qw(get_config)); use Onis::Html (qw(html_escape get_filehandle)); use Onis::Language (qw(translate)); @@ -10,6 +12,9 @@ use Onis::Data::Core (qw(register_plugin)); use Onis::Data::Persistent; use Onis::Users (qw(nick_to_name)); +@Onis::Plugins::Interestingnumbers::EXPORT_OK = (qw(get_interestingnumbers)); +@Onis::Plugins::Interestingnumbers::ISA = ('Exporter'); + register_plugin ('ACTION', \&add_action); register_plugin ('JOIN', \&add_join); register_plugin ('KICK', \&add_kick); @@ -17,7 +22,8 @@ register_plugin ('MODE', \&add_mode); register_plugin ('TEXT', \&add_text); register_plugin ('OUTPUT', \&output); -our $InterestingNumbersCache = Onis::Data::Persistent->new ('InterestingNumbersCache', 'nick', qw(actions joins kicks_given kicks_received ops_given ops_taken soliloquies)); +our $InterestingNumbersCache = Onis::Data::Persistent->new ('InterestingNumbersCache', 'nick', + qw(actions joins kicks_given kicks_received ops_given ops_taken soliloquies)); our $InterestingNumbersData = {}; our $SoliloquiesNick = ''; @@ -398,3 +404,15 @@ sub sort_by_field return (@retval); } + +sub get_interestingnumbers +{ + my $nick = shift; + + if (defined ($InterestingNumbersData->{$nick})) + { + return ({}); + } + + return ($InterestingNumbersData->{$nick}); +} diff --git a/lib/Onis/Plugins/Userdetails.pm b/lib/Onis/Plugins/Userdetails.pm index 48723ca..4d3edf7 100644 --- a/lib/Onis/Plugins/Userdetails.pm +++ b/lib/Onis/Plugins/Userdetails.pm @@ -9,9 +9,10 @@ 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::Plugin::Core (qw(get_core_nick_counters)); -use Onis::Plugin::Conversations (qw(get_conversations)); -use Onis::Plugin::Bignumbers (qw(get_bignumbers)); +use Onis::Plugins::Core (qw(get_core_nick_counters)); +use Onis::Plugins::Conversations (qw(get_conversations)); +use Onis::Plugins::Bignumbers (qw(get_bignumbers)); +use Onis::Plugins::Interestingnumbers (qw(get_interestingnumbers)); our $DISPLAY_IMAGES = 0; our $DEFAULT_IMAGE = ''; @@ -155,10 +156,11 @@ sub output $nick_data->{$nick} = get_core_nick_counters ($nick); $nick_data->{$nick}{'conversations'} = get_conversations ($nick); $nick_data->{$nick}{'bignumbers'} = get_bignumbers ($nick); + $nick_data->{$nick}{'interestingnumbers'} = get_interestingnumbers ($nick); for (my $i = 0; $i < 12; $i++) { - $num = $nick_data->{$nick}{'lines'}[$i] + $nick_data->{$nick}{'lines'}[$i + 1]; + $num = $nick_data->{$nick}{'lines'}[2 * $i] + $nick_data->{$nick}{'lines'}[(2 * $i) + 1]; $max_time = $num if ($max_time < $num); } @@ -261,61 +263,40 @@ sub output print $fh qq# \n \n#; - # FIXME - - if (defined ($DATA->{'byname'}{$name}{'op_given'})) + if (%{$ptr->{'interestingnumbers'}}) { - $num = $DATA->{'byname'}{$name}{'op_given'}; $trans = translate ('Has given %u ops'); - - printf $fh (" $trans
\n", $num); - } + printf $fh (" $trans
\n", $ptr->{'interestingnumbers'}{'ops_given'}); - if (defined ($DATA->{'byname'}{$name}{'op_taken'})) - { - $num = $DATA->{'byname'}{$name}{'op_taken'}; $trans = translate ('Has taken %u ops'); + printf $fh (" $trans
\n", $ptr->{'interestingnumbers'}{'ops_taken'}); - printf $fh (" $trans
\n", $num); - } - - if (defined ($DATA->{'byname'}{$name}{'kick_given'})) - { - $num = $DATA->{'byname'}{$name}{'kick_given'}; $trans = translate ('Has kicked out %u people'); - - printf $fh (" $trans
\n", $num); - } + printf $fh (" $trans
\n", $ptr->{'interestingnumbers'}{'kicks_given'}); - if (defined ($DATA->{'byname'}{$name}{'kick_received'})) - { - $num = $DATA->{'byname'}{$name}{'kick_received'}; $trans = translate ('Has been kicked out %u times'); + printf $fh (" $trans
\n", $ptr->{'interestingnumbers'}{'kicks_received'}); - printf $fh (" $trans
\n", $num); + $trans = translate ('Has performed %u actions'); + printf $fh (" $trans
\n", $ptr->{'interestingnumbers'}{'actions'}); } - - if (defined ($DATA->{'byname'}{$name}{'questions'})) + + if (%{$ptr->{'bignumbers'}}) { - $num = 100 * $DATA->{'byname'}{$name}{'questions'} / $DATA->{'byname'}{$name}{'lines'}; + $num = 100 * $ptr->{'bignumbers'}{'questions'} / $ptr->{'lines_total'}; $trans = translate ("Question ratio: %.1f%%"); - printf $fh (" $trans
\n", $num); - } - - if (defined ($DATA->{'byname'}{$name}{'topics'})) - { - $num = $DATA->{'byname'}{$name}{'topics'}; - $trans = translate ('Has set %u topics'); + $num = 100 * $ptr->{'bignumbers'}{'uppercase'} / $ptr->{'lines_total'}; + $trans = translate ("Uppercase ratio: %.1f%%"); printf $fh (" $trans
\n", $num); - } - if (defined ($DATA->{'byname'}{$name}{'actions'})) - { - $num = $DATA->{'byname'}{$name}{'actions'}; - $trans = translate ('Has performed %u actions'); + $num = 100 * $ptr->{'bignumbers'}{'smiley_happy'} / $ptr->{'lines_total'}; + $trans = translate ("Happy smiley ratio: %.1f%%"); + printf $fh (" $trans
\n", $num); + $num = 100 * $ptr->{'bignumbers'}{'smiley_sad'} / $ptr->{'lines_total'}; + $trans = translate ("Sad smiley ratio: %.1f%%"); printf $fh (" $trans
\n", $num); } @@ -328,32 +309,22 @@ sub output print $fh qq# \n \n \n \n#; - if (defined ($DATA->{'byname'}{$name}{'chars_time'})) + if (defined ($ptr->{'chars'})) { print $fh qq# \n \n#; - for (0..11) + for (my $i = 0; $i < 12; $i++) { - my $hour = 2 * $_; - my $num = 0; + my $hour = 2 * $i; + $num = 0; my $img = $V_IMAGES[int ($hour / 6)]; my $height; - if (defined ($DATA->{'byname'}{$name}{'chars_time'}{$hour})) - { - $num = $DATA->{'byname'}{$name}{'chars_time'}{$hour}; - } - if (defined ($DATA->{'byname'}{$name}{'chars_time'}{1 + $hour})) - { - $num = $DATA->{'byname'}{$name}{'chars_time'}{1 + $hour}; - } + $num = $ptr->{'chars'}[$hour]; + $num += $ptr->{'chars'}[$hour + 1]; - $height = int (0.5 + ($time_factor * $num)); - if (!$height) - { - $height = 1; - } + $height = int (0.5 + ($time_factor * $num)) || 1; print $fh qq# \n#; @@ -372,22 +343,27 @@ EOF } else { - print $fh ' '; + print ' '; } print $fh qq# \n EOF - $i = 0; - for (@names) + for (my $i = 0; $i < $PLUGIN_MAX and $i < scalar (@others); $i++) { - my $this_name = $_; + my $other = $others[$i]; + my $other_name = nick_to_name ($other) || $other; my $total = 0; print $fh " \n", - qq# \n#, + qq# \n#, qq# \n"; - - $i++; - - if ($i >= $PLUGIN_MAX) - { - last; - } } print $fh "
$num chars\n#; - if (defined ($DATA->{'byname'}{$name}{'conversations'})) + if (%{$ptr->{'conversations'}}) { my $i; - my $data = $DATA->{'byname'}{$name}{'conversations'}; - my @names = sort + my @others = sort { - ($data->{$b}[0] + $data->{$b}[1] + $data->{$b}[2] + $data->{$b}[3]) + ($ptr->{'conversations'}{$b}{'nicks'}{$nick}[0] + + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[1] + + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[2] + + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[3]) <=> - ($data->{$a}[0] + $data->{$a}[1] + $data->{$a}[2] + $data->{$a}[3]) + ($ptr->{'conversations'}{$a}{'nicks'}{$nick}[0] + + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[1] + + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[2] + + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[3]) } - keys (%$data); + (keys %{$ptr->{'conversations'}}); $trans = translate ('Talks to'); @@ -398,26 +374,20 @@ EOF
$this_name$other_name#; - for (0..3) + for (my $k = 0; $k < 4; $k++) { - my $k = $_; - my $img = $H_IMAGES[$k]; - my $width = int (0.5 + ($conv_factor * $data->{$this_name}[$_])); - if (!$width) - { - $width = 1; - } + my $width = int (0.5 + ($conv_factor * $ptr->{'conversations'}{$other}{'nicks'}{$nick}[$k])) || 1; print $fh qq#\n
\n"; @@ -447,12 +410,6 @@ EOF { print $fh ' '; } - - $max--; - if ($max <= 0) - { - last; - } } print $fh "\n\n"; -- 2.11.0