1 package Onis::Plugins::Userdetails;
6 use Onis::Config (qw(get_config));
7 use Onis::Html (qw(html_escape get_filehandle));
8 use Onis::Language (qw(translate));
9 use Onis::Data::Core (qw(get_main_nick register_plugin nick_to_name));
10 use Onis::Users (qw(ident_to_name get_link get_image));
12 use Onis::Plugins::Core (qw(get_core_nick_counters get_sorted_nicklist));
13 use Onis::Plugins::Weekdays (qw(get_weekdays));
14 use Onis::Plugins::Conversations (qw(get_conversations));
15 use Onis::Plugins::Bignumbers (qw(get_bignumbers));
16 use Onis::Plugins::Interestingnumbers (qw(get_interestingnumbers));
18 our $DISPLAY_IMAGES = 0;
19 our $DEFAULT_IMAGE = '';
21 register_plugin ('OUTPUT', \&output);
23 our $SORT_BY = 'lines';
24 if (get_config ('sort_by'))
26 my $tmp = get_config ('sort_by');
29 if (($tmp eq 'lines') or ($tmp eq 'words') or ($tmp eq 'chars'))
35 # The Core plugin already complained about this..
39 if (get_config ('plugin_max'))
41 my $tmp = get_config ('plugin_max');
43 $PLUGIN_MAX = $tmp if ($tmp);
45 if (get_config ('display_images'))
47 my $tmp = get_config ('display_images');
49 if ($tmp =~ m/true|on|yes/i)
53 elsif ($tmp =~ m/false|off|no/i)
59 print STDERR $/, __FILE__, ": ``display_times'' has been set to the invalid value ``$tmp''. ",
60 $/, __FILE__, ": Valid values are ``true'' and ``false''. Using default value ``false''.";
63 if (get_config ('default_image'))
65 $DEFAULT_IMAGE = get_config ('default_image');
68 our @H_IMAGES = qw#dark-theme/h-red.png dark-theme/h-blue.png dark-theme/h-yellow.png dark-theme/h-green.png#;
69 if (get_config ('horizontal_images'))
71 my @tmp = get_config ('horizontal_images');
74 if (scalar (@tmp) != 4)
77 # The core-pligin already complained about this..
80 for ($i = 0; $i < 4; $i++)
82 if (!defined ($tmp[$i]))
87 $H_IMAGES[$i] = $tmp[$i];
91 our @V_IMAGES = qw#images/ver0n.png images/ver1n.png images/ver2n.png images/ver3n.png#;
92 if (get_config ('vertical_images'))
94 my @tmp = get_config ('vertical_images');
97 if (scalar (@tmp) != 4)
100 # Hopefully someone complained by now..
103 for ($i = 0; $i < 4; $i++)
105 if (!defined ($tmp[$i]))
110 $V_IMAGES[$i] = $tmp[$i];
114 our $BAR_HEIGHT = 130;
115 if (get_config ('bar_height'))
117 my $tmp = get_config ('bar_height');
119 $BAR_HEIGHT = $tmp if ($tmp >= 10);
121 #$BAR_HEIGHT = int ($BAR_HEIGHT / 2);
123 our $BAR_WIDTH = 100;
124 if (get_config ('bar_width'))
126 my $tmp = get_config ('bar_width');
128 $BAR_WIDTH = $tmp if ($tmp >= 10);
131 my $VERSION = '$Id: Userdetails.pm,v 1.5 2005/03/14 18:40:25 octo Exp $';
132 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
138 my $nicks_ref = get_sorted_nicklist ();
140 my $fh = get_filehandle ();
142 my $trans = translate ('Detailed nick stats');
149 my @nicks = @$nicks_ref;
152 splice (@nicks, $PLUGIN_MAX) if (scalar (@nicks) > $PLUGIN_MAX);
158 $nick_data->{$nick} = get_core_nick_counters ($nick);
159 $nick_data->{$nick}{'weekdays'} = get_weekdays ($nick);
160 $nick_data->{$nick}{'conversations'} = get_conversations ($nick);
161 $nick_data->{$nick}{'bignumbers'} = get_bignumbers ($nick);
162 $nick_data->{$nick}{'interestingnumbers'} = get_interestingnumbers ($nick);
164 for (my $i = 0; $i < 24; $i++)
166 $num = $nick_data->{$nick}{'chars'}[$i];
167 $max_time = $num if ($max_time < $num);
170 for (keys %{$nick_data->{$nick}{'conversations'}})
173 my $ptr = $nick_data->{$nick}{'conversations'}{$other}{'nicks'}{$nick};
174 $num = $ptr->[0] + $ptr->[1] + $ptr->[2] + $ptr->[3];
175 $max_conv = $num if ($max_conv < $num);
178 for (keys %{$nick_data->{$nick}{'weekdays'}})
181 my $ptr = $nick_data->{$nick}{'weekdays'}{$day};
183 for (my $i = 0; $i < 4; $i++)
185 $max_weekday = $ptr->[$i] if ($max_weekday < $ptr->[$i]);
195 $time_factor = $BAR_HEIGHT / $max_time;
200 $conv_factor = $BAR_WIDTH / $max_conv;
203 print $fh qq#<table class="plugin userdetails">\n#,
205 qq# <th colspan="#, $DISPLAY_IMAGES ? 4 : 3, qq#">$trans</th>\n#,
211 my $name = nick_to_name ($nick);
212 my $print = $name ? $name : $nick;
213 my $ptr = $nick_data->{$nick};
215 print $fh qq# <tr>\n#,
216 qq# <th colspan="#, $DISPLAY_IMAGES ? 4 : 3, qq#" class="nick">$print</th>\n#,
222 my $link = get_link ($name);
223 my $image = get_image ($name);
225 if ($DEFAULT_IMAGE and !$image)
227 $image = $DEFAULT_IMAGE;
230 print $fh qq# <td class="image" rowspan="2">#;
235 print $fh qq#<a href="$link">#;
237 print $fh qq#<img src="$image" alt="$print" />#;
250 print $fh qq# <td class="counters">\n#;
257 $lines = $ptr->{'lines_total'};
258 $trans = translate ('Has written %u lines');
259 printf $fh (" $trans<br />\n", $lines);
261 $words = $ptr->{'words_total'};
262 $trans = translate ('Has written %u words');
263 printf $fh (" $trans<br />\n", $words);
265 $chars = $ptr->{'chars_total'};
266 $trans = translate ('Has written %u chars');
267 printf $fh (" $trans<br />\n", $chars);
271 $num = $words / $lines;
272 $trans = translate ('Has written %.1f words per line');
273 printf $fh (" $trans<br />\n", $num);
275 $num = $chars / $lines;
276 $trans = translate ('Has written %.1f characters per line');
277 printf $fh (" $trans<br />\n", $num);
280 print $fh qq# </td>\n <td class="numbers">\n#;
282 if (%{$ptr->{'interestingnumbers'}})
284 $trans = translate ('Has given %u ops');
285 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'op_given'});
287 $trans = translate ('Has taken %u ops');
288 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'op_taken'});
290 $trans = translate ('Has kicked out %u people');
291 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kick_given'});
293 $trans = translate ('Has been kicked out %u times');
294 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'kick_received'});
296 $trans = translate ('Has performed %u actions');
297 printf $fh (" $trans<br />\n", $ptr->{'interestingnumbers'}{'actions'});
300 if (%{$ptr->{'bignumbers'}})
302 $num = 100 * $ptr->{'bignumbers'}{'questions'} / $ptr->{'lines_total'};
303 $trans = translate ("Question ratio: %.1f%%");
304 printf $fh (" $trans<br />\n", $num);
306 $num = 100 * $ptr->{'bignumbers'}{'uppercase'} / $ptr->{'lines_total'};
307 $trans = translate ("Uppercase ratio: %.1f%%");
308 printf $fh (" $trans<br />\n", $num);
310 $num = 100 * $ptr->{'bignumbers'}{'smiley_happy'} / $ptr->{'lines_total'};
311 $trans = translate ("Happy smiley ratio: %.1f%%");
312 printf $fh (" $trans<br />\n", $num);
314 $num = 100 * $ptr->{'bignumbers'}{'smiley_sad'} / $ptr->{'lines_total'};
315 $trans = translate ("Sad smiley ratio: %.1f%%");
316 printf $fh (" $trans<br />\n", $num);
319 print $fh qq# </td>\n <td>\n#;
321 if (%{$ptr->{'conversations'}})
326 ($ptr->{'conversations'}{$b}{'nicks'}{$nick}[0]
327 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[1]
328 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[2]
329 + $ptr->{'conversations'}{$b}{'nicks'}{$nick}[3])
331 ($ptr->{'conversations'}{$a}{'nicks'}{$nick}[0]
332 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[1]
333 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[2]
334 + $ptr->{'conversations'}{$a}{'nicks'}{$nick}[3])
336 (keys %{$ptr->{'conversations'}});
338 $trans = translate ('Talks to');
341 <table class="conversations">
343 <td colspan="2">$trans:</td>
347 for (my $i = 0; $i < $PLUGIN_MAX and $i < scalar (@others); $i++)
349 my $other = $others[$i];
350 my $other_name = nick_to_name ($other) || $other;
354 qq# <td class="nick right">$other_name</td>\n#,
355 qq# <td class="bar horizontal right">#;
357 for (my $k = 0; $k < 4; $k++)
359 my $img = $H_IMAGES[$k];
360 my $num = $ptr->{'conversations'}{$other}{'nicks'}{$nick}[$k];
361 my $width = sprintf ("%.2f", 95 * $num / $max_conv);
363 print $fh qq#<img src="$img" alt="" #;
366 print $fh qq#class="first" #;
370 print $fh qq#class="last" #;
372 print $fh qq#style="width: $width\%;" />#;
375 print $fh "</td>\n </tr>\n";
378 print $fh " </table>\n";
384 print $fh qq# </td>\n </tr>\n#,
387 if (defined ($ptr->{'chars'}))
389 print $fh qq# <table class="hours">\n <tr class="bars">\n#;
391 for (my $i = 0; $i < 24; $i++)
395 my $img = $V_IMAGES[int ($i / 6)];
398 $num = $ptr->{'chars'}[$i];
400 $height = sprintf ("%.2f", 95 * $num / $max_time);
402 print $fh qq# <td class="bar vertical"><img src="$img" alt="$num chars" #,
403 qq#class="first last" style="height: $height\%;" /></td>\n#;
408 <tr class="numeration">
409 <td colspan="6" class="numeration">0-5</td>
410 <td colspan="6" class="numeration">6-11</td>
411 <td colspan="6" class="numeration">12-17</td>
412 <td colspan="6" class="numeration">18-23</td>
422 print $fh qq# </td>\n <td>\n#;
425 if (%{$nick_data->{$nick}{'weekdays'}})
427 my $data = $nick_data->{$nick}{'weekdays'};
428 my @days = (qw(mon tue wed thu fri sat sun));
430 print $fh qq# <table class="weekdays">\n#,
431 qq# <tr class="bars">\n#;
436 for (my $i = 0; $i < 4; $i++)
438 my $num = $nick_data->{$nick}{'weekdays'}{$day}[$i];
439 my $height = sprintf ("%.2f", 95 * $num / $max_weekday);
441 my $img = $V_IMAGES[$i];
443 print $fh qq# <td class="bar vertical">#,
444 qq#<img src="$img" alt="" class="first last" style="height: $height\%;" />#,
449 print $fh qq# </tr>\n#,
450 qq# <tr class="numeration">\n#;
455 my $trans = translate ($day);
457 print $fh qq# <td colspan="4" class="numeration $day">$trans</td>\n#;
460 print $fh qq# </tr>\n#,
464 print $fh qq# </td>\n <td>\n#;
467 print $fh qq# \n#;
469 print $fh qq# </td>\n </tr>\n#;
472 print $fh "</table>\n\n";