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 = ['#B63537', '#4E4DA0', '#008200', 'gray']
20 os_order = ['linux', 'mac', 'win', 'otheros']
21 time_order = ['notime', 'little', 'most', 'always']
22 time_colors = ['#AA2029', '#D1942B', '#7FB142', '#69A7CE']
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"]
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):
95 d[kv[0]] = kv[1].strip().strip('"')
101 os_dict = load_list2dict('oslist.txt')
102 datamod_dict = load_list2dict('datamodlist.txt')
103 sw_dict = load_list2dict('swlist.txt')
105 def __init__(self, srcdir):
106 # eats the whole directory
109 datafilenames = glob('%s/*.json' % srcdir)
110 for dfn in datafilenames:
111 rawdata = jsonload(open(dfn))
112 self[rawdata['timestamp']] = rawdata
114 def get_unique(self, key):
115 # return a set of all (unique) values for a field id
117 for d in self.values():
120 if isinstance(el, list):
121 uniq = uniq.union(el)
123 uniq = uniq.union((el,))
126 def get_not_none(self, key):
127 # return a list of all values of a specific field id
128 # the second return value is count of submission that did not have data
132 for d in self.values():
135 if isinstance(el, list):
146 def get_counts(self, key):
147 # return a dict with field values as keys and respective submission
149 vals = self.get_not_none(key)[0]
150 uniq = np.unique(vals)
151 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
154 def select_match(self, key, values):
155 # return a db with all submissions were a field id has one of the
158 for k, v in self.items():
162 if isinstance(el, list):
163 if len(set(values).intersection(el)):
169 def get_nice_name(self, id):
170 srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
171 resource_categories, time_categories]
175 # not found, nothing nicer
179 def mkpic_os_per_env(db, destdir):
180 envs = ['pers', 'man', 'virt', 'virt']
181 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
184 counts = db.get_counts(env)
185 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
187 stats[os_family_rev[os]] += counts[os]
188 total_count = np.sum(stats.values())
190 stats[osf] = float(stats[osf]) / total_count
191 env_stats[env] = stats
192 # make stacked barplot
193 pl.figure(figsize=(6.4, 4.8))
194 x = np.arange(len(envs))
195 bottoms = np.zeros(len(envs))
196 for i, os in enumerate(os_order):
197 stat = [env_stats[e][os] for e in envs]
198 pl.bar(x, stat, bottom=bottoms, color=os_colors[i],
199 label=db.get_nice_name(os), width=0.8)
201 pl.legend(loc='lower right')
202 pl.xticks(x + 0.4, [db.get_nice_name(e) for e in env_names])
203 pl.xlim(-0.25, len(envs))
204 pl.title("Operating system preference by environment")
205 pl.ylabel("Fraction of submissions")
206 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
209 def mkpic_time_per_env(db, destdir):
210 envs = ['pers_time', 'man_time', 'virt_time']
211 env_names = ['Personal', 'Managed', 'Virtual']
214 counts = dict(zip(time_order, [0] * len(time_order)))
215 counts.update(db.get_counts(env))
216 total_count = np.sum(counts.values())
218 counts[c] = float(counts[c]) / total_count
219 env_stats[env] = counts
220 # make stacked barplot
221 pl.figure(figsize=(7.5, 4))
222 x = np.arange(len(envs))
223 bottoms = np.zeros(len(envs))
224 for i, t in enumerate(time_order):
225 stat = [env_stats[e][t] for e in envs]
226 pl.barh(x, stat, left=bottoms, color=time_colors[i],
227 label=db.get_nice_name(t), height=.6)
229 pl.legend(loc='center left')
230 pl.yticks(x + 0.2, env_names)
231 pl.ylim(-0.4, len(envs))
232 pl.title("Research activity time by environment")
233 pl.xlabel("Fraction of submissions")
234 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
237 def mkpic_submissions_per_datamod(db, destdir):
239 spd = db.get_counts('bg_datamod')
240 spd = sorted(spd.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
241 x = np.arange(len(spd))
242 pl.figure(figsize=(6.4, 4.8))
243 pl.title('Submissions per data modality')
244 pl.bar(x, [s[1] for s in spd])
245 pl.xticks(x + 0.5, [db.datamod_dict[k[0]] for k in spd], rotation=-10)
246 pl.ylabel('Survey submissions per data modality\n(multiple choices per submission possible)')
247 pl.savefig('%s/submissions_per_datamod.png' % destdir, format='png', dpi=80)
249 def mkpic_resources(db, destdir):
250 res = db.get_counts('software_resource')
252 x = np.arange(len(res))
253 pl.figure(figsize=(6.4, 4.8))
254 pl.title('Software resources')
255 pl.bar(x + (1./8), [s[1] for s in res], width=0.75, color = '#008200')
256 pl.xticks(x + 0.5, ['' for s in res])
257 for i, s in enumerate(res):
258 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
259 horizontalalignment='center',
260 verticalalignment='bottom',
261 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
262 pl.ylabel('Number of submissions')
263 pl.savefig('%s/software_resources.png' % destdir, format='png', dpi=80)
265 def mkpic_software(db, destdir):
266 for typ in sw_categories.keys():
267 counts = db.get_counts('sw_%s' % typ)
268 pl.figure(figsize=(6.4, 4.8))
269 pl.title("Software popularity: %s" % db.get_nice_name(typ))
271 pl.text(.5, .5, "[Insufficient data for this figure]",
272 horizontalalignment='center')
276 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
277 x = np.arange(len(stats))
278 pl.bar(x + (1./8), [s[1] for s in stats], width=0.75, color = '#008200')
279 pl.xticks(x + 0.5, ['' for s in stats])
280 for i, s in enumerate(stats):
281 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
282 horizontalalignment='center',
283 verticalalignment='bottom',
284 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
285 pl.xlim(0, len(stats))
286 pl.ylabel("Number of submissions")
287 pl.savefig('%s/sw_%s.png' % (destdir, typ), format='png', dpi=80)
289 def mkpic_rating_by_os(db, env, items, destdir, title):
290 pl.figure(figsize=(6.4, 4.8))
291 for i, os in enumerate(os_order):
292 ratings = [db.select_match(env,
293 os_family[os]).get_not_none('%s' % (it,))[0]
295 plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
296 title=title, ylabel="Mean rating", label=db.get_nice_name(os))
298 pl.xlim((0,len(items)))
299 pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
300 pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
301 horizontalalignment='center')
302 pl.legend(loc='lower right')
303 pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
306 def main(srcdir, destdir):
308 if not os.path.exists(destdir):
310 for pic in [mkpic_submissions_per_datamod, mkpic_os_per_env, mkpic_software,
311 mkpic_resources, mkpic_time_per_env]:
313 mkpic_rating_by_os(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
314 "Ratings: Personal environment")
315 mkpic_rating_by_os(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
316 "Ratings: Managed environment")
317 mkpic_rating_by_os(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
318 "Ratings: Virtual environment (by host OS)")
319 # submission stats: this is RST
320 statsfile = open('%s/stats.txt' % destdir, 'w')
321 statsfile.write('::\n\n Number of submissions: %i\n' % len(db))
322 statsfile.write(' Statistics last updated: %s\n\n' \
323 % time.strftime('%A, %B %d %Y, %H:%M:%S UTC', time.gmtime()))
326 if __name__ == '__main__':
327 main(sys.argv[1], sys.argv[2])