From 62f15b5973529d4a3144dfc3db7b253a4920d221 Mon Sep 17 00:00:00 2001 From: octo Date: Thu, 14 Apr 2005 13:25:21 +0000 Subject: [PATCH] The Weeksdays plugin has been tested and works as wanted. Wee :) --- lib/Onis/Plugins/Weekdays.pm | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/Onis/Plugins/Weekdays.pm b/lib/Onis/Plugins/Weekdays.pm index 436e2e1..788c83e 100644 --- a/lib/Onis/Plugins/Weekdays.pm +++ b/lib/Onis/Plugins/Weekdays.pm @@ -55,11 +55,13 @@ sub add my $day = (localtime ($time))[6]; my $index = ($day * 4) + $hour; - my @data = $WeekdayCache->get ($nick) || (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 0 0 0 0)); + my @data = $WeekdayCache->get ($nick); + @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 0 0 0 0)) unless (@data); $data[$index] += $chars; $WeekdayCache->put ($nick, @data); - @data = $WeekdayCache->get ('') || (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 0 0 0 0)); + @data = $WeekdayCache->get (''); + @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 0 0 0 0)) unless (@data); $data[$index] += $chars; $WeekdayCache->put ('', @data); } @@ -119,6 +121,7 @@ sub output my $fh = get_filehandle (); my $max = 0; + my $total = 0; my $bar_factor = 0; for (@order) @@ -126,6 +129,7 @@ sub output my ($num, $abbr, $name) = @$_; my $sum = $data->{$abbr}[0] + $data->{$abbr}[1] + $data->{$abbr}[2] + $data->{$abbr}[3]; + $total += $sum; $max = $sum if ($max < $sum); } @@ -135,18 +139,28 @@ sub output for (@order) { my ($num, $abbr, $name) = @$_; - my $sum = $data->{$abbr}[0] + $data->{$abbr}[1] + $data->{$abbr}[2] + $data->{$abbr}[3]; - - print $fh qq# $sum
\n #; - for (my $i = 0; $i < 4; $i++) + print $fh qq# #; + for (my $i = 3; $i >= 0; $i--) { my $num = $data->{$abbr}[$i]; - my $height = int (0.5 + $num * $bar_factor) || 1; + my $height = sprintf ("%.2f", (95 * $num / $max)); my $img = $VImages[$i]; - - print $fh qq(); + my $class = ''; + + $class = q( class="first") if ($i == 3); + $class = q( class="last") if ($i == 0); + + print $fh qq(); } - print $fh "\n \n"; + print $fh "\n"; + } + print $fh qq( \n \n); + for (@order) + { + my ($num, $abbr, $name) = @$_; + my $sum = $data->{$abbr}[0] + $data->{$abbr}[1] + $data->{$abbr}[2] + $data->{$abbr}[3]; + my $pct = sprintf ("%.1f", (100 * $sum / $total)); + print $fh qq( $pct%\n); } print $fh qq( \n \n); for (@order) -- 2.11.0