X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=survey%2Fmakestats;h=c67a3ad72cca630a895c8eab704c6897ff551e20;hb=HEAD;hp=44b133c70654c99749709d4e069b1f7e87968649;hpb=9fb96b1232eb5c43b4538efb3448e5ec4cde65a4;p=neurodebian.git
diff --git a/survey/makestats b/survey/makestats
index 44b133c..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.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):
@@ -213,9 +243,10 @@ def mkpic_os_per_env(db, destdir):
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 left')
+ 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.xlabel("Fraction of submissions")
pl.subplots_adjust(left=0.15, right=0.97)
@@ -238,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")
@@ -255,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)
@@ -276,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'))
@@ -293,9 +325,11 @@ def mkpic_software(db, destdir):
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,
@@ -311,13 +345,19 @@ 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,
- intro_sentence="I agree with the statements"):
- per_os_width = 10
- max_rating = 4
+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.rst' % env, 'w')
+ rst = open('figures/ratings_%s%s.rst' % (env, suffix), 'w')
rst.write("""
%s
@@ -330,68 +370,68 @@ def mkpic_rating_by_os_hor_joined(db, env, items, destdir, title,
""" % (title, '=' * len(title), intro_sentence))
for k, it in enumerate(items):
- pl.figure(figsize=(3.2, 0.5))
+ if k == 0:
+ pl.figure(figsize=(3.2, 0.75))
+ else:
+ pl.figure(figsize=(3.2, 0.5))
it_nice = db.get_nice_name(it)#.lstrip('.').lstrip(' ')
it_nice = it_nice[0].upper() + it_nice[1:]
for i, os in enumerate(os_order):
ratings = np.array(db.select_match(env,
os_family[os]).get_not_none('%s' % (it,))[0])
- # assume that we have 4 grades from 0 to 3
- if len(ratings):
- assert(max(ratings) < max_rating)
- total = len(ratings)
- bottom = 0
- for r in range(max_rating)[::-1]: # so we go from agree to don't
- stat = np.sum(ratings == r) * per_os_width / float(total)
- #print r, it, os, stat, total
- #if it == "pers_r8" and os == "linux" and r == 3:
- # import pydb; pydb.debugger()
- kwargs = dict(label=None)
- if stat:
- pl.barh(1.0/nos * (nos - 1 - i), stat, left=bottom, color=os_colors[i],
- height=.25, alpha=0.25 + r/float(max_rating),
- label=None,
- edgecolor=os_colors[i])
- bottom += stat
+ #if len(ratings):
+ # assert(max(ratings) < max_rating)
# Complement with errorbar
if len(ratings):
+ scaling = float(per_os_width)/(max_rating-1)
meanstat = np.mean(ratings)
- errstat = len(ratings) > 1 and np.std(ratings) or 0
- pl.errorbar([per_os_width * (max_rating-1 - float(meanstat))/(max_rating-1)],
+ meanstat_point = scaling * meanstat
+ # standard error of estimate
+ errstat_point = len(ratings) > 1 and scaling*np.std(ratings)/np.sqrt(len(ratings)-1) or 0
+ #print ratings, meanstat, meanstat_point, errstat_point
+ if True:
+ # Beautiful piece not yet appreciated by the audience
+ total = len(ratings)
+ bottom = 0
+ max_rating_max = max(max_rating, max(ratings)+1)
+ for r in sorted(set(ratings)):#range(max_rating_max):
+ stat = np.sum(ratings == r) * meanstat_point / float(total)
+ #print r, it, os, stat, total
+ #if it == "pers_r8" and os == "linux" and r == 3:
+ # import pydb; pydb.debugger()
+ kwargs = dict(label=None)
+ if stat:
+ pl.barh(1.0/nos * (nos - 1 - i), stat, left=bottom, color=os_colors[i],
+ height=.25, alpha=1./max_rating_max + r/float(max_rating_max),
+ label=None,
+ edgecolor=os_colors[i])
+ bottom += stat
+ else:
+ pl.barh(1.0/nos * (nos - 1 - i), meanstat_point, left=0,
+ color=os_colors[i], height=.25, alpha=1.0, label=None)
+ pl.errorbar([meanstat_point],
[1.0/nos * (nos - 0.5 - i)],
- xerr=[errstat], fmt='o', color=os_colors[i], ecolor='k')
- #plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
- # title=title, ylabel="Mean rating", label=db.get_nice_name(os))
- #import pydb; pydb.debugger()
- #pl.xlim((0, per_os_width * len(os_order)))
- #pl.ylim((0, 1)) # len(items)))
- #pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
- #pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
- # horizontalalignment='center')
- #pl.legend(loc='lower right')
+ xerr=[errstat_point], fmt='o', color=os_colors[i], ecolor='k')
pl.xlim((0, per_os_width))
- pl.ylim((0, 1))
+ if k == 0 and max_rating == 4: # ad-hoc: only for those disagree/agree
+ pl.text(0, 1.1, "Disagree", horizontalalignment='left')
+ pl.text(per_os_width, 1.1, "Agree", horizontalalignment='right')
+ pl.ylim((0, 1.5))
+ else:
+ pl.ylim((0, 1))
pl.axis('off')
- pl.subplots_adjust(left=0.01, right=0.99, bottom=0.0, top=1,
+ pl.subplots_adjust(left=0.00, right=1., bottom=0.0, top=1,
wspace=0.05, hspace=0.05)
- fname = '%s/ratings_%s_%s.png' % (destdir, env, it)
+ fname = '%s/ratings_%s_%s%s.png' % (destdir, env, it, suffix)
pl.savefig(fname, format='png', dpi=80)
pl.close()
oddrow_s = k % 2 == 0 and ' class="oddrow"' or ''
rst.write("""
- %(it_nice)s |
- |
"""
+ %(it_nice)s |
+ | """
% (locals()))
- #pl.yticks(range(len(items)), [db.get_nice_name(it) for it in items])
- #pl.xlim((0, per_os_width))# * len(os_order)))
- #pl.ylim((0, len(items)))
- #pl.axis('off')
- #pl.subplots_adjust(left=0, right=1, bottom=0, top=1,
- # wspace=0.05, hspace=0.05)
- #pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
- #pl.close()
rst.write("""
@@ -402,16 +442,39 @@ def mkpic_rating_by_os_hor_joined(db, env, items, destdir, title,
def main(srcdir, destdir):
db = DB(srcdir)
+ if False:
+ ## Plot maintenance time per each group
+ # assess what would be our range
+ pmts, _ = db.get_not_none('pers_maint_time')
+ max_rating = int(np.mean(pmts) + np.std(pmts))
+ for pos in db.get_unique('bg_position'):
+ print pos
+ mkpic_rating_by_os_hor_joined(db.select_match('bg_position', pos),
+ 'pers_os', ['pers_maint_time'], destdir,
+ "Personal environment", "", suffix='_maint_time_%s' % pos,
+ max_rating=max_rating)
+
+ ## db2 = db
+ # custom selection for people dealing more with hardware
+ # any electrophys
+ ## db = db2.select_match('bg_datamod', (('ephys'),))
+ # or only selected ones (so no fmri/pet etc)
+ ## db = db2.select_match_exactly('bg_datamod', (('ephys'), ('behav'),))
+ ## db.update(db2.select_match_exactly('bg_datamod', (('ephys'),)))
+ ## db.update(db2.select_match_exactly('bg_datamod', (('ephys'), ('genetic'),)))
+ ## db.update(db2.select_match_exactly('bg_datamod', (('ephys'), ('simulation'),)))
+ ## db.update(db2.select_match_exactly('bg_datamod', (('ephys'), ('meeg'),)))
+
if not os.path.exists(destdir):
os.makedirs(destdir)
mkpic_submissions_per_key(
- db, destdir, 'virt_prod', sortby='name',
- title='Virtualization product popularity\n(multiple choices per submission possible)')
+ db, destdir, 'virt_prod', sortby='count',
+ title='Virtualization product popularity')
mkpic_submissions_per_key(
db, destdir, 'bg_datamod', sortby='count',
- title='Submissions per data modality\n(multiple choices per submission possible)')
+ title='Submissions per data modality')
mkpic_submissions_per_key(
db, destdir, 'bg_position', title='Submissions per position', sortby='count')
@@ -427,19 +490,21 @@ def main(srcdir, destdir):
for pic in [mkpic_os_per_env, mkpic_software, mkpic_time_per_env]:
pic(db, destdir)
+
+
mkpic_rating_by_os_hor_joined(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
"Personal environment", "I prefer this particular scientific software environment because ...")
- mkpic_rating_by_os_hor_joined(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
+ mkpic_rating_by_os_hor_joined(db, 'man_os', ['man_r%i' % i for i in range(1, 6)], destdir,
"Managed environment")
- mkpic_rating_by_os_hor_joined(db, 'virt_host_os', ['man_r%i' % i for i in range(1, 4)], destdir,
+ mkpic_rating_by_os_hor_joined(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 5)], destdir,
"Virtual environment (by host OS)")
+ mkpic_rating_by_os_hor_joined(db, 'virt_guest_os', ['virt_r%i' % i for i in range(1, 5)], destdir,
+ "Virtual environment (by guest OS)")
+
+ ## mkpic_rating_by_os_hor_joined(db.select_match('virt_prod', (('vmware'),)),
+ ## 'virt_host_os', ['virt_r%i' % i for i in range(1, 5)], destdir,
+ ## "Virtualbox virtual environment (by host OS)")
- ## mkpic_rating_by_os(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
- ## "Ratings: Personal environment")
- ## mkpic_rating_by_os(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
- ## "Ratings: Managed environment")
- ## mkpic_rating_by_os(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
- ## "Ratings: Virtual environment (by host OS)")
# submission stats: this is RST
statsfile = open('%s/stats.txt' % destdir, 'w')
statsfile.write('::\n\n Number of submissions: %i\n' % len(db))
@@ -449,3 +514,4 @@ def main(srcdir, destdir):
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])
+ #main('dataout', 'figures')