3 from mvpa.misc.plot.base import plot_bars
6 from json import load as jload
10 from json import read as jread
12 return jread(f.read())
18 # uniform colors for OS results
19 os_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE']
20 os_order = ['linux', 'mac', 'win', 'otheros']
21 time_order = ['notime', 'little', 'most', 'always']
22 time_colors = ['#FF0000', '#FF5500', '#FFAC00', '#FFFD08']
24 'notime': "don't use it",
25 'little': "less than 50%",
26 'most': "more than 50%",
30 resource_categories = {
31 'vendor': 'Vendor/Project website',
32 'retailer': 'Retailer',
33 'os': 'Operating system',
38 'freebsdports': 'FreeBSD ports',
40 'macports': 'Macports',
41 'matlabcentral': 'Matlab Central',
42 'neurodebian': 'NeuroDebian',
45 'pythonbundles': 'Python bundles',
46 'sourceforge': 'Sourceforge',
47 'other': 'Other resource'
51 'general': 'General computing',
52 'dc': 'Distributed computing',
53 'img': 'Brain imaging',
54 'datamanage': 'Data management',
55 'neusys': 'Neural systems modeling',
56 'electro': 'Electrophysiology, MEG/EEG',
57 'bci': 'Brain-computer interface',
58 'acq': 'Hardware interface/Data acquisition',
59 'rt': 'Real-time solutions',
60 'psychophys': 'Psychophysics/Experiment control'
63 # some meaningful groups of OSes
64 redhat_family = ["rhel", "centos", "fedora", "scilinux"]
65 debian_family = ["debian", "ubuntu", "biolinux"]
66 suse_family = ["suse", "slel"]
67 other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"]
68 other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other", "dontknow"]
80 'linux': redhat_family + debian_family + suse_family + other_linux_family,
81 'otheros': other_family
83 # end the reverse mapping
86 for os_ in os_family[ost]:
87 os_family_rev[os_] = ost
90 def load_list2dict(name):
94 if line.strip() == "":
99 "Got a line %s with a duplicate key %s whenever value for it "
100 "is known already to be %r" % (line, kv[0], d[kv[0]]))
101 d[kv[0]] = kv[1].strip().strip('"')
107 os_dict = load_list2dict('oslist.txt')
108 datamod_dict = load_list2dict('datamodlist.txt')
109 sw_dict = load_list2dict('swlist.txt')
110 position_dict = load_list2dict('position-dd-list.txt')
111 employer_dict = load_list2dict('employer-dd-list.txt')
112 ratings_dict = load_list2dict('ratingslist.txt')
113 vm_dict = load_list2dict('vmlist.txt')
115 def __init__(self, srcdir):
116 # eats the whole directory
119 datafilenames = glob('%s/*.json' % srcdir)
120 for dfn in datafilenames:
121 rawdata = jsonload(open(dfn))
122 self[rawdata['timestamp']] = rawdata
124 def get_unique(self, key):
125 # return a set of all (unique) values for a field id
127 for d in self.values():
130 if isinstance(el, list):
131 uniq = uniq.union(el)
133 uniq = uniq.union((el,))
136 def get_not_none(self, key):
137 # return a list of all values of a specific field id
138 # the second return value is count of submission that did not have data
142 for d in self.values():
145 if isinstance(el, list):
156 def get_counts(self, key):
157 # return a dict with field values as keys and respective submission
159 vals = self.get_not_none(key)[0]
160 uniq = np.unique(vals)
161 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
164 def select_match(self, key, values):
165 # return a db with all submissions were a field id has one of the
168 for k, v in self.items():
172 if isinstance(el, list):
173 if len(set(values).intersection(el)):
179 def get_nice_name(self, id):
180 srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
181 resource_categories, time_categories,
182 DB.datamod_dict, DB.position_dict, DB.employer_dict,
183 DB.vm_dict, DB.ratings_dict]
187 # not found, nothing nicer
191 def mkpic_os_per_env(db, destdir):
192 envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
193 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
196 counts = db.get_counts(env)
197 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
199 stats[os_family_rev[os]] += counts[os]
200 total_count = np.sum(stats.values())
205 stats[osf] = float(stats[osf]) / total_count
206 env_stats[env] = stats
207 # make stacked barplot
208 pl.figure(figsize=(7.5, 4))
209 x = np.arange(len(envs))
210 bottoms = np.zeros(len(envs))
211 for i, os in enumerate(os_order):
212 stat = [env_stats[e][os] for e in envs[::-1]]
213 pl.barh(x, stat, left=bottoms, color=os_colors[i],
214 label=db.get_nice_name(os), height=0.8)
216 pl.legend(loc='lower left')
217 pl.yticks(x + 0.4, env_names[::-1])
218 pl.ylim(-0.25, len(envs))
219 pl.title("Operating system preference by environment")
220 pl.xlabel("Fraction of submissions")
221 pl.subplots_adjust(left=0.15, right=0.97)
222 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
225 def mkpic_time_per_env(db, destdir):
226 envs = ['pers_time', 'man_time', 'virt_time']
227 env_names = ['Personal', 'Managed', 'Virtual']
230 counts = dict(zip(time_order, [0] * len(time_order)))
231 counts.update(db.get_counts(env))
232 total_count = np.sum(counts.values())
234 counts[c] = float(counts[c]) / total_count
235 env_stats[env] = counts
236 # make stacked barplot
237 pl.figure(figsize=(7.5, 4))
238 x = np.arange(len(envs))
239 bottoms = np.zeros(len(envs))
240 for i, t in enumerate(time_order):
241 stat = [env_stats[e][t] for e in envs]
242 pl.barh(x, stat, left=bottoms, color=time_colors[i],
243 label=db.get_nice_name(t), height=.6)
245 pl.legend(loc='center left')
246 pl.yticks(x + 0.2, env_names)
247 pl.ylim(-0.4, len(envs))
248 pl.title("Research activity time by environment")
249 pl.xlabel("Fraction of submissions")
250 pl.subplots_adjust(right=0.97)
251 pl.savefig('%s/time_by_env.png' % destdir, format='png', dpi=80)
254 def mkpic_submissions_per_key(db, destdir, key, title, sortby='name',
256 counts = db.get_counts(key)
257 pl.figure(figsize=(6.4, (len(counts)-2) * 0.4 + 2))
258 tmargin = .8/len(counts)
259 if tmargin > 0.3: tmargin = 0.3
260 pl.subplots_adjust(left=0.03, right=0.97, top=1-tmargin, bottom=tmargin)
263 pl.text(.5, .5, "[Insufficient data for this figure]",
264 horizontalalignment='center')
269 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
270 elif sortby == 'count':
271 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
273 raise ValueError("Specify either name or count for sortby")
274 x = np.arange(len(stats))
275 pl.barh(x + (1./8), [s[1] for s in stats[::-1]], height=0.75, color = '#008200')
276 pl.yticks(x + 0.5, ['' for s in stats])
277 text_offset = pl.gca().get_xlim()[1] / 30.
278 for i, s in enumerate(stats[::-1]):
279 pl.text(text_offset, i+.5, db.get_nice_name(s[0]),
280 horizontalalignment='left',
281 verticalalignment='center',
282 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
283 pl.ylim(0, len(stats))
284 yl = "Number of submissions"
286 yl += "\n(multiple choices per submission possible)"
288 pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80)
291 def mkpic_software(db, destdir):
292 for typ in sw_categories.keys():
293 mkpic_submissions_per_key(
294 db, destdir, 'sw_%s' % typ,
295 title="Software popularity: %s" % db.get_nice_name(typ),
298 def mkpic_rating_by_os(db, env, items, destdir, title):
299 pl.figure(figsize=(6.4, 4.8))
300 for i, os in enumerate(os_order):
301 ratings = [db.select_match(env,
302 os_family[os]).get_not_none('%s' % (it,))[0]
304 plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
305 title=title, ylabel="Mean rating", label=db.get_nice_name(os))
307 pl.xlim((0,len(items)))
308 pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
309 pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
310 horizontalalignment='center')
311 pl.legend(loc='lower right')
312 pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
314 def mkpic_rating_by_os_hor_joined(db, env, items, destdir, title,
315 intro_sentence="I agree with the statements"):
318 #pl.figure(figsize=(6.4, 4.8))
320 rst = open('figures/ratings_%s.rst' % env, 'w')
331 """ % (title, '=' * len(title), intro_sentence))
332 for k, it in enumerate(items):
334 pl.figure(figsize=(3.2, 0.75))
336 pl.figure(figsize=(3.2, 0.5))
337 it_nice = db.get_nice_name(it)#.lstrip('.').lstrip(' ')
338 it_nice = it_nice[0].upper() + it_nice[1:]
339 for i, os in enumerate(os_order):
340 ratings = np.array(db.select_match(env,
341 os_family[os]).get_not_none('%s' % (it,))[0])
342 # assume that we have 4 grades from 0 to 3
344 assert(max(ratings) < max_rating)
345 # Complement with errorbar
347 meanstat = np.mean(ratings)
348 meanstat_point = per_os_width * (float(meanstat))/(max_rating-1)
349 # standard error of estimate
350 errstat = len(ratings) > 1 and np.std(ratings)/np.sqrt(len(ratings)-1) or 0
353 # Beautiful piece not yet appreciated by the audience
356 for r in range(max_rating):
357 stat = np.sum(ratings == r) * meanstat_point / float(total)
358 #print r, it, os, stat, total
359 #if it == "pers_r8" and os == "linux" and r == 3:
360 # import pydb; pydb.debugger()
361 kwargs = dict(label=None)
363 pl.barh(1.0/nos * (nos - 1 - i), stat, left=bottom, color=os_colors[i],
364 height=.25, alpha=0.25 + r/float(max_rating),
366 edgecolor=os_colors[i])
369 pl.barh(1.0/nos * (nos - 1 - i), meanstat_point, left=0,
370 color=os_colors[i], height=.25, alpha=1.0, label=None)
371 pl.errorbar([meanstat_point],
372 [1.0/nos * (nos - 0.5 - i)],
373 xerr=[errstat], fmt='o', color=os_colors[i], ecolor='k')
374 pl.xlim((0, per_os_width))
376 pl.text(0, 1.1, "Disagree", horizontalalignment='left')
377 pl.text(per_os_width, 1.1, "Agree", horizontalalignment='right')
382 pl.subplots_adjust(left=0.00, right=1., bottom=0.0, top=1,
383 wspace=0.05, hspace=0.05)
384 fname = '%s/ratings_%s_%s.png' % (destdir, env, it)
385 pl.savefig(fname, format='png', dpi=80)
387 oddrow_s = k % 2 == 0 and ' class="oddrow"' or ''
391 <td><img border="0" alt="%(fname)s" src="%(fname)s" /></td> </tr>"""
402 def main(srcdir, destdir):
404 if not os.path.exists(destdir):
407 mkpic_submissions_per_key(
408 db, destdir, 'virt_prod', sortby='name',
409 title='Virtualization product popularity\n(multiple choices per submission possible)')
411 mkpic_submissions_per_key(
412 db, destdir, 'bg_datamod', sortby='count',
413 title='Submissions per data modality\n(multiple choices per submission possible)')
415 mkpic_submissions_per_key(
416 db, destdir, 'bg_position', title='Submissions per position', sortby='count')
418 mkpic_submissions_per_key(
419 db, destdir, 'bg_country', title='Submissions per country', sortby='count')
421 mkpic_submissions_per_key(
422 db, destdir, 'bg_employer', title='Submissions per venue', sortby='count')
424 mkpic_submissions_per_key(
425 db, destdir, 'software_resource', title='Software resource popularity', sortby='count')
427 for pic in [mkpic_os_per_env, mkpic_software, mkpic_time_per_env]:
429 mkpic_rating_by_os_hor_joined(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
430 "Personal environment", "I prefer this particular scientific software environment because ...")
431 mkpic_rating_by_os_hor_joined(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
432 "Managed environment")
433 mkpic_rating_by_os_hor_joined(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
434 "Virtual environment (by host OS)")
436 # submission stats: this is RST
437 statsfile = open('%s/stats.txt' % destdir, 'w')
438 statsfile.write('::\n\n Number of submissions: %i\n' % len(db))
439 statsfile.write(' Statistics last updated: %s\n\n' \
440 % time.strftime('%A, %B %d %Y, %H:%M:%S UTC', time.gmtime()))
443 if __name__ == '__main__':
444 main(sys.argv[1], sys.argv[2])