Преглед изворни кода

No need to pass $self->{stats} as a argument to HTML functions, it already
exists in the object, this should improve performance a bit.

Morten Brix Pedersen пре 25 година
родитељ
комит
ca91e88508
1 измењених фајлова са 146 додато и 171 уклоњено
  1. 146 171
      modules/Pisg/HTMLGenerator.pm

+ 146 - 171
modules/Pisg/HTMLGenerator.pm

@@ -54,56 +54,56 @@ sub create_html
         $self->{cfg}->{tablewidth} += 40;
         $self->{cfg}->{tablewidth} += 40;
     }
     }
     $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
     $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
-    $self->_htmlheader($self->{stats});
-    $self->_pageheader($self->{stats});
-    $self->_activetimes($self->{stats});
-    $self->_activenicks($self->{stats});
+    $self->_htmlheader();
+    $self->_pageheader();
+    $self->_activetimes();
+    $self->_activenicks();
 
 
     $self->_headline($self->_template_text('bignumtopic'));
     $self->_headline($self->_template_text('bignumtopic'));
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
-    $self->_questions($self->{stats});
-    $self->_shoutpeople($self->{stats});
-    $self->_capspeople($self->{stats});
-    $self->_violent($self->{stats});
-    $self->_mostsmiles($self->{stats});
-    $self->_mostsad($self->{stats});
-    $self->_linelengths($self->{stats});
-    $self->_mostwords($self->{stats});
-    $self->_mostwordsperline($self->{stats});
+    $self->_questions();
+    $self->_shoutpeople();
+    $self->_capspeople();
+    $self->_violent();
+    $self->_mostsmiles();
+    $self->_mostsad();
+    $self->_linelengths();
+    $self->_mostwords();
+    $self->_mostwordsperline();
     _html("</table>"); # Needed for sections
     _html("</table>"); # Needed for sections
 
 
     if ($self->{cfg}->{show_muw}) {
     if ($self->{cfg}->{show_muw}) {
-        $self->_mostusedword($self->{stats});
+        $self->_mostusedword();
     }
     }
 
 
     if ($self->{cfg}->{show_mrn}) {
     if ($self->{cfg}->{show_mrn}) {
-        $self->_mostreferencednicks($self->{stats});
+        $self->_mostreferencednicks();
     }
     }
 
 
     if ($self->{cfg}->{show_mru}) {
     if ($self->{cfg}->{show_mru}) {
-        $self->_mosturls($self->{stats});
+        $self->_mosturls();
     }
     }
 
 
     $self->_headline($self->_template_text('othernumtopic'));
     $self->_headline($self->_template_text('othernumtopic'));
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
-    $self->_gotkicks($self->{stats});
-    $self->_mostkicks($self->{stats});
-    $self->_mostop($self->{stats});
-    $self->_mostactions($self->{stats});
-    $self->_mostmonologues($self->{stats});
-    $self->_mostjoins($self->{stats});
-    $self->_mostfoul($self->{stats});
+    $self->_gotkicks();
+    $self->_mostkicks();
+    $self->_mostop();
+    $self->_mostactions();
+    $self->_mostmonologues();
+    $self->_mostjoins();
+    $self->_mostfoul();
     _html("</table>"); # Needed for sections
     _html("</table>"); # Needed for sections
 
 
     $self->_headline($self->_template_text('latesttopic'));
     $self->_headline($self->_template_text('latesttopic'));
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
     _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
-    $self->_lasttopics($self->{stats});
+    $self->_lasttopics();
     _html("</table>"); # Needed for sections
     _html("</table>"); # Needed for sections
 
 
     my %hash = ( lines => $self->{stats}->{totallines} );
     my %hash = ( lines => $self->{stats}->{totallines} );
     _html($self->_template_text('totallines', %hash) . "<br><br>");
     _html($self->_template_text('totallines', %hash) . "<br><br>");
 
 
-    $self->_htmlfooter($self->{stats});
+    $self->_htmlfooter();
 
 
     close(OUTPUT);
     close(OUTPUT);
 }
 }
