From: Eric S. Raymond Date: Tue, 16 Sep 2003 21:19:07 +0000 (+0000) Subject: Polish the statistics object. X-Git-Tag: 2.0~33 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=9efef539b7a3ac7d2f36675c76bd85ccb8401e62;p=comparator.git Polish the statistics object. --- diff --git a/comparator.py b/comparator.py index 1a6e15d..d2ea298 100644 --- a/comparator.py +++ b/comparator.py @@ -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 diff --git a/filterator b/filterator index 608b413..5316b0d 100755 --- a/filterator +++ b/filterator @@ -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: