-def mkpic_rating_by_os_hor(db, env, items, destdir, title):
- envs = ['pers_time', 'man_time', 'virt_time']
- env_names = ['Personal', 'Managed', 'Virtual']
- env_stats = {}
- for env in envs:
- counts = dict(zip(time_order, [0] * len(time_order)))
- counts.update(db.get_counts(env))
- total_count = np.sum(counts.values())
- for c in counts:
- counts[c] = float(counts[c]) / total_count
- env_stats[env] = counts
- # make stacked barplot
- pl.figure(figsize=(7.5, 4))
- 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]
+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
+ #pl.figure(figsize=(6.4, 4.8))
+ nos = len(os_order)
+ rst = open('figures/ratings_%s.rst' % env, 'w')
+ rst.write("""
+
+%s
+%s
+
+%s
+
+.. raw:: html
+
+ <table>
+ """ % (title, '=' * len(title), intro_sentence))
+ for k, it in enumerate(items):
+ 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
+ # Complement with errorbar
+ if len(ratings):
+ 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)],
+ [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))