@@ -111,7 +111,6 @@ sub create_html
 sub _htmlheader
 sub _htmlheader
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
     my $bgpic = "";
     my $bgpic = "";
     if ($self->{cfg}->{bgpic}) {
     if ($self->{cfg}->{bgpic}) {
         $bgpic = " background=\"$self->{cfg}->{bgpic}\"";
         $bgpic = " background=\"$self->{cfg}->{bgpic}\"";
@@ -160,8 +159,8 @@ HTML
 my %hash = (
 my %hash = (
     network    => $self->{cfg}->{network},
     network    => $self->{cfg}->{network},
     maintainer => $self->{cfg}->{maintainer},
     maintainer => $self->{cfg}->{maintainer},
-    days       => $stats->{days},
-    nicks      => scalar keys %{ $stats->{lines} }
+    days       => $self->{stats}->{days},
+    nicks      => scalar keys %{ $self->{stats}->{lines} }
 );
 );
 print OUTPUT "<span class=\"title\">" . $self->_template_text('pagetitle1', %hash) . "</span><br>";
 print OUTPUT "<span class=\"title\">" . $self->_template_text('pagetitle1', %hash) . "</span><br>";
 print OUTPUT "<br>";
 print OUTPUT "<br>";
@@ -214,12 +213,11 @@ print OUTPUT "<br>" . $self->_template_text('pagetitle3', %hash) . "<br><br>";
 sub _htmlfooter
 sub _htmlfooter
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
     print OUTPUT <<HTML;
     print OUTPUT <<HTML;
 <span class="small">
 <span class="small">
 Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $self->{cfg}->{version}<br>
 Stats generated by <a href="http://pisg.sourceforge.net/" title="Go to the pisg homepage">pisg</a> $self->{cfg}->{version}<br>
 pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten Brix Pedersen</a> and others<br>
 pisg by <a href="http://www.wtf.dk/hp/" title="Go to the authors homepage">Morten Brix Pedersen</a> and others<br>
-Stats generated in $stats->{processtime}
+Stats generated in $self->{stats}->{processtime}
 </span>
 </span>
 </div>
 </div>
 </body>
 </body>
@@ -264,25 +262,24 @@ sub _activetimes
 {
 {
     # The most actives times on the channel
     # The most actives times on the channel
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my (%output, $tbgcolor);
     my (%output, $tbgcolor);
 
 
     $self->_headline($self->_template_text('activetimestopic'));
     $self->_headline($self->_template_text('activetimestopic'));
 
 
-    my @toptime = sort { $stats->{times}{$b} <=> $stats->{times}{$a} } keys %{ $stats->{times} };
+    my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
 
 
-    my $highest_value = $stats->{times}{$toptime[0]};
+    my $highest_value = $self->{stats}->{times}{$toptime[0]};
 
 
     my @now = localtime($self->{cfg}->{timestamp});
     my @now = localtime($self->{cfg}->{timestamp});
 
 
     my $image;
     my $image;
 
 
-    for my $hour (sort keys %{ $stats->{times} }) {
-        $self->{debug}->("Time: $hour => ". $stats->{times}{$hour});
+    for my $hour (sort keys %{ $self->{stats}->{times} }) {
+        $self->{debug}->("Time: $hour => ". $self->{stats}->{times}{$hour});
 
 
-        my $size = ($stats->{times}{$hour} / $highest_value) * 100;
-        my $percent = ($stats->{times}{$hour} / $stats->{totallines}) * 100;
+        my $size = ($self->{stats}->{times}{$hour} / $highest_value) * 100;
+        my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{totallines}) * 100;
         $percent =~ s/(\.\d)\d+/$1/;
         $percent =~ s/(\.\d)\d+/$1/;
 
 
         if ($size < 1 && $size != 0) {
         if ($size < 1 && $size != 0) {
@@ -341,7 +338,6 @@ sub _activenicks
 {
 {
     # The most active nicks (those who wrote most lines)
     # The most active nicks (those who wrote most lines)
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     $self->_headline($self->_template_text('activenickstopic'));
     $self->_headline($self->_template_text('activenickstopic'));
 
 
@@ -362,8 +358,8 @@ sub _activenicks
 
 
     _html("</tr>");
     _html("</tr>");
 
 
-    my @active = sort { $stats->{lines}{$b} <=> $stats->{lines}{$a} } keys %{ $stats->{lines} };
-    my $nicks = scalar keys %{ $stats->{lines} };
+    my @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
+    my $nicks = scalar keys %{ $self->{stats}->{lines} };
 
 
     if ($self->{cfg}->{activenicks} > $nicks) {
     if ($self->{cfg}->{activenicks} > $nicks) {
         $self->{cfg}->{activenicks} = $nicks;
         $self->{cfg}->{activenicks} = $nicks;
@@ -375,10 +371,10 @@ sub _activenicks
         $nick = $active[$c];
         $nick = $active[$c];
         $visiblenick = $active[$c];
         $visiblenick = $active[$c];
 
 
-        if (not defined $stats->{sayings}{$nick}) {
+        if (not defined $self->{stats}->{sayings}{$nick}) {
             $randomline = "";
             $randomline = "";
         } else {
         } else {
-            $randomline = htmlentities($stats->{sayings}{$nick});
+            $randomline = htmlentities($self->{stats}->{sayings}{$nick});
         }
         }
 
 
         # Convert URLs and e-mail addys to links
         # Convert URLs and e-mail addys to links
@@ -407,15 +403,15 @@ sub _activenicks
 
 
 
 
         _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\" align=\"left\">");
         _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\" align=\"left\">");
-        my $line = $stats->{lines}{$nick};
-        my $w    = $stats->{words}{$nick};
-        my $ch   = $stats->{lengths}{$nick};
+        my $line = $self->{stats}->{lines}{$nick};
+        my $w    = $self->{stats}->{words}{$nick};
+        my $ch   = $self->{stats}->{lengths}{$nick};
         _html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
         _html("$i</td><td bgcolor=\"#$col_r$col_g$col_b\">$visiblenick</td>"
         . ($self->{cfg}->{show_linetime} ?
         . ($self->{cfg}->{show_linetime} ?
-        "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_linetimes($stats,$nick,$active[0])."</td>"
+        "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_linetimes($nick,$active[0])."</td>"
         : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
         : "<td bgcolor=\"#$col_r$col_g$col_b\">$line</td>")
         . ($self->{cfg}->{show_time} ?
         . ($self->{cfg}->{show_time} ?
-        "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_times($stats,$nick)."</td>"
+        "<td bgcolor=\"$col_r$col_g$col_b\">".$self->_user_times($nick)."</td>"
         : "")
         : "")
         . ($self->{cfg}->{show_words} ?
         . ($self->{cfg}->{show_words} ?
         "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
         "<td bgcolor=\"#$col_r$col_g$col_b\">$w</td>"
@@ -459,7 +455,7 @@ sub _activenicks
             unless ($c % 5) { unless ($c == $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
             unless ($c % 5) { unless ($c == $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
             _html("<td bgcolor=\"$self->{cfg}->{rankc}\" class=\"small\">");
             _html("<td bgcolor=\"$self->{cfg}->{rankc}\" class=\"small\">");
             my $nick = $active[$c];
             my $nick = $active[$c];
-            my $lines = $stats->{lines}{$nick};
+            my $lines = $self->{stats}->{lines}{$nick};
             _html("$nick ($lines)</td>");
             _html("$nick ($lines)</td>");
         }
         }
 
 
@@ -481,13 +477,12 @@ sub _questions
 {
 {
     # Persons who asked the most questions
     # Persons who asked the most questions
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %qpercent;
     my %qpercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{questions} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $qpercent{$nick} = ($stats->{questions}{$nick} / $stats->{lines}{$nick}) * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
             $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
             $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -522,13 +517,12 @@ sub _shoutpeople
 {
 {
     # The ones who speak with exclamation marks!
     # The ones who speak with exclamation marks!
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %spercent;
     my %spercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{shouts} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $spercent{$nick} = ($stats->{shouts}{$nick} / $stats->{lines}{$nick}) * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -565,13 +559,12 @@ sub _capspeople
 {
 {
     # The ones who speak ALL CAPS.
     # The ones who speak ALL CAPS.
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %cpercent;
     my %cpercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{allcaps} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $cpercent{$nick} = $stats->{allcaps}{$nick} / $stats->{lines}{$nick} * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
             $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
             $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -582,7 +575,7 @@ sub _capspeople
         my %hash = (
         my %hash = (
             nick => $caps[0],
             nick => $caps[0],
             per  => $cpercent{$caps[0]},
             per  => $cpercent{$caps[0]},
-            line => htmlentities($stats->{allcaplines}{$caps[0]})
+            line => htmlentities($self->{stats}->{allcaplines}{$caps[0]})
         );
         );
 
 
         my $text = $self->_template_text('allcaps1', %hash);
         my $text = $self->_template_text('allcaps1', %hash);
@@ -613,18 +606,17 @@ sub _violent
 {
 {
     # They attacked others (words defined by $self->{cfg}->{violent})
     # They attacked others (words defined by $self->{cfg}->{violent})
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my @aggressors;
     my @aggressors;
 
 
-    @aggressors = sort { $stats->{violence}{$b} <=> $stats->{violence}{$a} }
-                         keys %{ $stats->{violence} };
+    @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
+                         keys %{ $self->{stats}->{violence} };
 
 
     if(@aggressors) {
     if(@aggressors) {
         my %hash = (
         my %hash = (
             nick    => $aggressors[0],
             nick    => $aggressors[0],
-            attacks => $stats->{violence}{$aggressors[0]},
-            line    => htmlentities($stats->{violencelines}{$aggressors[0]})
+            attacks => $self->{stats}->{violence}{$aggressors[0]},
+            line    => htmlentities($self->{stats}->{violencelines}{$aggressors[0]})
         );
         );
         my $text = $self->_template_text('violent1', %hash);
         my $text = $self->_template_text('violent1', %hash);
         if($self->{cfg}->{show_violentlines}) {
         if($self->{cfg}->{show_violentlines}) {
@@ -636,7 +628,7 @@ sub _violent
         if (@aggressors >= 2) {
         if (@aggressors >= 2) {
             my %hash = (
             my %hash = (
                 nick    => $aggressors[1],
                 nick    => $aggressors[1],
-                attacks => $stats->{violence}{$aggressors[1]}
+                attacks => $self->{stats}->{violence}{$aggressors[1]}
             );
             );
 
 
             my $text = $self->_template_text('violent2', %hash);
             my $text = $self->_template_text('violent2', %hash);
@@ -651,14 +643,14 @@ sub _violent
 
 
     # They got attacked
     # They got attacked
     my @victims;
     my @victims;
-    @victims = sort { $stats->{attacked}{$b} <=> $stats->{attacked}{$a} }
-		    keys %{ $stats->{attacked} };
+    @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
+		    keys %{ $self->{stats}->{attacked} };
 
 
     if(@victims) {
     if(@victims) {
         my %hash = (
         my %hash = (
             nick    => $victims[0],
             nick    => $victims[0],
-            attacks => $stats->{attacked}{$victims[0]},
-            line    => htmlentities($stats->{attackedlines}{$victims[0]})
+            attacks => $self->{stats}->{attacked}{$victims[0]},
+            line    => htmlentities($self->{stats}->{attackedlines}{$victims[0]})
         );
         );
         my $text = $self->_template_text('attacked1', %hash);
         my $text = $self->_template_text('attacked1', %hash);
         if($self->{cfg}->{show_violentlines}) {
         if($self->{cfg}->{show_violentlines}) {
@@ -670,7 +662,7 @@ sub _violent
         if (@victims >= 2) {
         if (@victims >= 2) {
             my %hash = (
             my %hash = (
                 nick    => $victims[1],
                 nick    => $victims[1],
-                attacks => $stats->{attacked}{$victims[1]}
+                attacks => $self->{stats}->{attacked}{$victims[1]}
             );
             );
 
 
             my $text = $self->_template_text('attacked2', %hash);
             my $text = $self->_template_text('attacked2', %hash);
@@ -684,16 +676,15 @@ sub _gotkicks
 {
 {
     # The persons who got kicked the most
     # The persons who got kicked the most
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @gotkick = sort { $stats->{gotkicked}{$b} <=> $stats->{gotkicked}{$a} }
-                       keys %{ $stats->{gotkicked} };
+    my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
+                       keys %{ $self->{stats}->{gotkicked} };
 
 
     if (@gotkick) {
     if (@gotkick) {
         my %hash = (
         my %hash = (
             nick  => $gotkick[0],
             nick  => $gotkick[0],
-            kicks => $stats->{gotkicked}{$gotkick[0]},
-            line  => $stats->{kicklines}{$gotkick[0]}
+            kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
+            line  => $self->{stats}->{kicklines}{$gotkick[0]}
         );
         );
 
 
         my $text = $self->_template_text('gotkick1', %hash);
         my $text = $self->_template_text('gotkick1', %hash);
@@ -708,7 +699,7 @@ sub _gotkicks
         if (@gotkick >= 2) {
         if (@gotkick >= 2) {
             my %hash = (
             my %hash = (
                 nick  => $gotkick[1],
                 nick  => $gotkick[1],
-                kicks => $stats->{gotkicked}{$gotkick[1]}
+                kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
             );
             );
 
 
             my $text = $self->_template_text('gotkick2', %hash);
             my $text = $self->_template_text('gotkick2', %hash);
@@ -721,15 +712,14 @@ sub _gotkicks
 sub _mostjoins
 sub _mostjoins
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @joins = sort { $stats->{joins}{$b} <=> $stats->{joins}{$a} }
-                     keys %{ $stats->{joins} };
+    my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
+                     keys %{ $self->{stats}->{joins} };
 
 
     if (@joins) {
     if (@joins) {
         my %hash = (
         my %hash = (
             nick  => $joins[0],
             nick  => $joins[0],
-            joins => $stats->{joins}{$joins[0]}
+            joins => $self->{stats}->{joins}{$joins[0]}
         );
         );
 
 
         my $text = $self->_template_text('joins', %hash);
         my $text = $self->_template_text('joins', %hash);
@@ -742,15 +732,14 @@ sub _mostwords
 {
 {
     # The person who got words the most
     # The person who got words the most
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-     my @words = sort { $stats->{words}{$b} <=> $stats->{words}{$a} }
-                      keys %{ $stats->{words} };
+     my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
+                      keys %{ $self->{stats}->{words} };
 
 
     if (@words) {
     if (@words) {
         my %hash = (
         my %hash = (
             nick  => $words[0],
             nick  => $words[0],
-            words => $stats->{words}{$words[0]}
+            words => $self->{stats}->{words}{$words[0]}
         );
         );
 
 
         my $text = $self->_template_text('words1', %hash);
         my $text = $self->_template_text('words1', %hash);
@@ -760,7 +749,7 @@ sub _mostwords
             my %hash = (
             my %hash = (
                 oldnick => $words[0],
                 oldnick => $words[0],
                 nick    => $words[1],
                 nick    => $words[1],
-                words   => $stats->{words}{$words[1]}
+                words   => $self->{stats}->{words}{$words[1]}
             );
             );
 
 
             my $text = $self->_template_text('words2', %hash);
             my $text = $self->_template_text('words2', %hash);
@@ -777,15 +766,14 @@ sub _mostkicks
 {
 {
     # The person who kicked the most
     # The person who kicked the most
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @kicked = sort { $stats->{kicked}{$b} <=> $stats->{kicked}{$a} }
-                        keys %{ $stats->{kicked} };
+    my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
+                        keys %{ $self->{stats}->{kicked} };
 
 
     if (@kicked) {
     if (@kicked) {
         my %hash = (
         my %hash = (
             nick   => $kicked[0],
             nick   => $kicked[0],
-            kicked => $stats->{kicked}{$kicked[0]}
+            kicked => $self->{stats}->{kicked}{$kicked[0]}
         );
         );
 
 
         my $text = $self->_template_text('kick1', %hash);
         my $text = $self->_template_text('kick1', %hash);
@@ -795,7 +783,7 @@ sub _mostkicks
             my %hash = (
             my %hash = (
                 oldnick => $kicked[0],
                 oldnick => $kicked[0],
                 nick    => $kicked[1],
                 nick    => $kicked[1],
-                kicked  => $stats->{kicked}{$kicked[1]}
+                kicked  => $self->{stats}->{kicked}{$kicked[1]}
             );
             );
 
 
             my $text = $self->_template_text('kick2', %hash);
             my $text = $self->_template_text('kick2', %hash);
@@ -812,14 +800,13 @@ sub _mostmonologues
 {
 {
     # The person who had the most monologues (speaking to himself)
     # The person who had the most monologues (speaking to himself)
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @monologue = sort { $stats->{monologues}{$b} <=> $stats->{monologues}{$a} } keys %{ $stats->{monologues} };
+    my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} } keys %{ $self->{stats}->{monologues} };
 
 
     if (@monologue) {
     if (@monologue) {
         my %hash = (
         my %hash = (
             nick  => $monologue[0],
             nick  => $monologue[0],
-            monos => $stats->{monologues}{$monologue[0]}
+            monos => $self->{stats}->{monologues}{$monologue[0]}
         );
         );
 
 
         my $text = $self->_template_text('mono1', %hash);
         my $text = $self->_template_text('mono1', %hash);
@@ -828,7 +815,7 @@ sub _mostmonologues
         if (@monologue >= 2) {
         if (@monologue >= 2) {
             my %hash = (
             my %hash = (
                 nick  => $monologue[1],
                 nick  => $monologue[1],
-                monos => $stats->{monologues}{$monologue[1]}
+                monos => $self->{stats}->{monologues}{$monologue[1]}
             );
             );
 
 
             my $text = $self->_template_text('mono2', %hash);
             my $text = $self->_template_text('mono2', %hash);
@@ -842,13 +829,12 @@ sub _linelengths
 {
 {
     # The person(s) who wrote the longest lines
     # The person(s) who wrote the longest lines
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %len;
     my %len;
 
 
-    foreach my $nick (sort keys %{ $stats->{lengths} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $len{$nick} = $stats->{lengths}{$nick} / $stats->{lines}{$nick};
+    foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
             $len{$nick} =~ s/(\.\d)\d+/$1/;
             $len{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -857,9 +843,9 @@ sub _linelengths
 
 
     my $all_lines = 0;
     my $all_lines = 0;
     my $totallength;
     my $totallength;
-    foreach my $nick (keys %{ $stats->{lines} }) {
-        $all_lines   += $stats->{lines}{$nick};
-        $totallength += $stats->{lengths}{$nick};
+    foreach my $nick (keys %{ $self->{stats}->{lines} }) {
+        $all_lines   += $self->{stats}->{lines}{$nick};
+        $totallength += $self->{stats}->{lengths}{$nick};
     }
     }
 
 
     my $totalaverage;
     my $totalaverage;
@@ -914,13 +900,12 @@ sub _linelengths
 sub _mostfoul
 sub _mostfoul
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %spercent;
     my %spercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{foul} }) {
-        if ($stats->{lines}{$nick} > 15) {
-            $spercent{$nick} = $stats->{foul}{$nick} / $stats->{lines}{$nick} * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
+        if ($self->{stats}->{lines}{$nick} > 15) {
+            $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{lines}{$nick} * 100;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -961,13 +946,12 @@ sub _mostfoul
 sub _mostsad
 sub _mostsad
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %spercent;
     my %spercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{frowns} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $spercent{$nick} = $stats->{frowns}{$nick} / $stats->{lines}{$nick} * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -1005,17 +989,16 @@ sub _mostsad
 sub _mostop
 sub _mostop
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @ops   = sort { $stats->{gaveops}{$b} <=> $stats->{gaveops}{$a} }
-                     keys %{ $stats->{gaveops} };
-    my @deops = sort { $stats->{tookops}{$b} <=> $stats->{tookops}{$a} }
-                     keys %{ $stats->{tookops} };
+    my @ops   = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
+                     keys %{ $self->{stats}->{gaveops} };
+    my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
+                     keys %{ $self->{stats}->{tookops} };
 
 
     if (@ops) {
     if (@ops) {
         my %hash = (
         my %hash = (
             nick => $ops[0],
             nick => $ops[0],
-            ops  => $stats->{gaveops}{$ops[0]}
+            ops  => $self->{stats}->{gaveops}{$ops[0]}
         );
         );
 
 
         my $text = $self->_template_text('mostop1', %hash);
         my $text = $self->_template_text('mostop1', %hash);
@@ -1025,7 +1008,7 @@ sub _mostop
         if (@ops >= 2) {
         if (@ops >= 2) {
             my %hash = (
             my %hash = (
                 nick => $ops[1],
                 nick => $ops[1],
-                ops  => $stats->{gaveops}{$ops[1]}
+                ops  => $self->{stats}->{gaveops}{$ops[1]}
             );
             );
 
 
             my $text = $self->_template_text('mostop2', %hash);
             my $text = $self->_template_text('mostop2', %hash);
@@ -1040,7 +1023,7 @@ sub _mostop
     if (@deops) {
     if (@deops) {
         my %hash = (
         my %hash = (
             nick  => $deops[0],
             nick  => $deops[0],
-            deops => $stats->{tookops}{$deops[0]}
+            deops => $self->{stats}->{tookops}{$deops[0]}
         );
         );
         my $text = $self->_template_text('mostdeop1', %hash);
         my $text = $self->_template_text('mostdeop1', %hash);
 
 
@@ -1049,7 +1032,7 @@ sub _mostop
         if (@deops >= 2) {
         if (@deops >= 2) {
             my %hash = (
             my %hash = (
                 nick  => $deops[1],
                 nick  => $deops[1],
-                deops => $stats->{tookops}{$deops[1]}
+                deops => $self->{stats}->{tookops}{$deops[1]}
             );
             );
             my $text = $self->_template_text('mostdeop2', %hash);
             my $text = $self->_template_text('mostdeop2', %hash);
 
 
@@ -1066,16 +1049,15 @@ sub _mostactions
 {
 {
     # The person who did the most /me's
     # The person who did the most /me's
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @actions = sort { $stats->{actions}{$b} <=> $stats->{actions}{$a} }
-                        keys %{ $stats->{actions} };
+    my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
+                        keys %{ $self->{stats}->{actions} };
 
 
     if (@actions) {
     if (@actions) {
         my %hash = (
         my %hash = (
             nick    => $actions[0],
             nick    => $actions[0],
-            actions => $stats->{actions}{$actions[0]},
-            line    => htmlentities($stats->{actionlines}{$actions[0]})
+            actions => $self->{stats}->{actions}{$actions[0]},
+            line    => htmlentities($self->{stats}->{actionlines}{$actions[0]})
         );
         );
         my $text = $self->_template_text('action1', %hash);
         my $text = $self->_template_text('action1', %hash);
         if($self->{cfg}->{show_actionline}) {
         if($self->{cfg}->{show_actionline}) {
@@ -1088,7 +1070,7 @@ sub _mostactions
         if (@actions >= 2) {
         if (@actions >= 2) {
             my %hash = (
             my %hash = (
                 nick    => $actions[1],
                 nick    => $actions[1],
-                actions => $stats->{actions}{$actions[1]}
+                actions => $self->{stats}->{actions}{$actions[1]}
             );
             );
 
 
             my $text = $self->_template_text('action2', %hash);
             my $text = $self->_template_text('action2', %hash);
@@ -1106,13 +1088,12 @@ sub _mostsmiles
 {
 {
     # The person(s) who smiled the most :-)
     # The person(s) who smiled the most :-)
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %spercent;
     my %spercent;
 
 
-    foreach my $nick (sort keys %{ $stats->{smiles} }) {
-        if ($stats->{lines}{$nick} > 100) {
-            $spercent{$nick} = $stats->{smiles}{$nick} / $stats->{lines}{$nick} * 100;
+    foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
+        if ($self->{stats}->{lines}{$nick} > 100) {
+            $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
             $spercent{$nick} =~ s/(\.\d)\d+/$1/;
         }
         }
     }
     }
@@ -1150,16 +1131,15 @@ sub _mostsmiles
 sub _lasttopics
 sub _lasttopics
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    if ($stats->{topics}) {
-        $self->{debug}->("Total number of topics: " . scalar @{ $stats->{topics} });
+    if ($self->{stats}->{topics}) {
+        $self->{debug}->("Total number of topics: " . scalar @{ $self->{stats}->{topics} });
 
 
         my %hash = (
         my %hash = (
-            total => scalar @{ $stats->{topics} }
+            total => scalar @{ $self->{stats}->{topics} }
         );
         );
 
 
-        my $ltopic = $#{ $stats->{topics} };
+        my $ltopic = $#{ $self->{stats}->{topics} };
         my $tlimit = 0;
         my $tlimit = 0;
 
 
         $self->{cfg}->{topichistory} -= 1;
         $self->{cfg}->{topichistory} -= 1;
@@ -1169,14 +1149,14 @@ sub _lasttopics
         }
         }
 
 
         for (my $i = $ltopic; $i >= $tlimit; $i--) {
         for (my $i = $ltopic; $i >= $tlimit; $i--) {
-            my $topic = htmlentities($stats->{topics}[$i]{topic});
-            $topic = _replace_links($stats->{topics}[$i]{topic});
+            my $topic = htmlentities($self->{stats}->{topics}[$i]{topic});
+            $topic = _replace_links($self->{stats}->{topics}[$i]{topic});
             # Strip off the quotes (')
             # Strip off the quotes (')
             $topic =~ s/^\'(.*)\'$/$1/;
             $topic =~ s/^\'(.*)\'$/$1/;
 
 
-            my $nick = $stats->{topics}[$i]{nick};
-            my $hour = $stats->{topics}[$i]{hour};
-            my $min  = $stats->{topics}[$i]{min};
+            my $nick = $self->{stats}->{topics}[$i]{nick};
+            my $hour = $self->{stats}->{topics}[$i]{hour};
+            my $min  = $self->{stats}->{topics}[$i]{min};
 
 
             $hash{nick} = $nick;
             $hash{nick} = $nick;
             $hash{time} = "$hour:$min";
             $hash{time} = "$hour:$min";
@@ -1252,14 +1232,13 @@ sub _mostusedword
 {
 {
     # Word usage statistics
     # Word usage statistics
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %usages;
     my %usages;
 
 
-    foreach my $word (keys %{ $stats->{wordcounts} }) {
+    foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
         # Skip people's nicks.
         # Skip people's nicks.
-        next if exists $stats->{lines}{$word};
-        $usages{$word} = $stats->{wordcounts}{$word};
+        next if exists $self->{stats}->{lines}{$word};
+        $usages{$word} = $self->{stats}->{wordcounts}{$word};
     }
     }
 
 
 
 
@@ -1280,11 +1259,11 @@ sub _mostusedword
             # Skip nicks.  It's far more efficient to do this here than when
             # Skip nicks.  It's far more efficient to do this here than when
             # @popular is created.
             # @popular is created.
             next if is_ignored($popular[$i]);
             next if is_ignored($popular[$i]);
-            next if exists $stats->{lines}{find_alias($popular[$i])};
+            next if exists $self->{stats}->{lines}{find_alias($popular[$i])};
             my $a = $count + 1;
             my $a = $count + 1;
             my $popular = htmlentities($popular[$i]);
             my $popular = htmlentities($popular[$i]);
-            my $wordcount = $stats->{wordcounts}{$popular[$i]};
-            my $lastused = htmlentities($stats->{wordnicks}{$popular[$i]});
+            my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
+            my $lastused = htmlentities($self->{stats}->{wordnicks}{$popular[$i]});
             _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
             _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
@@ -1301,15 +1280,14 @@ sub _mostwordsperline
 {
 {
     # The person who got the most words per line
     # The person who got the most words per line
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my %wpl = ();
     my %wpl = ();
     my $numlines = 0;
     my $numlines = 0;
     my ($avg, $numwords);
     my ($avg, $numwords);
-    foreach my $n (keys %{ $stats->{words} }) {
-        $wpl{$n} = sprintf("%.2f", $stats->{words}{$n}/$stats->{lines}{$n});
-        $numlines += $stats->{lines}{$n};
-        $numwords += $stats->{words}{$n};
+    foreach my $n (keys %{ $self->{stats}->{words} }) {
+        $wpl{$n} = sprintf("%.2f", $self->{stats}->{words}{$n}/$self->{stats}->{lines}{$n});
+        $numlines += $self->{stats}->{lines}{$n};
+        $numwords += $self->{stats}->{words}{$n};
     }
     }
     if ($numlines > 0) {
     if ($numlines > 0) {
         $avg = sprintf("%.2f", $numwords/$numlines);
         $avg = sprintf("%.2f", $numwords/$numlines);
@@ -1340,14 +1318,13 @@ sub _mostreferencednicks
 {
 {
     # List showing the most referenced nicks
     # List showing the most referenced nicks
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
     my (%usages);
     my (%usages);
 
 
-    foreach my $word (sort keys %{ $stats->{wordcounts} }) {
-        next unless exists $stats->{lines}{$word};
+    foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
+        next unless exists $self->{stats}->{lines}{$word};
         next if is_ignored($word);
         next if is_ignored($word);
-        $usages{$word} = $stats->{wordcounts}{$word};
+        $usages{$word} = $self->{stats}->{wordcounts}{$word};
     }
     }
 
 
     my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
     my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
@@ -1365,8 +1342,8 @@ sub _mostreferencednicks
             last unless $i < $#popular;
             last unless $i < $#popular;
             my $a = $i + 1;
             my $a = $i + 1;
             my $popular   = $popular[$i];
             my $popular   = $popular[$i];
-            my $wordcount = $stats->{wordcounts}{$popular[$i]};
-            my $lastused  = $stats->{wordnicks}{$popular[$i]};
+            my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
+            my $lastused  = $self->{stats}->{wordnicks}{$popular[$i]};
             _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
             _html("<tr><td bgcolor=\"$self->{cfg}->{rankc}\"><b>$a</b>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$popular</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
             _html("<td bgcolor=\"$self->{cfg}->{hicell}\">$wordcount</td>");
@@ -1381,10 +1358,9 @@ sub _mosturls
 {
 {
     # List showing the most referenced URLs
     # List showing the most referenced URLs
     my $self = shift;
     my $self = shift;
-    my ($stats) = @_;
 
 
-    my @sorturls = sort { $stats->{urlcounts}{$b} <=> $stats->{urlcounts}{$a} }
-                        keys %{ $stats->{urlcounts} };
+    my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
+                        keys %{ $self->{stats}->{urlcounts} };
 
 
     if (@sorturls) {
     if (@sorturls) {
 
 
@@ -1399,8 +1375,8 @@ sub _mosturls
             last unless $i < $#sorturls;
             last unless $i < $#sorturls;
             my $a = $i + 1;
             my $a = $i + 1;
             my $sorturl  = $sorturls[$i];
             my $sorturl  = $sorturls[$i];
-            my $urlcount = $stats->{urlcounts}{$sorturls[$i]};
-            my $lastused = $stats->{urlnicks}{$sorturls[$i]};
+            my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
+            my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
             if (length($sorturl) > 60) {
             if (length($sorturl) > 60) {
                 $sorturl = substr($sorturl, 0, 60);
                 $sorturl = substr($sorturl, 0, 60);
             }
             }
@@ -1455,17 +1431,16 @@ sub _replace_links
 sub _user_linetimes
 sub _user_linetimes
 {
 {
     my $self = shift;
     my $self = shift;
-    my $stats = shift;
     my $nick  = shift;
     my $nick  = shift;
     my $top   = shift;
     my $top   = shift;
 
 
     my $bar      = "";
     my $bar      = "";
-    my $len      = ($stats->{lines}{$nick} / $stats->{lines}{$top}) * 100;
+    my $len      = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
     my $debuglen = 0;
     my $debuglen = 0;
 
 
     for (my $i = 0; $i <= 3; $i++) {
     for (my $i = 0; $i <= 3; $i++) {
-        next if not defined $stats->{line_times}{$nick}[$i];
-        my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * $len);
+        next if not defined $self->{stats}->{line_times}{$nick}[$i];
+        my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
         $debuglen += $w;
         $debuglen += $w;
         if ($w) {
         if ($w) {
             my $pic = 'pic_h_'.(6*$i);
             my $pic = 'pic_h_'.(6*$i);
@@ -1473,19 +1448,19 @@ sub _user_linetimes
         }
         }
     }
     }
     $self->{debug}->("Length='$len', Sum='$debuglen'");
     $self->{debug}->("Length='$len', Sum='$debuglen'");
-    return "$bar&nbsp;$stats->{lines}{$nick}";
+    return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
 }
 }
 
 
 sub _user_times
 sub _user_times
 {
 {
     my $self = shift;
     my $self = shift;
-    my ($stats, $nick) = @_;
+    my ($nick) = @_;
 
 
     my $bar = "";
     my $bar = "";
 
 
     for (my $i = 0; $i <= 3; $i++) {
     for (my $i = 0; $i <= 3; $i++) {
-        next if not defined $stats->{line_times}{$nick}[$i];
-        my $w = int(($stats->{line_times}{$nick}[$i] / $stats->{lines}{$nick}) * 40);
+        next if not defined $self->{stats}->{line_times}{$nick}[$i];
+        my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * 40);
         if ($w) {
         if ($w) {
             my $pic = 'pic_h_'.(6*$i);
             my $pic = 'pic_h_'.(6*$i);
             $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";
             $bar .= "<img src=\"$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\">";