Преглед на файлове

Apply (and heavily sanitize) patch by Igge for "Most active genders" stats (enable with ShowActiveGenders="1").

Christoph Berg преди 21 години
родител
ревизия
0765b3ad80
променени са 6 файла, в които са добавени 116 реда и са изтрити 8 реда
  1. 2 0
      docs/Changelog
  2. 38 1
      docs/pisg-doc.xml
  3. 10 0
      lang.txt
  4. 3 2
      modules/Pisg.pm
  5. 52 0
      modules/Pisg/HTMLGenerator.pm
  6. 11 5
      modules/Pisg/Parser/Logfile.pm

+ 2 - 0
docs/Changelog

@@ -16,6 +16,8 @@ pisg (0.63) - ??
      Pinski).
      Pinski).
    * irssi.pm: Recognize joins even when autorealname.pl is loaded.
    * irssi.pm: Recognize joins even when autorealname.pl is loaded.
    * Hint user to use a log with timestamps when no parseable lines are found.
    * Hint user to use a log with timestamps when no parseable lines are found.
+   * Apply (and heavily sanitize) patch by Igge for "Most active genders"
+     stats (enable with ShowActiveGenders="1").
 
 
 pisg (0.62) - Sat Dec, 11th 2004
 pisg (0.62) - Sat Dec, 11th 2004
    Changes by Christoph Berg:
    Changes by Christoph Berg:

+ 38 - 1
docs/pisg-doc.xml

@@ -163,7 +163,8 @@
     <![CDATA[<user nick="Ben" pic="ben_*.jpg">]]>
     <![CDATA[<user nick="Ben" pic="ben_*.jpg">]]>
     </programlisting>
     </programlisting>
 
 
-    You can also set a user's sex:
+    You can also set a user's sex.
+    The sex setting can be "f"emale, "m"ale, or "b"ot:
     <programlisting>
     <programlisting>
     <![CDATA[<user nick="Ben" sex="m">]]>
     <![CDATA[<user nick="Ben" sex="m">]]>
     </programlisting>
     </programlisting>
@@ -1962,6 +1963,42 @@
     </refsect1>
     </refsect1>
     </refentry>
     </refentry>
 
 
+    <!-- *** SHOWACTIVEGENDERS *** -->
+    <refentry id="ShowActiveGenders">
+
+    <refmeta> <refentrytitle>ShowActiveGenders</refentrytitle> </refmeta>
+
+    <refnamediv>
+    <refname>ShowActiveGenders</refname>
+    <refpurpose>show stats on which gender talked most</refpurpose>
+    </refnamediv>
+
+    <refsynopsisdiv><programlisting>
+      <![CDATA[
+        <channel="#channel">
+         Logfile = "channel.log"
+         Format = "xchat"
+         ShowActiveGenders = "0"
+        </channel>
+
+        <set ShowActiveGenders="1">
+      ]]>
+    </programlisting></refsynopsisdiv>
+
+    <refsect1>
+    <title>Description</title>
+    <para>
+    Setting this option will make pisg create statistics on which gender
+    (female/male/bot) talked most (see the "sex" option in <xref
+    linkend="user-options" />).
+    </para>
+    </refsect1>
+    <refsect1>
+    <title>Default</title>
+    <para> 0 (disabled) </para>
+    </refsect1>
+    </refentry>
+
     <!-- *** SHOWMOSTACTIVEBYHOUR *** -->
     <!-- *** SHOWMOSTACTIVEBYHOUR *** -->
     <refentry id="ShowMostActiveByHour">
     <refentry id="ShowMostActiveByHour">
 
 

+ 10 - 0
lang.txt

@@ -147,6 +147,7 @@ notopic = "A topic was never set on this channel."
 mostnickstopic = "Users with most nicknames"
 mostnickstopic = "Users with most nicknames"
 bylinetopic = "by [:nick] on [:time]"
 bylinetopic = "by [:nick] on [:time]"
 dailyactivitytopic = "Daily activity (last [:n] days)"
 dailyactivitytopic = "Daily activity (last [:n] days)"
