[Pcsclite-cvs-commit] r6612 - /website/calculate_stats.py

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Sat Apr 20 10:01:27 UTC 2013


Author: rousseau
Date: Sat Apr 20 10:01:27 2013
New Revision: 6612

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6612
Log:
Calculate some statistics

Added:
    website/calculate_stats.py   (with props)

Added: website/calculate_stats.py
URL: http://svn.debian.org/wsvn/pcsclite/website/calculate_stats.py?rev=6612&op=file
==============================================================================
--- website/calculate_stats.py (added)
+++ website/calculate_stats.py Sat Apr 20 10:01:27 2013
@@ -1,0 +1,145 @@
+#!/usr/bin/env python
+
+"""
+#    make_stats.py: calculate some statistics
+#    Copyright (C) 2013  Ludovic Rousseau
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along
+#    with this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""
+
+# $Id$
+
+from matrix import parse_ini
+import sys
+
+path = "../trunk/Drivers/ccid/readers/"
+
+
+def inverse_dict(map):
+    inv_map = {}
+    for k, v in map.iteritems():
+        inv_map[v] = inv_map.get(v, [])
+        inv_map[v].append(k)
+    return inv_map
+
+
+def display_stats_for_field(readers, field, csv=False):
+    total = len(all_readers) + 0.0
+
+    stats = get_stats_for_field(all_readers, field)
+
+    if csv:
+        # CSV file
+        output = open(field + ".csv", 'w')
+        output.write("%s;\n" % field)
+        for key in sorted(stats):
+            for value in sorted(stats[key]):
+                left = value
+                right = key
+
+                try:
+                    int_value = int(left)
+                    left = "'%d'" % int_value
+                except ValueError:
+                    pass
+                output.write("%s;%d\n" % (left, right))
+        output.close()
+
+        # HTML table
+        output = open(field + ".html", 'w')
+        output.write('<table class=\"mytable\">\n')
+        output.write("<thead><tr><th>%s</th><th>#</th><th>%%</th></tr></thead>\n" % field)
+        #output.write("<tfoot><tr><td>total</td><td>%d</td></tr></tfoot>\n" % total)
+        output.write("<tbody>\n")
+        for key in reversed(sorted(stats)):
+            for value in sorted(stats[key]):
+                left = value
+                right = key
+
+                output.write("<tr><td>%s</td><td>%d</td><td>%.2f %%</td></tr>\n" % (left, right, right / total * 100.))
+        output.write('</tbody></table>\n')
+        output.close()
+    else:
+        # console output
+        print
+        print "Stats for:", field
+        for key in sorted(stats):
+            print "%.2f%%\t%s" % (key / total * 100., ", ".join(stats[key]))
+
+
+def get_stats_for_field(readers, field):
+    stats = dict()
+
+    cat_name = {"supported": "Supported readers",
+        "shouldwork": "Should work readers",
+        "unsupported": "Unsupported readers",
+        "disabled": "Disabled readers"}
+
+    for reader in readers:
+        descriptor = readers[reader]
+        value = descriptor[field]
+        if field == 'section':
+            value = cat_name[value]
+        if field == 'features':
+            for val1 in value:
+                val2 = field + " " + val1
+                if val2 in stats:
+                    stats[val2] += 1
+                else:
+                    stats[val2] = 1
+        else:
+            if value in stats:
+                stats[value] += 1
+            else:
+                stats[value] = 1
+
+    return inverse_dict(stats)
+
+
+def get_all_readers():
+    """ returns the list of all readers """
+
+    supported_readers = parse_ini(path, "supported")
+    shouldwork_readers = parse_ini(path, "shouldwork")
+    unsupported_readers = parse_ini(path, "unsupported")
+    #disabled_readers = parse_ini(path, "disabled")
+
+    # all_readers contains the union of the 3 lists
+    all_readers = dict(supported_readers)
+    all_readers.update(shouldwork_readers)
+    all_readers.update(unsupported_readers)
+    #all_readers.update(disabled_readers)
+
+    return all_readers
+
+if __name__ == "__main__":
+    all_readers = get_all_readers()
+
+    if len(sys.argv) > 1:
+        csv = True
+        import os
+        try:
+            os.mkdir(sys.argv[1])
+        except OSError:
+            pass
+        os.chdir(sys.argv[1])
+    else:
+        csv = False
+
+    for field in all_readers['id3_CL1356T.txt']:
+        if field in ('image', 'limitations', 'iInterface'):
+            continue
+        else:
+            display_stats_for_field(all_readers, field, csv)

Propchange: website/calculate_stats.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: website/calculate_stats.py
------------------------------------------------------------------------------
    svn:keywords = Id




More information about the Pcsclite-cvs-commit mailing list