5 from json import load as jload
9 from json import read as jread
11 return jread(f.read())
17 # uniform colors for OS results
18 os_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE']
19 os_order = ['linux', 'mac', 'win', 'otheros']
20 time_order = ['notime', 'little', 'most', 'always']
21 time_colors = ['#FF0000', '#FF5500', '#FFAC00', '#FFFD08']
23 'notime': "don't use it",
24 'little': "less than 50%",
25 'most': "more than 50%",
29 resource_categories = {
30 'vendor': 'Vendor/Project website',
31 'retailer': 'Retailer',
32 'os': 'Operating system',
37 'freebsdports': 'FreeBSD ports',
39 'macports': 'Macports',
40 'matlabcentral': 'Matlab Central',
41 'neurodebian': 'NeuroDebian',
44 'pythonbundles': 'Python bundles',
45 'sourceforge': 'Sourceforge',
46 'otherres': 'Other resource'
50 'general': 'General computing',
51 'dc': 'Distributed computing',
52 'img': 'Brain imaging',
53 'datamanage': 'Data management',
54 'neusys': 'Neural systems modeling',
55 'electro': 'Electrophysiology, MEG/EEG',
56 'bci': 'Brain-computer interface',
57 'acq': 'Hardware interface/Data acquisition',
58 'rt': 'Real-time solutions',
59 'psychphys': 'Psychophysics/Experiment control'
62 # some meaningful groups of OSes
63 redhat_family = ["rhel", "centos", "fedora", "scilinux"]
64 debian_family = ["debian", "ubuntu", "biolinux"]
65 suse_family = ["suse", "slel"]
66 other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"]
67 other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other", "dontknow"]
79 'linux': redhat_family + debian_family + suse_family + other_linux_family,
80 'otheros': other_family
82 # end the reverse mapping
85 for os_ in os_family[ost]:
86 os_family_rev[os_] = ost
89 def load_list2dict(name):
93 if line.strip() == "":
98 "Got a line %s with a duplicate key %s whenever value for it "
99 "is known already to be %r" % (line, kv[0], d[kv[0]]))
100 d[kv[0]] = kv[1].strip().strip('"')
106 os_dict = load_list2dict('oslist.txt')
107 datamod_dict = load_list2dict('datamodlist.txt')
108 sw_dict = load_list2dict('swlist.txt')
109 position_dict = load_list2dict('position-dd-list.txt')
110 employer_dict = load_list2dict('employer-dd-list.txt')
111 ratings_dict = load_list2dict('ratingslist.txt')
112 vm_dict = load_list2dict('vmlist.txt')
114 def __init__(self, srcdir):
115 # eats the whole directory
118 datafilenames = glob('%s/*.json' % srcdir)
119 for dfn in datafilenames:
120 rawdata = jsonload(open(dfn))
121 self[rawdata['timestamp']] = rawdata
123 def get_unique(self, key):
124 # return a set of all (unique) values for a field id
126 for d in self.values():
129 if isinstance(el, list):
130 uniq = uniq.union(el)
132 uniq = uniq.union((el,))
135 def get_not_none(self, key):
136 # return a list of all values of a specific field id
137 # the second return value is count of submission that did not have data
141 for d in self.values():
144 if isinstance(el, list):
155 def get_counts(self, key, predef_keys=None):
156 # return a dict with field values as keys and respective submission
158 vals = self.get_not_none(key)[0]
159 uniq = np.unique(vals)
160 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
161 if not predef_keys is None:
162 ret = dict(zip(predef_keys, [0] * len(predef_keys)))
168 def select_match(self, key, values):
169 # return a db with all submissions were a field id has one of the
172 for k, v in self.items():
176 if isinstance(el, list):
177 if len(set(values).intersection(el)):
183 def get_nice_name(self, id):
184 srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
185 resource_categories, time_categories,
186 DB.datamod_dict, DB.position_dict, DB.employer_dict,
187 DB.vm_dict, DB.ratings_dict]
191 # not found, nothing nicer
195 def mkpic_os_per_env(db, destdir):
196 envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
197 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
200 counts = db.get_counts(env)
201 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
203 stats[os_family_rev[os]] += counts[os]
204 total_count = np.sum(stats.values())
209 stats[osf] = float(stats[osf]) / total_count
210 env_stats[env] = stats
211 # make stacked barplot
212 pl.figure(figsize=(7.5, 4))
213 x = np.arange(len(envs))
214 bottoms = np.zeros(len(envs))
215 for i, os in enumerate(os_order):
216 stat = [env_stats[e][os] for e in envs[::-1]]
217 pl.barh(x, stat, left=bottoms, color=os_colors[i],
218 label=db.get_nice_name(os), height=0.8)
220 pl.legend(loc='center left')
221 pl.yticks(x + 0.4, env_names[::-1])
222 pl.ylim(-0.25, len(envs))
224 pl.title("Operating system preference by environment")
225 pl.xlabel("Fraction of submissions")
226 pl.subplots_adjust(left=0.15, right=0.97)
227 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
230 def mkpic_time_per_env(db, destdir):
231 envs = ['pers_time', 'man_time', 'virt_time']
232 env_names = ['Personal', 'Managed', 'Virtual']
235 counts = dict(zip(time_order, [0] * len(time_order)))
236 counts.update(db.get_counts(env))
237 total_count = np.sum(counts.values())
239 counts[c] = float(counts[c]) / total_count
240 env_stats[env] = counts
241 # make stacked barplot
242 pl.figure(figsize=(7.5, 4))
243 x = np.arange(len(envs))
244 bottoms = np.zeros(len(envs))
245 for i, t in enumerate(time_order):
246 stat = [env_stats[e][t] for e in envs[::-1]]
247 pl.barh(x, stat, left=bottoms, color=time_colors[i],
248 label=db.get_nice_name(t), height=.6)
250 pl.legend(loc='lower left')
251 pl.yticks(x + 0.2, env_names[::-1])
252 pl.ylim(-0.4, len(envs))
253 pl.title("Research activity time by environment")
254 pl.xlabel("Fraction of submissions")
255 pl.subplots_adjust(right=0.97)
256 pl.savefig('%s/time_by_env.png' % destdir, format='png', dpi=80)
259 def mkpic_submissions_per_key(db, destdir, key, title, sortby='name',
261 counts = db.get_counts(key)
262 pl.figure(figsize=(6.4, (len(counts)-2) * 0.4 + 2))
263 if not len(counts): tmargin = 0.4
264 else: tmargin = .8/len(counts)
265 if tmargin > 0.3: tmargin = 0.3
266 pl.subplots_adjust(left=0.03, right=0.97, top=1-tmargin, bottom=tmargin)
269 pl.text(.5, .5, "[Insufficient data for this figure]",
270 horizontalalignment='center')
275 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
276 elif sortby == 'count':
277 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
279 raise ValueError("Specify either name or count for sortby")
280 x = np.arange(len(stats))
281 pl.barh(x + (1./8), [s[1] for s in stats[::-1]], height=0.75, color = '#008200')
282 pl.yticks(x + 0.5, ['' for s in stats])
283 text_offset = pl.gca().get_xlim()[1] / 30.
284 for i, s in enumerate(stats[::-1]):
285 pl.text(text_offset, i+.5, db.get_nice_name(s[0]) + " [%d]" % (s[1],),
286 horizontalalignment='left',
287 verticalalignment='center',
288 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
289 pl.ylim(0, len(stats))
290 yl = "Number of submissions"
292 yl += "\n(multiple choices per submission possible)"
294 pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80)
297 def mkpic_software(db, destdir):
298 for typ in sw_categories.keys():
299 mkpic_submissions_per_key(
300 db, destdir, 'sw_%s' % typ,
301 title="Software popularity: %s" % db.get_nice_name(typ),
304 def mkpic_rating_by_os(db, env, items, destdir, title):
305 from mvpa.misc.plot.base import plot_bars
307 pl.figure(figsize=(6.4, 4.8))
308 for i, os in enumerate(os_order):
309 ratings = [db.select_match(env,
310 os_family[os]).get_not_none('%s' % (it,))[0]
312 plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
313 title=title, ylabel="Mean rating", label=db.get_nice_name(os))
315 pl.xlim((0,len(items)))
316 pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
317 pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
318 horizontalalignment='center')
319 pl.legend(loc='lower right')
320 pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
322 def mkpic_rating_by_os_hor_joined(db, env, items, destdir, title,
323 intro_sentence="I agree with the statements"):
326 #pl.figure(figsize=(6.4, 4.8))
328 rst = open('figures/ratings_%s.rst' % env, 'w')
339 """ % (title, '=' * len(title), intro_sentence))
340 for k, it in enumerate(items):
342 pl.figure(figsize=(3.2, 0.75))
344 pl.figure(figsize=(3.2, 0.5))
345 it_nice = db.get_nice_name(it)#.lstrip('.').lstrip(' ')
346 it_nice = it_nice[0].upper() + it_nice[1:]
347 for i, os in enumerate(os_order):
348 ratings = np.array(db.select_match(env,
349 os_family[os]).get_not_none('%s' % (it,))[0])
350 # assume that we have 4 grades from 0 to 3
352 assert(max(ratings) < max_rating)
353 # Complement with errorbar
355 meanstat = np.mean(ratings)
356 meanstat_point = per_os_width * (float(meanstat))/(max_rating-1)
357 # standard error of estimate
358 errstat = len(ratings) > 1 and np.std(ratings)/np.sqrt(len(ratings)-1) or 0
361 # Beautiful piece not yet appreciated by the audience
364 for r in range(max_rating):
365 stat = np.sum(ratings == r) * meanstat_point / float(total)
366 #print r, it, os, stat, total
367 #if it == "pers_r8" and os == "linux" and r == 3:
368 # import pydb; pydb.debugger()
369 kwargs = dict(label=None)
371 pl.barh(1.0/nos * (nos - 1 - i), stat, left=bottom, color=os_colors[i],
372 height=.25, alpha=0.25 + r/float(max_rating),
374 edgecolor=os_colors[i])
377 pl.barh(1.0/nos * (nos - 1 - i), meanstat_point, left=0,
378 color=os_colors[i], height=.25, alpha=1.0, label=None)
379 pl.errorbar([meanstat_point],
380 [1.0/nos * (nos - 0.5 - i)],
381 xerr=[errstat], fmt='o', color=os_colors[i], ecolor='k')
382 pl.xlim((0, per_os_width))
384 pl.text(0, 1.1, "Disagree", horizontalalignment='left')
385 pl.text(per_os_width, 1.1, "Agree", horizontalalignment='right')
390 pl.subplots_adjust(left=0.00, right=1., bottom=0.0, top=1,
391 wspace=0.05, hspace=0.05)
392 fname = '%s/ratings_%s_%s.png' % (destdir, env, it)
393 pl.savefig(fname, format='png', dpi=80)
395 oddrow_s = k % 2 == 0 and ' class="oddrow"' or ''
399 <td><img border="0" alt="%(fname)s" src="%(fname)s" /></td> </tr>"""
410 def main(srcdir, destdir):
412 if not os.path.exists(destdir):
415 mkpic_submissions_per_key(
416 db, destdir, 'virt_prod', sortby='count',
417 title='Virtualization product popularity')
419 mkpic_submissions_per_key(
420 db, destdir, 'bg_datamod', sortby='count',
421 title='Submissions per data modality')
423 mkpic_submissions_per_key(
424 db, destdir, 'bg_position', title='Submissions per position', sortby='count')
426 mkpic_submissions_per_key(
427 db, destdir, 'bg_country', title='Submissions per country', sortby='count')
429 mkpic_submissions_per_key(
430 db, destdir, 'bg_employer', title='Submissions per venue', sortby='count')
432 mkpic_submissions_per_key(
433 db, destdir, 'software_resource', title='Software resource popularity', sortby='count')
435 for pic in [mkpic_os_per_env, mkpic_software, mkpic_time_per_env]:
437 mkpic_rating_by_os_hor_joined(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
438 "Personal environment", "I prefer this particular scientific software environment because ...")
439 mkpic_rating_by_os_hor_joined(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
440 "Managed environment")
441 mkpic_rating_by_os_hor_joined(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
442 "Virtual environment (by host OS)")
444 # submission stats: this is RST
445 statsfile = open('%s/stats.txt' % destdir, 'w')
446 statsfile.write('::\n\n Number of submissions: %i\n' % len(db))
447 statsfile.write(' Statistics last updated: %s\n\n' \
448 % time.strftime('%A, %B %d %Y, %H:%M:%S UTC', time.gmtime()))
451 if __name__ == '__main__':
452 main(sys.argv[1], sys.argv[2])