+activegenderstopic = "Most active gender"
 
 
 ## Other text
 ## Other text
 
 
@@ -183,6 +184,10 @@ seconds = "seconds"
 and = "and"
 and = "and"
 names1 = "names"
 names1 = "names"
 names2 = "name"
 names2 = "name"
+gender = "Gender"
+gender_f = "Female"
+gender_m = "Male"
+gender_b = "Bot"
 
 
 # Mouse-over titles
 # Mouse-over titles
 pisghomepage = "Go to the pisg homepage"
 pisghomepage = "Go to the pisg homepage"
@@ -302,6 +307,7 @@ notopic = "In diesem Channel wurde kein Topic gesetzt."
 bylinetopic = "von [:nick] um [:time]"
 bylinetopic = "von [:nick] um [:time]"
 dailyactivitytopic = "Tägliche Aktivität (letzte [:n] Tage)"
 dailyactivitytopic = "Tägliche Aktivität (letzte [:n] Tage)"
 mostnickstopic = "Chatter mit den meisten Nicks"
 mostnickstopic = "Chatter mit den meisten Nicks"
+activegenderstopic = "Aktivste Geschlechter"
 
 
 ## Other text
 ## Other text
 
 
@@ -338,6 +344,10 @@ seconds = "Sekunden"
 and = "und"
 and = "und"
 names1 = "Nicks"
 names1 = "Nicks"
 names2 = "Nick"
 names2 = "Nick"
+gender = "Geschlecht"
+gender_f = "Weiblich"
+gender_m = "Männlich"
+gender_b = "Bot"
 
 
 # Mouse-over titles
 # Mouse-over titles
 pisghomepage = "pisg-Homepage öffnen"
 pisghomepage = "pisg-Homepage öffnen"

+ 3 - 2
modules/Pisg.pm

@@ -158,6 +158,7 @@ sub get_default_config_settings
         showvoices => 0,
         showvoices => 0,
         showhalfops => 0,
         showhalfops => 0,
         showmostnicks => 0,
         showmostnicks => 0,
+        showactivegenders => 0,
         showmostactivebyhour => 0,
         showmostactivebyhour => 0,
         showmostactivebyhourgraph => 0,
         showmostactivebyhourgraph => 0,
         showonlytop => 0,
         showonlytop => 0,
@@ -296,7 +297,7 @@ sub init_config
                 add_ignore($nick);
                 add_ignore($nick);
             }
             }
 
 
