+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
+
+ <table>
+ """ % (title, '=' * len(title), intro_sentence))
+ for k, it in enumerate(items):
+ 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])
+ #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)
+ 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_point], fmt='o', color=os_colors[i], ecolor='k')
+ pl.xlim((0, per_os_width))
+ 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.00, right=1., bottom=0.0, top=1,
+ wspace=0.05, hspace=0.05)
+ 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("""
+ <tr%(oddrow_s)s>
+ <td>%(it_nice)s</td>
+ <td><img border="0" alt="%(fname)s" src="%(fname)s" /></td> </tr>"""
+ % (locals()))
+
+ rst.write("""
+ </table>
+
+ """)
+ rst.close()
+ return
+