You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Daniel Quinlan <qu...@pathname.com> on 2006/01/26 10:00:25 UTC

bizarre code from logs-to-c

Does the last part of this patch make *any* sense?  It's Allen code from
January 2003 (bug 1088), checked in without a comment probably because
none of us understood it.  (The single line changes in the patch are
fine.)

As far as I can tell, all it does is screw up scores when doing
fp-fn-statistics because read_ranges now happens before readlogs at the
beginning of logs-to-c.  So, some scores are *changed* before doing
counts for fp-fn-statistics.  Before the move, it looks like a complete
no-op, but it's been this way since mid-2004.

This change confuses the hell out of me.  I can't even figure out what
the hell Allen was *trying* to do.

Daniel (continuing to fix the scoring scripts)

Index: logs-to-c
===================================================================
--- logs-to-c	(revision 4400)
+++ logs-to-c	(revision 4453)
@@ -154,7 +154,7 @@
     if ((scalar(@hits)+1) > $max_hits_per_msg) {
       $max_hits_per_msg = scalar(@hits)+1;
     }
-    }
+  }
 
   for ($i = 0; $i <= $#index_to_rule; $i++) {
     my $name = $index_to_rule[$i];
@@ -331,7 +331,7 @@
     $range_hi{$t} = $2+0;
     my $mut = $3+0;
 
-    if ($t =~ /^__/) {
+    if ($allrules{$t}->{issubrule}) {
       $ignored_rule{$t} = 1;
       $mutable_tests{$t} = 0;
       next;
@@ -351,7 +351,7 @@
       $mutable_tests{$t} = 0;
     } elsif ($range_lo{$t} == $range_hi{$t}) {
       $mutable_tests{$t} = 0;
-    } elsif ($allrules{$t}->{tflags} =~ m/userconf/) {
+    } elsif ($allrules{$t}->{tflags} =~ m/\buserconf\b/i) {
       $mutable_tests{$t} = 0;
     } else {
       $mutable_tests{$t} = 1;
@@ -365,22 +365,56 @@
   # catch up on the ones missed; seems to be userconf or 0-hitters mostly.
   foreach my $t (sort keys %allrules) {
     next if (exists($range_lo{$t}));
-    if ($t =~ /^__/) {
+    if ($allrules{$t}->{issubrule}) {
       $ignored_rule{$t} = 1;
       $mutable_tests{$t} = 0;
       next;
     }
     $ignored_rule{$t} = 0;
     unless (exists($mutable_tests{$t}) &&
-	    ($allrules{$t}->{tflags} !~ m/userconf/)) {
+	    ($allrules{$t}->{tflags} !~ m/\buserconf\b/i)) {
       $mutable_tests{$t} = 0;
     }
     unless ($mutable_tests{$t} || $scores{$t}) {
       $ignored_rule{$t} = 1;
-  }
+    }
     $index_to_rule[$count] = $t;
     $count++;
   }
+  foreach my $t (keys %range_lo) {
+    next if ($ignored_rule{$t});
+    if ($mutable_tests{$t}) {
+      if (($scores{$t} == 1) && ($allrules{$t}->{tflags} =~ m/\bnice\b/i)) {
+	$scores{$t} = -1;
+      } elsif (($scores{$t} == 0.01) && ($t =~ m/^T_/) &&
+	       ($allrules{$t}->{tflags} =~ m/\bnice\b/i)) {
+	$scores{$t} = -0.01;
+      }
+      if ($scores{$t} >= $range_hi{$t}) {
+	$scores{$t} = $range_hi{$t} - 0.001;
+      } elsif ($scores{$t} <= $range_lo{$t}) {
+	$scores{$t} = $range_lo{$t} + 0.001;
+      }
+    } else {
+      if ($allrules{$t}->{tflags} =~ m/\buserconf\b/i) {
+	next;
+      } elsif ($range_lo{$t} == $range_hi{$t}) {
+	$scores{$t} = $range_lo{$t};
+	next;
+      }
+      if (($scores{$t} == 1) && ($allrules{$t}->{tflags} =~ m/\bnice\b/i)) {
+	$scores{$t} = -1;
+      } elsif (($scores{$t} == 0.01) && ($t =~ m/^T_/) &&
+	       ($allrules{$t}->{tflags} =~ m/\bnice\b/i)) {
+	$scores{$t} = -0.01;
+      }
+      if ($scores{$t} > $range_hi{$t}) {
+	$scores{$t} = $range_hi{$t};
+      } elsif ($scores{$t} < $range_lo{$t}) {
+	$scores{$t} = $range_lo{$t};
+      }
+    }
+  }
 }
 
 sub evaluate {

-- 
Daniel Quinlan
http://www.pathname.com/~quinlan/