X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=survey%2Fmakestats;h=c67a3ad72cca630a895c8eab704c6897ff551e20;hb=HEAD;hp=b4b2328cdc2d61f601d1c9b6f1c54293e1d0d0d5;hpb=bfd5c22188b65aa754168d5b4bfefa46562a95f8;p=neurodebian.git diff --git a/survey/makestats b/survey/makestats index b4b2328..c67a3ad 100755 --- a/survey/makestats +++ b/survey/makestats @@ -1,6 +1,6 @@ #!/usr/bin/python +# emacs: -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- -from mvpa.misc.plot.base import plot_bars from glob import glob try: from json import load as jload @@ -15,6 +15,14 @@ import pylab as pl import numpy as np import time +from common import entries_to_refresh +fresh_keys = [k + for k, (regex, b) in + reduce(list.__add__,[x.items() + for x in entries_to_refresh['sw_other_name'].values()], + []) + if b] + # uniform colors for OS results os_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE'] os_order = ['linux', 'mac', 'win', 'otheros'] @@ -44,7 +52,7 @@ resource_categories = { 'pypi': 'PyPi', 'pythonbundles': 'Python bundles', 'sourceforge': 'Sourceforge', - 'other': 'Other resource' + 'otherres': 'Other resource' } # software categories sw_categories = { @@ -57,7 +65,7 @@ sw_categories = { 'bci': 'Brain-computer interface', 'acq': 'Hardware interface/Data acquisition', 'rt': 'Real-time solutions', - 'psychophys': 'Psychophysics/Experiment control' + 'psychphys': 'Psychophysics/Experiment control' } # some meaningful groups of OSes @@ -65,7 +73,7 @@ redhat_family = ["rhel", "centos", "fedora", "scilinux"] debian_family = ["debian", "ubuntu", "biolinux"] suse_family = ["suse", "slel"] other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"] -other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other"] +other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other", "dontknow"] os_cat_names = { 'win': 'Windows', @@ -153,13 +161,18 @@ class DB(dict): missing += 1 return val, missing - def get_counts(self, key): + def get_counts(self, key, predef_keys=None): # return a dict with field values as keys and respective submission # count as value vals = self.get_not_none(key)[0] uniq = np.unique(vals) counts = dict(zip(uniq, [vals.count(u) for u in uniq])) - return counts + if not predef_keys is None: + ret = dict(zip(predef_keys, [0] * len(predef_keys))) + else: + ret = {} + ret.update(counts) + return ret def select_match(self, key, values): # return a db with all submissions were a field id has one of the @@ -176,16 +189,33 @@ class DB(dict): match[k] = v return match + def select_match_exactly(self, key, values): + # return a db with all submissions were a field id has value + # equal to the supplied + match = DB(None) + set_values = set(values) + for k, v in self.items(): + if not key in v: + continue + el = v[key] + if isinstance(el, list): + if set(el) == set_values: + match[k] = v + elif set([el]) == set_values: + match[k] = v + return match + 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, DB.position_dict, DB.employer_dict, - DB.vm_dict] + DB.vm_dict, DB.ratings_dict] + suffix = u'$^â $' if id in fresh_keys else '' for src in srcs: if id in src: - return src[id] + return src[id] + suffix # not found, nothing nicer - return id + return id + suffix def mkpic_os_per_env(db, destdir): @@ -205,19 +235,21 @@ def mkpic_os_per_env(db, destdir): stats[osf] = float(stats[osf]) / total_count env_stats[env] = stats # make stacked barplot - pl.figure(figsize=(6.4, 4.8)) + pl.figure(figsize=(7.5, 4)) x = np.arange(len(envs)) bottoms = np.zeros(len(envs)) for i, os in enumerate(os_order): - stat = [env_stats[e][os] for e in envs] - pl.bar(x, stat, bottom=bottoms, color=os_colors[i], - label=db.get_nice_name(os), width=0.8) + stat = [env_stats[e][os] for e in envs[::-1]] + pl.barh(x, stat, left=bottoms, color=os_colors[i], + label=db.get_nice_name(os), height=0.8) bottoms += stat - pl.legend(loc='lower right') - pl.xticks(x + 0.4, [db.get_nice_name(e) for e in env_names]) - pl.xlim(-0.25, len(envs)) + pl.legend(loc='center left') + pl.yticks(x + 0.4, env_names[::-1]) + pl.ylim(-0.25, len(envs)) + pl.xlim(0,1) pl.title("Operating system preference by environment") - pl.ylabel("Fraction of submissions") + pl.xlabel("Fraction of submissions") + pl.subplots_adjust(left=0.15, right=0.97) pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80) @@ -237,12 +269,12 @@ def mkpic_time_per_env(db, destdir): x = np.arange(len(envs)) bottoms = np.zeros(len(envs)) for i, t in enumerate(time_order): - stat = [env_stats[e][t] for e in envs] + stat = [env_stats[e][t] for e in envs[::-1]] pl.barh(x, stat, left=bottoms, color=time_colors[i], label=db.get_nice_name(t), height=.6) bottoms += stat - pl.legend(loc='center left') - pl.yticks(x + 0.2, env_names) + pl.legend(loc='lower left') + pl.yticks(x + 0.2, env_names[::-1]) pl.ylim(-0.4, len(envs)) pl.title("Research activity time by environment") pl.xlabel("Fraction of submissions") @@ -254,7 +286,8 @@ def mkpic_submissions_per_key(db, destdir, key, title, sortby='name', multiple=False): counts = db.get_counts(key) pl.figure(figsize=(6.4, (len(counts)-2) * 0.4 + 2)) - tmargin = .8/len(counts) + if not len(counts): tmargin = 0.4 + else: tmargin = .8/len(counts) if tmargin > 0.3: tmargin = 0.3 pl.subplots_adjust(left=0.03, right=0.97, top=1-tmargin, bottom=tmargin) pl.title(title) @@ -275,7 +308,7 @@ def mkpic_submissions_per_key(db, destdir, key, title, sortby='name', pl.yticks(x + 0.5, ['' for s in stats]) text_offset = pl.gca().get_xlim()[1] / 30. for i, s in enumerate(stats[::-1]): - pl.text(text_offset, i+.5, db.get_nice_name(s[0]), + pl.text(text_offset, i+.5, db.get_nice_name(s[0]) + " [%d]" % (s[1],), horizontalalignment='left', verticalalignment='center', bbox=dict(facecolor='white', alpha=0.8, edgecolor='white')) @@ -287,30 +320,16 @@ def mkpic_submissions_per_key(db, destdir, key, title, sortby='name', pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80) -def mkpic_resources(db, destdir): - res = db.get_counts('software_resource') - res = res.items() - x = np.arange(len(res)) - pl.figure(figsize=(6.4, 4.8)) - pl.title('Software resources') - pl.bar(x + (1./8), [s[1] for s in res], width=0.75, color = '#008200') - pl.xticks(x + 0.5, ['' for s in res]) - for i, s in enumerate(res): - pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90, - horizontalalignment='center', - verticalalignment='bottom', - bbox=dict(facecolor='white', alpha=0.8, edgecolor='white')) - pl.ylabel('Number of submissions') - pl.savefig('%s/software_resources.png' % destdir, format='png', dpi=80) - def mkpic_software(db, destdir): for typ in sw_categories.keys(): mkpic_submissions_per_key( db, destdir, 'sw_%s' % typ, title="Software popularity: %s" % db.get_nice_name(typ), - sortby='name') + sortby='count') def mkpic_rating_by_os(db, env, items, destdir, title): + from mvpa.misc.plot.base import plot_bars + pl.figure(figsize=(6.4, 4.8)) for i, os in enumerate(os_order): ratings = [db.select_match(env, @@ -326,19 +345,136 @@ def mkpic_rating_by_os(db, env, items, destdir, title): pl.legend(loc='lower right') pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80) +def mkpic_rating_by_os_hor_joined(db, env, items, destdir='.', title=None, + intro_sentence="I agree with the statements", + suffix='', max_rating=4): + per_os_width = 1 + #pl.figure(figsize=(6.4, 4.8)) + if max_rating is None: + assert(len(items) == 1) + # We need to query for it + field = items[0] + max_rating = np.max([db[k][field] for k in db if field in db[k]]) + 1 + print "max ", max_rating + nos = len(os_order) + rst = open('figures/ratings_%s%s.rst' % (env, suffix), 'w') + rst.write(""" + +%s +%s + +%s + +.. raw:: html + +
%(it_nice)s | +