4
0
Эх сурвалжийг харах

Add DailyActivity option.

Morten Brix Pedersen 22 жил өмнө
parent
commit
0b1b9f247e

+ 2 - 0
docs/Changelog

@@ -1,6 +1,8 @@
 pisg (x.xx)
    * Fixed a bug in the irssi format where an action could be recognized as a
      normal line (thanks, Emil Mikulic)
+   * Added a DailyActivity option, which shows the activity in the channel of
+     the last N days. Disabled by default. (thanks, sektor).
 
 pisg (0.50) - Mon Nov, 17th 2003
    * Added NFiles option, which can be used for LogDirs to only parse the last

+ 1 - 0
modules/Pisg.pm

@@ -196,6 +196,7 @@ sub get_default_config_settings
 
         botnicks => '',            # Needed for DCpp format (non-irc)
 
+        dailyactivity => 0,
         version => "0.50",
     };
 

+ 69 - 0
modules/Pisg/HTMLGenerator.pm

@@ -68,6 +68,10 @@ sub create_output
     $self->_pageheader()
         if ($self->{cfg}->{pagehead} ne 'none');
 
+    if ($self->{cfg}->{dailyactivity}) {
+	$self->_activedays();
+    }
+
     if ($self->{cfg}->{showactivetimes}) {
         $self->_activetimes();
     }
@@ -300,6 +304,71 @@ sub _pagefooter
     close(PAGEFOOT);
 }
 
+sub _activedays
+{
+    # The most actives times on the channel
+    my $self = shift;
+    my $days = $self->{stats}->{days};
+    my $ndays = $self->{cfg}->{dailyactivity};
+    my $image;
+    my $time;
+    my $day;
+
+    my (%output, $class);
+
+    my $highest_value = 1;
+    for ($day = $days; $day > $days - $ndays ; $day--) {
+        if (defined($self->{stats}->{day_lines}{$day})) {
+            if ($self->{stats}->{day_lines}{$day} > $highest_value) {
+                $highest_value=$self->{stats}->{day_lines}{$day};
+            }
+        } else {
+            #there are only $days - $day days :)
+            $ndays = $days - $day;
+        }
+    }
+
+    $self->_headline("Daily activity (last $ndays days)");
+
+    _html("<table border=\"0\"><tr>\n");
+
+    for ($day = $days - $ndays +1; $day <= $days ; $day++) {
+        my $lines = $self->{stats}->{day_lines}{$day};
+        _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">$lines<br>");
+        for ($time = 4; $time >= 0; $time--) {
+            if (defined($self->{stats}->{day_times}{$day}[$time])) {
+                my $size = ($self->{stats}->{day_times}{$day}[$time] / $highest_value) * 100;
+
+                if ($size < 1 && $size != 0) {
+                    # Opera doesn't understand '0.xxxx' in the height="xx" attr,
+                    # so we simply round up to 1.0 here.
+
+                    $size = 1.0;
+                }
+
+                $image = "pic_v_".$time*6;
+                $image = $self->{cfg}->{$image};
+                _html("<img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$lines\" /><br>");
+
+            }
+        }
+        _html("</td>\n");
+    }
+
+    _html("</tr><tr>");
+
+    for ($b = $ndays-1; $b >= 0 ; $b--) {
+            $class = 'rankc10center';
+        _html("<td class=\"$class\" align=\"center\">$b</td>");
+}
+
+    _html("</tr></table>");
+
+    if($self->{cfg}->{showlegend} == 1) {
+        $self->_legend();
+    }
+}
+
 sub _activetimes
 {
     # The most actives times on the channel

+ 32 - 3
modules/Pisg/Parser/Logfile.pm

@@ -260,7 +260,14 @@ sub _parse_file
                 checkname($hashref->{nick}, $nick, $stats) if ($self->{cfg}->{showmostnicks});
                 $saying = $hashref->{saying};
 
-                if ($hour < $state->{oldtime}) { $stats->{days}++ }
+                if ($hour < $state->{oldtime}) {
+                    $stats->{days}++;
+                    $stats->{day_times}{$stats->{days}}[0] = 0;
+                    $stats->{day_times}{$stats->{days}}[1] = 0;
+                    $stats->{day_times}{$stats->{days}}[2] = 0;
+                    $stats->{day_times}{$stats->{days}}[3] = 0;
+                    $stats->{day_lines}{$stats->{days}} = 0;
+                }
                 $state->{oldtime} = $hour;
 
                 if (!is_ignored($nick)) {
@@ -268,6 +275,8 @@ sub _parse_file
 
                     # Timestamp collecting
                     $stats->{times}{$hour}++;
+                    $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
+                    $stats->{day_lines}{$stats->{days}}++;
 
                     $stats->{lines}{$nick}++;
                     $stats->{lastvisited}{$nick} = $stats->{days};
@@ -355,12 +364,22 @@ sub _parse_file
             checkname($hashref->{nick}, $nick, $stats) if ($self->{cfg}->{showmostnicks});
             $saying = $hashref->{saying};
 
-            if ($hour < $state->{oldtime}) { $stats->{days}++ }
+            if ($hour < $state->{oldtime}) {
+                $stats->{days}++;
+                $stats->{day_times}{$stats->{days}}[0] = 0;
+                $stats->{day_times}{$stats->{days}}[1] = 0;
+                $stats->{day_times}{$stats->{days}}[2] = 0;
+                $stats->{day_times}{$stats->{days}}[3] = 0;
+                $stats->{day_lines}{$stats->{days}} = 0;
+            }
+
             $state->{oldtime} = $hour;
 
             if (!is_ignored($nick)) {
                 # Timestamp collecting
                 $stats->{times}{$hour}++;
+                $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
+                $stats->{day_lines}{$stats->{days}}++;
 
                 $stats->{actions}{$nick}++;
                 push @{ $lines->{actionlines}{$nick} }, $line;
@@ -411,12 +430,22 @@ sub _parse_file
             $newjoin  = $hashref->{newjoin};
             $newnick  = $hashref->{newnick};
 
-            if ($hour < $state->{oldtime}) { $stats->{days}++ }
+            if ($hour < $state->{oldtime}) {
+                $stats->{days}++;
+                $stats->{day_times}{$stats->{days}}[0]=0;
+                $stats->{day_times}{$stats->{days}}[1]=0;
+                $stats->{day_times}{$stats->{days}}[2]=0;
+                $stats->{day_times}{$stats->{days}}[3]=0;
+                $stats->{day_lines}{$stats->{days}}=0;
+            }
+
             $state->{oldtime} = $hour;
 
             if (!is_ignored($nick)) {
                 # Timestamp collecting
                 $stats->{times}{$hour}++;
+                $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
+                $stats->{day_lines}{$stats->{days}}++;
 
                 $stats->{lastvisited}{$nick} = $stats->{days};