Completed the Longterm Plugin. It seems to drain performance quite a bit though....
authorocto <octo>
Fri, 15 Apr 2005 22:11:23 +0000 (22:11 +0000)
committerocto <octo>
Fri, 15 Apr 2005 22:11:23 +0000 (22:11 +0000)
Added var directory. Didn't get merged from trunk or something..
Added ``get_most_recent_time'' to Data::Core

config
lib/Onis/Data/Core.pm
lib/Onis/Plugins/Longterm.pm
onis
reports/light-theme/style.css

diff --git a/config b/config
index 9e2f00f..4f275ce 100644 (file)
--- 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";
 # 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";
 plugin: "Conversations";
 plugin: "BigNumbers";
 plugin: "Words";
index 701e086..0eb9230 100644 (file)
@@ -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
        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');
 
 );
 @Onis::Data::Core::ISA = ('Exporter');
 
@@ -199,6 +199,11 @@ sub store
                $counter++;
                $GeneralCounters->put ('lines_total', $counter);
 
                $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++;
        }
 
                $LinesThisRun++;
        }
 
@@ -645,6 +650,20 @@ sub get_total_lines
        return ($total, $LinesThisRun);
 }
 
        return ($total, $LinesThisRun);
 }
 
+=item I<$epoch> = B<get_most_recent_time> ()
+
+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<nick_rename> (I<$old_nick>, I<$new_nick>)
 
 Keeps track of a nick's hostname if the nick changes.
 =item B<nick_rename> (I<$old_nick>, I<$new_nick>)
 
 Keeps track of a nick's hostname if the nick changes.
index 0ca0f6b..9e92c8b 100644 (file)
@@ -1,4 +1,4 @@
-package Onis::Plugins::Weekdays;
+package Onis::Plugins::Longterm;
 
 use strict;
 use warnings;
 
 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::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);
 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 $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
 
 
 =head1 CONFIGURATION OPTIONS
 
@@ -89,102 +90,115 @@ sub add
 
 sub calculate
 {
 
 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 $nick = $_;
-               my $main = $nick eq '<TOTAL>' ? '<TOTAL>' : 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->{'<TOTAL>'}))
+               {
+                       $LongtermData->{'<TOTAL>'} = [];
+                       $LongtermData->{'<TOTAL>'}[$_] = [0, 0, 0, 0] for (0 .. ($DisplayDays - 1));
+               }
+
+               $LongtermData->{$main}[$idx][$_] += $data[$_] for (0 .. 3);
+               $LongtermData->{'<TOTAL>'}[$idx][$_] += $data[$_] for (0 .. 3);
        }
 }
 
 sub output
 {
        calculate ();
        }
 }
 
 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->{'<TOTAL>'};
+       my $data = $LongtermData->{'<TOTAL>'};
+
+       my @weekdays = (qw(sun mon tue wed thu fri sat sun));
 
        my $fh = get_filehandle ();
        
        my $max = 0;
        my $total = 0;
 
        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#<table class="plugin weekdays">\n  <tr class="bars">\n#;
-       for (@order)
+       print $fh qq#<table class="plugin longterm">\n  <tr class="bars">\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 $height = sprintf ("%.2f", (95 * $num / $max));
-                       my $img = $VImages[$i];
+                       my $img = $VImages[$j];
 
 
-                       print $fh qq#    <td class="bar vertical $abbr">#,
+                       print $fh qq#    <td class="bar vertical">#,
                        qq(<img src="$img" alt="" class="first last" style="height: ${height}%;" /></td>\n);
                }
        }
        print $fh qq(  </tr>\n  <tr class="counter">\n);
                        qq(<img src="$img" alt="" class="first last" style="height: ${height}%;" /></td>\n);
                }
        }
        print $fh qq(  </tr>\n  <tr class="counter">\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(    <td colspan="4" class="counter $abbr">$pct%</td>\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(    <td colspan="4" class="counter">$percent%</td>\n);
        }
        print $fh qq(  </tr>\n  <tr class="numeration">\n);
        }
        print $fh qq(  </tr>\n  <tr class="numeration">\n);
-       for (@order)
+       for (my $i = 0; $i < $DisplayDays; $i++)
        {
        {
-               my ($num, $abbr, $name) = @$_;
-               print $fh qq(    <td colspan="4" class="numeration $abbr">$name</td>\n);
+               my $epoch = ($old + $i) * 86400;
+               my ($day, $wd) = (localtime ($epoch))[3,6];
+               my $class = $weekdays[$wd];
+               
+               print $fh qq(    <td colspan="4" class="numeration $class">$day.</td>\n);
        }
        print $fh "  </tr>\n</table>\n\n";
 }
        }
        print $fh "  </tr>\n</table>\n\n";
 }
diff --git a/onis b/onis
index c34fc74..b0d1bdc 100755 (executable)
--- a/onis
+++ b/onis
@@ -71,6 +71,7 @@ foreach ('Core', get_config ('plugin'))
 
 if (!get_config ('input'))
 {
 
 if (!get_config ('input'))
 {
+       # TODO: Make a complete (!) lsit..
        print STDERR <<EOF;
 
 Usage: $0 [options] <logfile> [logfile logfile ..]
        print STDERR <<EOF;
 
 Usage: $0 [options] <logfile> [logfile logfile ..]
index aaf08fc..aae0209 100644 (file)
@@ -174,6 +174,22 @@ table.legend td
        width: 125px;
 }
 
        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;
 table.plugin
 {
        width: 500px;
@@ -333,6 +349,12 @@ td.numeration
        background-color: silver;
 }
 
        background-color: silver;
 }
 
+td.numeration.sun,
+td.numeration.sat
+{
+       color: maroon;
+}
+
 td.invis
 {
        background-color: transparent;
 td.invis
 {
        background-color: transparent;