You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2011/09/20 18:07:01 UTC
svn commit: r1173216 - /subversion/trunk/tools/dev/histogram.py
Author: hwright
Date: Tue Sep 20 16:07:00 2011
New Revision: 1173216
URL: http://svn.apache.org/viewvc?rev=1173216&view=rev
Log:
Add a completely useless and undocumented script to generate a histogram from
a list of values received on stdin.
Suggested by: gstein
* tools/dev/histogram.py:
New.
Added:
subversion/trunk/tools/dev/histogram.py (with props)
Added: subversion/trunk/tools/dev/histogram.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dev/histogram.py?rev=1173216&view=auto
==============================================================================
--- subversion/trunk/tools/dev/histogram.py (added)
+++ subversion/trunk/tools/dev/histogram.py Tue Sep 20 16:07:00 2011
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+import sys
+
+
+def count(infile):
+ counts = {}
+ for line in infile:
+ line = line.strip()
+ if line in counts:
+ counts[line] = counts[line] + 1
+ else:
+ counts[line] = 1
+
+ return counts
+
+
+def histogram(counts, width):
+ (max_len, max_count) = reduce(lambda x, i: (max(len(i[0]), x[0]),
+ max(i[1], x[1])),
+ counts.iteritems(), (0, 0))
+
+ adjustor = float(max_count) / (width - max_len - 3)
+
+ for (count, author) in sorted((v, k) for (k, v) in counts.items())[::-1]:
+ print "%s%s | %s" % (author, " "*(max_len-len(author)),
+ "X"*int(count/adjustor))
+
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ ### TODO: Automagically determine terminal width
+ width = 80
+ else:
+ width = int(sys.argv[1])
+ counts = count(sys.stdin)
+
+ histogram(counts, width)
Propchange: subversion/trunk/tools/dev/histogram.py
------------------------------------------------------------------------------
svn:executable = *