]> git.donarmstrong.com Git - neurodebian.git/blobdiff - survey/makestats
NF: parsing out those ratings questions
[neurodebian.git] / survey / makestats
index 7b229b1e900febb3ff03c36dff119250958db69f..7f500d692773156983d7f8fa83fa640a30a59f7f 100755 (executable)
@@ -16,10 +16,10 @@ import numpy as np
 import time
 
 # uniform colors for OS results
-os_colors = ['#B63537', '#4E4DA0', '#008200', 'gray']
+os_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE']
 os_order = ['linux', 'mac', 'win', 'otheros']
 time_order = ['notime', 'little', 'most', 'always']
-time_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE']
+time_colors = ['#FF0000', '#FF5500', '#FFAC00', '#FFFD08']
 time_categories = {
         'notime': "don't use it",
         'little': "less than 50%",
@@ -91,7 +91,13 @@ def load_list2dict(name):
     d = {}
     lfile = open(name)
     for line in lfile:
+        if line.strip() == "":
+            continue
         kv = line.split(':')
+        if kv[0] in d:
+            raise RuntimeError(
+                "Got a line %s with a duplicate key %s whenever value for it "
+                "is known already to be %r" % (line, kv[0], d[kv[0]]))
         d[kv[0]] = kv[1].strip().strip('"')
     return d
 
@@ -101,6 +107,9 @@ class DB(dict):
     os_dict = load_list2dict('oslist.txt')
     datamod_dict = load_list2dict('datamodlist.txt')
     sw_dict = load_list2dict('swlist.txt')
+    position_dict = load_list2dict('position-dd-list.txt')
+    employer_dict = load_list2dict('employer-dd-list.txt')
+    ratings_dict = load_list2dict('ratingslist.txt')
 
     def __init__(self, srcdir):
         # eats the whole directory
@@ -168,7 +177,8 @@ class DB(dict):
 
     def get_nice_name(self, id):
         srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
-                resource_categories, time_categories, DB.datamod_dict]
+                resource_categories, time_categories,
+                DB.datamod_dict, DB.position_dict, DB.employer_dict]
         for src in srcs:
             if id in src:
                 return src[id]
@@ -177,7 +187,7 @@ class DB(dict):
 
 
 def mkpic_os_per_env(db, destdir):
-    envs = ['pers', 'man', 'virt', 'virt']
+    envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
     env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
     env_stats = {}
     for env in envs:
@@ -187,7 +197,10 @@ def mkpic_os_per_env(db, destdir):
             stats[os_family_rev[os]] += counts[os]
         total_count = np.sum(stats.values())
         for osf in stats:
-            stats[osf] = float(stats[osf]) / total_count
+            if not total_count:
+                stats[osf] = 0
+            else:
+                stats[osf] = float(stats[osf]) / total_count
         env_stats[env] = stats
     # make stacked barplot
     pl.figure(figsize=(6.4, 4.8))
@@ -231,13 +244,18 @@ def mkpic_time_per_env(db, destdir):
     pl.ylim(-0.4, len(envs))
     pl.title("Research activity time by environment")
     pl.xlabel("Fraction of submissions")
-    pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
+    pl.subplots_adjust(right=0.97)
+    pl.savefig('%s/time_by_env.png' % destdir, format='png', dpi=80)
 
 
 def mkpic_submissions_per_key(db, destdir, key, title, sortby='name',
                             multiple=False):
     counts = db.get_counts(key)
-    pl.figure(figsize=(6.4, 4.8))
+    pl.figure(figsize=(6.4, (len(counts)-2) * 0.4 + 2))
+    tmargin = .8/len(counts)
+    if tmargin > 0.3: tmargin = 0.3
+    print key, tmargin
+    pl.subplots_adjust(left=0.03, right=0.97, top=1-tmargin, bottom=tmargin)
     pl.title(title)
     if not len(counts):
         pl.text(.5, .5, "[Insufficient data for this figure]",
@@ -252,18 +270,18 @@ def mkpic_submissions_per_key(db, destdir, key, title, sortby='name',
         else:
             raise ValueError("Specify either name or count for sortby")
         x = np.arange(len(stats))
-        pl.bar(x + (1./8), [s[1] for s in stats], width=0.75, color = '#008200')
-        pl.xticks(x + 0.5,  ['' for s in stats])
+        pl.barh(x + (1./8), [s[1] for s in stats], height=0.75, color = '#008200')
+        pl.yticks(x + 0.5,  ['' for s in stats])
         for i, s in enumerate(stats):
-            pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
-                    horizontalalignment='center',
-                    verticalalignment='bottom',
+            pl.text(0.1, i+.5, db.get_nice_name(s[0]),
+                    horizontalalignment='left',
+                    verticalalignment='center',
                     bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
-        pl.xlim(0, len(stats))
+        pl.ylim(0, len(stats))
         yl = "Number of submissions"
         if multiple:
             yl += "\n(multiple choices per submission possible)"
-        pl.ylabel(yl)
+        pl.xlabel(yl)
     pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80)