-            if ($line =~ /sex=(["'])([MmFf])\1/) {
+            if ($line =~ /sex=(["'])([MmFfBb])\1/) {
                 $self->{users}->{sex}{$nick} = lc($2);
                 $self->{users}->{sex}{$nick} = lc($2);
             }
             }
         } elsif ($line =~ /<link(.*)>/) {
         } elsif ($line =~ /<link(.*)>/) {
@@ -449,7 +450,7 @@ sub do_channel
         eval <<_END;
         eval <<_END;
 use Pisg::Parser::$self->{cfg}->{logtype};
 use Pisg::Parser::$self->{cfg}->{logtype};
 \$analyzer = new Pisg::Parser::$self->{cfg}->{logtype}(
 \$analyzer = new Pisg::Parser::$self->{cfg}->{logtype}(
-    cfg => \$self->{cfg}
+    { cfg => \$self->{cfg}, users => \$self->{users} }
 );
 );
 _END
 _END
         if ($@) {
         if ($@) {

+ 52 - 0
modules/Pisg/HTMLGenerator.pm

@@ -129,6 +129,10 @@ sub create_output
         $self->_mostnicks();
         $self->_mostnicks();
     }
     }
 
 
+    if ($self->{cfg}->{showactivegenders}) {
+        $self->_activegenders();
+    }
+
     if ($self->{cfg}->{showmuw}) {
     if ($self->{cfg}->{showmuw}) {
         $self->_mostusedword();
         $self->_mostusedword();
     }
     }
@@ -2198,6 +2202,54 @@ sub _istoponly {
     }
     }
 }
 }
 
 
+sub _activegenders {
+    # The most active gender in the channel
+    my $self = shift;
+    my @topgender = sort {$self->{stats}->{sex_lines}{$b} <=> $self->{stats}->{sex_lines}{$a}} keys %{$self->{stats}->{sex_lines}};
+
+    return unless @topgender;
+
+    $self->_headline($self->_template_text('activegenderstopic'));
+    _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
+    _html(" <td>&nbsp;</td>"
+    . "<td class=\"tdtop\"><b>" . $self->_template_text('gender') . "</b></td>"
+    . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
+    . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
+    );
+
+    my $i = 1;
+    for my $gender (@topgender) {
+        my $bar = "";
+        my $len = ($self->{stats}->{sex_lines}{$gender} / $self->{stats}->{sex_lines}{$topgender[0]}) * 100;
+
+        for (0 .. 3) {
+            next if not defined $self->{stats}->{sex_line_times}{$gender}[$_];
+            my $w = int(($self->{stats}->{sex_line_times}{$gender}[$_] / $self->{stats}->{sex_lines}{$gender}) * $len);
+            if ($w) {
+                my $pic = 'pic_h_'.(6*$_);
+                $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"$self->{stats}->{sex_line_times}{$gender}[$_]\" />";
+            }
+        }
+
+        my @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
+            grep { $self->{users}->{sex}{$_} and $self->{users}->{sex}{$_} eq $gender }
+            keys %{ $self->{stats}->{lines} };
+        splice @top_active, 20 if @top_active > 20;
+        my $nicklist = join ", ", map { "$_ ($self->{stats}->{lines}{$_})" } @top_active;
+
+        my $class = ($i == 1 ? "hirankc" : "rankc");
+        my $span_class = $gender eq 'm' ? "male" : ($gender eq 'f' ? "female" : "bot");
+        _html("</tr><tr>");
+        _html(" <td class=\"$class\" align=\"left\">$i</td>");
+        _html(" <td class=\"hicell\"><span class=\"$span_class\">" . $self->_template_text("gender_$gender") . "</span></td>");
+        _html(" <td class=\"hicell\"><span style=\"white-space:nowrap;\">$bar</span> $self->{stats}->{sex_lines}{$gender}</td>");
+        _html(" <td class=\"hicell\">$nicklist</td>");
+        $i++;
+    }
+
+    _html("</tr></table><br />");
+}
+
 1;
 1;
 
 
 __END__
 __END__

+ 11 - 5
modules/Pisg/Parser/Logfile.pm

@@ -14,11 +14,7 @@ $have_iconv = 0 if $@;
 sub new
 sub new
 {
 {
     my $type = shift;
     my $type = shift;
-    my %args = @_;
-    my $self = {
-        cfg => $args{cfg},
-        parser => undef
-    };
+    my $self = shift; # get cfg and users
 
 
     # Import common functions in Pisg::Common
     # Import common functions in Pisg::Common
     require Pisg::Common;
     require Pisg::Common;
@@ -396,6 +392,11 @@ sub _parse_file
                         }
                         }
                     }
                     }
 
 
+                    if (my $s = $self->{users}->{sex}{$nick}) {
+                        $stats->{sex_lines}{$s}++;
+                        $stats->{sex_line_times}{$s}[int($hour/6)]++;
+                    }
+
                     _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
                     _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
                 }
                 }
             }
             }
@@ -458,6 +459,11 @@ sub _parse_file
 
 
                 $stats->{lengths}{$nick} += length($saying);
                 $stats->{lengths}{$nick} += length($saying);
 
 
+                if (my $s = $self->{users}->{sex}{$nick}) {
+                    $stats->{sex_lines}{$s}++;
+                    $stats->{sex_line_times}{$s}[int($hour/6)]++;
+                }
+
                 _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
                 _parse_words($stats, $saying, $nick, $self->{ignorewords_regexp}, $hour);
             }
             }
         }
         }