From: octo Date: Fri, 15 Apr 2005 22:11:23 +0000 (+0000) Subject: Completed the Longterm Plugin. It seems to drain performance quite a bit though.... X-Git-Tag: Release-0.8.0~17 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=942b56647efea6b2c0a7f1da4772ceca3ac5ef83;p=onis.git Completed the Longterm Plugin. It seems to drain performance quite a bit though. Maybe some benchmarking can target this..? Added var directory. Didn't get merged from trunk or something.. Added ``get_most_recent_time'' to Data::Core --- diff --git a/config b/config index 9e2f00f..4f275ce 100644 --- a/config +++ b/config @@ -41,6 +41,7 @@ overwrite: "false"; # Load these plugins. These are all available plugins as of now, but this # is a development release. The missing one(s) will be back.. plugin: "Weekdays"; +plugin: "Longterm"; plugin: "Conversations"; plugin: "BigNumbers"; plugin: "Words"; diff --git a/lib/Onis/Data/Core.pm b/lib/Onis/Data/Core.pm index 701e086..0eb9230 100644 --- a/lib/Onis/Data/Core.pm +++ b/lib/Onis/Data/Core.pm @@ -44,7 +44,7 @@ qw( store unsharp calculate_nicks get_all_nicks get_channel get_main_nick nick_to_ident ident_to_nick nick_to_name - get_total_lines nick_rename print_output register_plugin + get_total_lines get_most_recent_time nick_rename print_output register_plugin ); @Onis::Data::Core::ISA = ('Exporter'); @@ -199,6 +199,11 @@ sub store $counter++; $GeneralCounters->put ('lines_total', $counter); + my ($time) = $GeneralCounters->get ('most_recent_time'); + $time ||= 0; + $time = $data->{'epoch'} if ($time < $data->{'epoch'}); + $GeneralCounters->put ('most_recent_time', $time); + $LinesThisRun++; } @@ -645,6 +650,20 @@ sub get_total_lines return ($total, $LinesThisRun); } +=item I<$epoch> = B () + +Returns the epoch of the most recent line received from the parser. + +=cut + +sub get_most_recent_time +{ + my ($time) = $GeneralCounters->get ('most_recent_time'); + $time ||= 0; + + return ($time); +} + =item B (I<$old_nick>, I<$new_nick>) Keeps track of a nick's hostname if the nick changes. diff --git a/lib/Onis/Plugins/Longterm.pm b/lib/Onis/Plugins/Longterm.pm index 0ca0f6b..9e92c8b 100644 --- a/lib/Onis/Plugins/Longterm.pm +++ b/lib/Onis/Plugins/Longterm.pm @@ -1,4 +1,4 @@ -package Onis::Plugins::Weekdays; +package Onis::Plugins::Longterm; use strict; use warnings; @@ -6,7 +6,7 @@ use warnings; 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 nick_to_name)); +use Onis::Data::Core (qw(register_plugin get_main_nick get_most_recent_time nick_to_ident nick_to_name)); use Onis::Data::Persistent (); register_plugin ('TEXT', \&add); @@ -15,6 +15,7 @@ register_plugin ('OUTPUT', \&output); our $LongtermLastSeen = Onis::Data::Persistent->new ('LongtermLastSeen', 'nick', 'day'); our $LongtermCache = Onis::Data::Persistent->new ('LongtermCache', 'key', qw(time0 time1 time2 time3)); +our $LongtermData = {}; =head1 CONFIGURATION OPTIONS @@ -89,102 +90,115 @@ sub add sub calculate { - for ($WeekdayCache->keys ()) + my $now_epoch = get_most_recent_time (); + my $now = int ($now_epoch / 86400); + return unless ($now); + + my $old = 1 + $now - $DisplayDays; + + my $del = {}; + + for ($LongtermLastSeen->keys ()) { my $nick = $_; - my $main = $nick eq '' ? '' : get_main_nick ($nick); - my @data = $WeekdayCache->get ($nick); + my ($last) = $LongtermLastSeen->get ($nick); + + if ($last < $old) + { + $del->{$nick} = $last; + $LongtermLastSeen->del ($nick); + } + } + + for ($LongtermCache->keys ()) + { + my $key = $_; + my ($nick, $day) = split (m/:/, $key); - if (!defined ($WeekdayData->{$main})) + if (defined ($del->{$nick}) or ($day < $old)) { - $WeekdayData->{$main} = - { - sun => [0, 0, 0, 0], - mon => [0, 0, 0, 0], - tue => [0, 0, 0, 0], - wed => [0, 0, 0, 0], - thu => [0, 0, 0, 0], - fri => [0, 0, 0, 0], - sat => [0, 0, 0, 0] - }; + $LongtermCache->del ($key); + next; } - for (my $i = 0; $i < 7; $i++) + my $idx = $day - $old; + my $main = get_main_nick ($nick); + my @data = $LongtermCache->get ($key); + + if (!defined ($LongtermData->{$main})) { - my $day = $Weekdays[$i]; - for (my $j = 0; $j < 4; $j++) - { - my $idx = ($i * 4) + $j; - $WeekdayData->{$main}{$day}[$j] += $data[$idx]; - } + $LongtermData->{$main} = []; + $LongtermData->{$main}[$_] = [0, 0, 0, 0] for (0 .. ($DisplayDays - 1)); } + if (!defined ($LongtermData->{''})) + { + $LongtermData->{''} = []; + $LongtermData->{''}[$_] = [0, 0, 0, 0] for (0 .. ($DisplayDays - 1)); + } + + $LongtermData->{$main}[$idx][$_] += $data[$_] for (0 .. 3); + $LongtermData->{''}[$idx][$_] += $data[$_] for (0 .. 3); } } sub output { calculate (); - return (undef) unless (%$WeekdayData); + return (undef) unless (%$LongtermData); + + my $now_epoch = get_most_recent_time (); + my $now = int ($now_epoch / 86400); + return unless ($now); - my @order = - ( - [1, 'mon', 'Monday'], - [2, 'tue', 'Tuesday'], - [3, 'wed', 'Wednesday'], - [4, 'thu', 'Thursday'], - [5, 'fri', 'Friday'], - [6, 'sat', 'Saturday'], - [0, 'sun', 'Sunday'] - ); + my $old = 1 + $now - $DisplayDays; - my $data = $WeekdayData->{''}; + my $data = $LongtermData->{''}; + + my @weekdays = (qw(sun mon tue wed thu fri sat sun)); my $fh = get_filehandle (); my $max = 0; my $total = 0; - my $bar_factor = 0; - for (@order) + for (my $i = 0; $i < $DisplayDays; $i++) { - my ($num, $abbr, $name) = @$_; - - for (my $i = 0; $i < 4; $i++) + for (my $j = 0; $j < 4; $j++) { - $max = $data->{$abbr}[$i] if ($max < $data->{$abbr}[$i]); - $total += $data->{$abbr}[$i]; + $max = $data->[$i][$j] if ($max < $data->[$i][$j]); + $total += $data->[$i][$j]; } } - $bar_factor = $BarHeight / $max; - - print $fh qq#\n \n#; - for (@order) + print $fh qq#
\n \n#; + for (my $i = 0; $i < $DisplayDays; $i++) { - my ($num, $abbr, $name) = @$_; - for (my $i = 0; $i < 4; $i++) + for (my $j = 0; $j < 4; $j++) { - my $num = $data->{$abbr}[$i]; + my $num = $data->[$i][$j]; my $height = sprintf ("%.2f", (95 * $num / $max)); - my $img = $VImages[$i]; + my $img = $VImages[$j]; - print $fh qq# \n); } } print $fh qq( \n \n); - for (@order) + for (my $i = 0; $i < $DisplayDays; $i++) { - 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( \n); + my $sum = $data->[$i][0] + $data->[$i][1] + $data->[$i][2] + $data->[$i][3]; + my $percent = sprintf ("%.1f", 100 * $sum / $total); + + print $fh qq( \n); } print $fh qq( \n \n); - for (@order) + for (my $i = 0; $i < $DisplayDays; $i++) { - my ($num, $abbr, $name) = @$_; - print $fh qq( \n); + my $epoch = ($old + $i) * 86400; + my ($day, $wd) = (localtime ($epoch))[3,6]; + my $class = $weekdays[$wd]; + + print $fh qq( \n); } print $fh " \n
#, + print $fh qq# #, qq(
$pct%$percent%
$name$day.
\n\n"; } diff --git a/onis b/onis index c34fc74..b0d1bdc 100755 --- a/onis +++ b/onis @@ -71,6 +71,7 @@ foreach ('Core', get_config ('plugin')) if (!get_config ('input')) { + # TODO: Make a complete (!) lsit.. print STDERR < [logfile logfile ..] diff --git a/reports/light-theme/style.css b/reports/light-theme/style.css index aaf08fc..aae0209 100644 --- a/reports/light-theme/style.css +++ b/reports/light-theme/style.css @@ -174,6 +174,22 @@ table.legend td width: 125px; } +table.longterm tr.bars +{ + height: 100px; +} + +table.longterm tr.bars td +{ + color: black; + background-color: transparent; +} + +table.longterm tr.bars td img +{ + width: 3px; +} + table.plugin { width: 500px; @@ -333,6 +349,12 @@ td.numeration background-color: silver; } +td.numeration.sun, +td.numeration.sat +{ + color: maroon; +} + td.invis { background-color: transparent;