-def mkpic_submissions_per_datamod(db, destdir):
- # simple demo
- spd = db.get_counts('bg_datamod')
- spd = sorted(spd.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
- x = np.arange(len(spd))
- pl.figure(figsize=(6.4, 4.8))
- pl.title('Submissions per data modality')
- pl.bar(x, [s[1] for s in spd])
- pl.xticks(x + 0.5, [db.datamod_dict[k[0]] for k in spd], rotation=-10)
- pl.ylabel('Survey submissions per data modality\n(multiple choices per submission possible)')
- pl.savefig('%s/submissions_per_datamod.png' % destdir, format='png', dpi=80)
-
-def mkpic_resources(db, destdir):
- res = db.get_counts('software_resource')
- res = res.items()
- x = np.arange(len(res))
- pl.figure(figsize=(6.4, 4.8))
- pl.title('Software resources')
- pl.bar(x + (1./8), [s[1] for s in res], width=0.75, color = '#008200')
- pl.xticks(x + 0.5, ['' for s in res])
- for i, s in enumerate(res):
- pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
- horizontalalignment='center',
- verticalalignment='bottom',
- bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
- pl.ylabel('Number of submissions')
- pl.savefig('%s/software_resources.png' % destdir, format='png', dpi=80)
+
+def mkpic_time_per_env(db, destdir):
+ 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]
+ pl.barh(x, stat, left=bottoms, color=time_colors[i],
+ label=db.get_nice_name(t), height=.6)
+ bottoms += stat
+ pl.legend(loc='upper left')
+ pl.yticks(x + 0.2, env_names)
+ pl.ylim(-0.4, len(envs))
+ pl.title("Research activity time by environment")
+ pl.xlabel("Fraction of submissions")
+ pl.subplots_adjust(right=0.97)
+ pl.savefig('%s/time_by_env.png' % destdir, format='png', dpi=80)
+
+
+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))
+ 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)
+ if not len(counts):
+ pl.text(.5, .5, "[Insufficient data for this figure]",
+ horizontalalignment='center')
+ pl.axis('off')
+ else:
+ # sort by name
+ if sortby == 'name':
+ stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
+ elif sortby == 'count':
+ stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
+ else:
+ raise ValueError("Specify either name or count for sortby")
+ x = np.arange(len(stats))
+ pl.barh(x + (1./8), [s[1] for s in stats[::-1]], height=0.75, color = '#008200')
+ 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]) + " [%d]" % (s[1],),
+ horizontalalignment='left',
+ verticalalignment='center',
+ bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
+ pl.ylim(0, len(stats))
+ yl = "Number of submissions"
+ if multiple:
+ yl += "\n(multiple choices per submission possible)"
+ pl.xlabel(yl)
+ pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80)
+