8 from mvpa.misc.plot.base import plot_bars
10 # uniform colors for OS results
11 os_colors = ['#B63537', '#4E4DA0', '#008200', 'gray']
12 os_order = ['linux', 'mac', 'win', 'otheros']
14 resource_categories = {
15 'vendor': 'Vendor/Project website',
16 'retailer': 'Retailer',
17 'os': 'Operating system',
22 'freebsdports': 'FreeBSD ports',
24 'macports': 'Macports',
25 'matlabcentral': 'Matlab Central',
26 'neurodebian': 'NeuroDebian',
29 'pythonbundles': 'Python bundles',
30 'sourceforge': 'Sourceforge',
31 'other': 'Other resource'
35 'general': 'General computing',
36 'dc': 'Distributed computing',
37 'img': 'Brain imaging',
38 'datamanage': 'Data management',
39 'neusys': 'Neural systems modeling',
40 'electro': 'Electrophysiology, MEG/EEG',
41 'bci': 'Brain-computer interface',
42 'acq': 'Hardware interface/Data acquisition',
43 'rt': 'Real-time solutions',
44 'psychophys': 'Psychophysics/Experiment control'
47 # some meaningful groups of OSes
48 redhat_family = ["rhel", "centos", "fedora", "scilinux"]
49 debian_family = ["debian", "ubuntu", "biolinux"]
50 suse_family = ["suse", "slel"]
51 other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"]
52 other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other"]
64 'linux': redhat_family + debian_family + suse_family + other_linux_family,
65 'otheros': other_family
67 # end the reverse mapping
70 for os in os_family[ost]:
71 os_family_rev[os] = ost
74 def load_list2dict(name):
79 d[kv[0]] = kv[1].strip().strip('"')
85 os_dict = load_list2dict('oslist.txt')
86 datamod_dict = load_list2dict('datamodlist.txt')
87 sw_dict = load_list2dict('swlist.txt')
89 def __init__(self, srcdir):
90 # eats the whole directory
93 datafilenames = glob('%s/*.json' % srcdir)
94 for dfn in datafilenames:
95 rawdata = json.load(open(dfn))
96 self[rawdata['timestamp']] = rawdata
98 def get_unique(self, key):
99 # return a set of all (unique) values for a field id
101 for d in self.values():
104 if isinstance(el, list):
105 uniq = uniq.union(el)
107 uniq = uniq.union((el,))
110 def get_not_none(self, key):
111 # return a list of all values of a specific field id
112 # the second return value is count of submission that did not have data
116 for d in self.values():
119 if isinstance(el, list):
130 def get_counts(self, key):
131 # return a dict with field values as keys and respective submission
133 vals = self.get_not_none(key)[0]
134 uniq = np.unique(vals)
135 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
138 def select_match(self, key, values):
139 # return a db with all submissions were a field id has one of the
142 for k, v in self.items():
146 if isinstance(el, list):
147 if len(set(values).intersection(el)):
153 def get_nice_name(self, id):
154 srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
159 # not found, nothing nicer
163 def mkpic_os_per_env(db, destdir):
164 envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
165 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
169 counts = db.get_counts(env)
170 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
172 stats[os_family_rev[os]] += counts[os]
173 total_count = np.sum(stats.values())
175 stats[osf] = float(stats[osf]) / total_count
176 env_stats[env] = stats
177 # make stacked barplot
178 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
179 x = np.arange(len(envs))
180 bottoms = np.zeros(len(envs))
181 for i, os in enumerate(os_order):
182 stat = [env_stats[e][os] for e in envs]
183 pl.bar(x, stat, bottom=bottoms, color=os_colors[i],
184 label=db.get_nice_name(os), width=0.8)
186 pl.legend(loc='lower right')
187 pl.xticks(x + 0.4, [db.get_nice_name(e) for e in env_names])
188 pl.xlim(-0.25, len(envs))
189 pl.title("Operating system preference by environment")
190 pl.ylabel("Fraction of submissions")
191 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
193 def mkpic_submissions_per_datamod(db, destdir):
195 spd = db.get_counts('bg_datamod')
196 spd = sorted(spd.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
197 x = np.arange(len(spd))
198 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
199 pl.title('Submissions per data modality')
200 pl.bar(x, [s[1] for s in spd])
201 pl.xticks(x + 0.5, [db.datamod_dict[k[0]] for k in spd], rotation=-10)
202 pl.ylabel('Survey submissions per data modality\n(multiple choices per submission possible)')
203 pl.savefig('%s/submissions_per_datamod.png' % destdir, format='png', dpi=80)
205 def mkpic_resources(db, destdir):
206 res = db.get_counts('software_resource')
208 x = np.arange(len(res))
209 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
210 pl.title('Software resources')
211 pl.bar(x + (1./8), [s[1] for s in res], width=0.75, color = '#008200')
212 pl.xticks(x + 0.5, ['' for s in res])
213 for i, s in enumerate(res):
214 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
215 horizontalalignment='center',
216 verticalalignment='bottom',
217 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white',
219 pl.ylabel('Number of submissions')
220 pl.savefig('%s/software_resources' % destdir, format='png', dpi=80)
222 def mkpic_software(db, destdir):
223 for typ in sw_categories.keys():
224 counts = db.get_counts('sw_%s' % typ)
225 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
226 pl.title("Software popularity: %s" % db.get_nice_name(typ))
228 pl.text(.5, .5, "[Insufficient data for this figure]",
229 horizontalalignment='center')
233 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
234 x = np.arange(len(stats))
235 pl.bar(x + (1./8), [s[1] for s in stats], width=0.75, color = '#008200')
236 pl.xticks(x + 0.5, ['' for s in stats])
237 for i, s in enumerate(stats):
238 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
239 horizontalalignment='center',
240 verticalalignment='bottom',
241 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white',
243 pl.xlim(0, len(stats))
244 pl.ylabel("Number of submissions")
245 pl.savefig('%s/sw_%s.png' % (destdir, typ), format='png', dpi=80)
247 def mkpic_rating_by_os(db, env, items, destdir, title):
248 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
249 for i, os in enumerate(os_order):
250 ratings = [db.select_match(env,
251 os_family[os]).get_not_none('%s' % (it,))[0]
253 plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
254 title=title, ylabel="Mean rating", label=db.get_nice_name(os))
256 pl.xlim((0,len(items)))
257 pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
258 pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
259 horizontalalignment='center')
260 pl.legend(loc='lower right')
261 pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
264 def main(srcdir, destdir):
266 for pic in [mkpic_submissions_per_datamod, mkpic_os_per_env, mkpic_software,
269 mkpic_rating_by_os(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
270 "Ratings: Personal environment")
271 mkpic_rating_by_os(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
272 "Ratings: Managed environment")
273 mkpic_rating_by_os(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
274 "Ratings: Virtual environment (by host OS)")
276 if __name__ == '__main__':
277 main(sys.argv[1], sys.argv[2])