]> thyrsus.com Git - comparator.git/commitdiff
We now have a statistics object.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 20:45:51 +0000 (20:45 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 16 Sep 2003 20:45:51 +0000 (20:45 +0000)
comparator.py
filterator

index 5cf3dd11756639855c0c155d7dec97ec257680bf..1a6e15dfeff981c53a0bebf50ebf8e8acaff84a9 100644 (file)
@@ -209,3 +209,17 @@ class CommonReport:
                 raise ComparatorException("couldn't extracrt file text")
         self.cliques = filtered
 
+class CommonStatistics:
+    "Statistical information from a report."
+    def __init__(self, report):
+        self.chunks = report.segment_count()
+        self.trees = []
+        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
+        for (tree, lines, total) in self.trees:
+            rep += "%s:%d:%d\n" % (tree, lines, total)
+        return rep
index 635ef9f9cd682423ad5926f87c1dfbc45edc6bf6..608b413a4c220ea73c419b2078ad2f3cec9ce8a0 100755 (executable)
@@ -64,10 +64,7 @@ if __name__ == '__main__':
             state.filter_by_significance()
 
         if stats:
-            print "%d overlaps" % state.segment_count()
-            for (tree, totallines) in state.trees.items():
-                lines = state.line_count(tree)
-                print "%s:%d:%d" % (tree, lines, state.trees[tree])
+            sys.stdout.write(str(comparator.CommonStatistics(state)))
         else:
             report_common(state)
     except comparator.ComparatorException, e: