]> thyrsus.com Git - comparator.git/commitdiff
Polish the statistics object.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 21:19:07 +0000 (21:19 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 21:19:07 +0000 (21:19 +0000)
comparator.py
filterator

index 1a6e15dfeff981c53a0bebf50ebf8e8acaff84a9..d2ea2988ca15b721a6b9f6336a10e5d106e43194 100644 (file)
@@ -43,7 +43,7 @@ junk = {
         )),
     }
 
-def nontrivial(filetype, text):
+def nontrivial(filetype, text, debug=None):
     "Identify a shred as trivial or nontrivial."
     if filetype:
         if debug:
@@ -203,10 +203,8 @@ class CommonReport:
         filtered = []
         for clique in self.cliques:
             (type, text) = self.extract_text(clique)
-            if text:
+            if nontrivial(type, text):
                 filtered.append(clique)
-            else:
-                raise ComparatorException("couldn't extracrt file text")
         self.cliques = filtered
 
 class CommonStatistics:
@@ -214,12 +212,14 @@ class CommonStatistics:
     def __init__(self, report):
         self.chunks = report.segment_count()
         self.trees = []
+        self.normalization = report.normalization
         for (tree, totallines) in report.trees.items():
             lines = report.line_count(tree)
             self.trees.append((tree, lines, totallines))
 
     def __str__(self):
-        rep = "%d overlaps\n" % self.chunks
+        rep = "Trees: " + " ".join(map(lambda x: x[0], self.trees))
+        rep = "%d overlaps with %s normalization\n" % (self.chunks, self.normalization)
         for (tree, lines, total) in self.trees:
-            rep += "%s:%d:%d\n" % (tree, lines, total)
+            rep += "%s:\t%d of %d (%02.2f%%)\n" % (tree, lines, total, (lines * 100.0)/total)
         return rep
index 608b413a4c220ea73c419b2078ad2f3cec9ce8a0..5316b0db86a6aa88d1bad24bb5c7f29ad514522e 100755 (executable)
@@ -16,12 +16,8 @@ if __name__ == '__main__':
         print "Shred-Size: %d" % state.shredsize
         if minsize:
             print "Minimum-Size: %d" % minsize
-        if stats:
-            print 75 * '-'
-            print "# %d overlaps." % state.segment_count()
-            for (tree, totallines) in state.trees.items():
-                lines = state.line_count(tree)
-                print "# %f%% of %s" % ((lines*100.0)/totallines, tree)
+        print 75 * '-'
+        sys.stdout.write(str(comparator.CommonStatistics(state)))
         print 75 * '-'
         for clique in state.cliques:
             for (file, start, end) in clique: