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']
22 resource_categories = {
23 'vendor': 'Vendor/Project website',
24 'retailer': 'Retailer',
25 'os': 'Operating system',
30 'freebsdports': 'FreeBSD ports',
32 'macports': 'Macports',
33 'matlabcentral': 'Matlab Central',
34 'neurodebian': 'NeuroDebian',
37 'pythonbundles': 'Python bundles',
38 'sourceforge': 'Sourceforge',
39 'other': 'Other resource'
43 'general': 'General computing',
44 'dc': 'Distributed computing',
45 'img': 'Brain imaging',
46 'datamanage': 'Data management',
47 'neusys': 'Neural systems modeling',
48 'electro': 'Electrophysiology, MEG/EEG',
49 'bci': 'Brain-computer interface',
50 'acq': 'Hardware interface/Data acquisition',
51 'rt': 'Real-time solutions',
52 'psychophys': 'Psychophysics/Experiment control'
55 # some meaningful groups of OSes
56 redhat_family = ["rhel", "centos", "fedora", "scilinux"]
57 debian_family = ["debian", "ubuntu", "biolinux"]
58 suse_family = ["suse", "slel"]
59 other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"]
60 other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other"]
72 'linux': redhat_family + debian_family + suse_family + other_linux_family,
73 'otheros': other_family
75 # end the reverse mapping
78 for os_ in os_family[ost]:
79 os_family_rev[os_] = ost
82 def load_list2dict(name):
87 d[kv[0]] = kv[1].strip().strip('"')
93 os_dict = load_list2dict('oslist.txt')
94 datamod_dict = load_list2dict('datamodlist.txt')
95 sw_dict = load_list2dict('swlist.txt')
97 def __init__(self, srcdir):
98 # eats the whole directory
101 datafilenames = glob('%s/*.json' % srcdir)
102 for dfn in datafilenames:
103 rawdata = jsonload(open(dfn))
104 self[rawdata['timestamp']] = rawdata
106 def get_unique(self, key):
107 # return a set of all (unique) values for a field id
109 for d in self.values():
112 if isinstance(el, list):
113 uniq = uniq.union(el)
115 uniq = uniq.union((el,))
118 def get_not_none(self, key):
119 # return a list of all values of a specific field id
120 # the second return value is count of submission that did not have data
124 for d in self.values():
127 if isinstance(el, list):
138 def get_counts(self, key):
139 # return a dict with field values as keys and respective submission
141 vals = self.get_not_none(key)[0]
142 uniq = np.unique(vals)
143 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
146 def select_match(self, key, values):
147 # return a db with all submissions were a field id has one of the
150 for k, v in self.items():
154 if isinstance(el, list):
155 if len(set(values).intersection(el)):
161 def get_nice_name(self, id):
162 srcs = [DB.os_dict, os_cat_names, DB.sw_dict, sw_categories,
163 resource_categories, DB.datamod_dict]
167 # not found, nothing nicer
171 def mkpic_os_per_env(db, destdir):
172 envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
173 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
177 counts = db.get_counts(env)
178 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
180 stats[os_family_rev[os]] += counts[os]
181 total_count = np.sum(stats.values())
183 stats[osf] = float(stats[osf]) / total_count
184 env_stats[env] = stats
185 # make stacked barplot
186 pl.figure(figsize=(6.4, 4.8))
187 x = np.arange(len(envs))
188 bottoms = np.zeros(len(envs))
189 for i, os in enumerate(os_order):
190 stat = [env_stats[e][os] for e in envs]
191 pl.bar(x, stat, bottom=bottoms, color=os_colors[i],
192 label=db.get_nice_name(os), width=0.8)
194 pl.legend(loc='lower right')
195 pl.xticks(x + 0.4, [db.get_nice_name(e) for e in env_names])
196 pl.xlim(-0.25, len(envs))
197 pl.title("Operating system preference by environment")
198 pl.ylabel("Fraction of submissions")
199 pl.savefig('%s/ospref_by_env.png' % destdir, format='png', dpi=80)
202 def mkpic_submissions_per_key(db, destdir, key, title, sortby='name',
204 counts = db.get_counts(key)
205 pl.figure(figsize=(6.4, 4.8))
208 pl.text(.5, .5, "[Insufficient data for this figure]",
209 horizontalalignment='center')
214 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[0], y[0]))
215 elif sortby == 'count':
216 stats = sorted(counts.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
218 raise ValueError("Specify either name or count for sortby")
219 x = np.arange(len(stats))
220 pl.bar(x + (1./8), [s[1] for s in stats], width=0.75, color = '#008200')
221 pl.xticks(x + 0.5, ['' for s in stats])
222 for i, s in enumerate(stats):
223 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
224 horizontalalignment='center',
225 verticalalignment='bottom',
226 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
227 pl.xlim(0, len(stats))
228 yl = "Number of submissions"
230 yl += "\n(multiple choices per submission possible)"
232 pl.savefig('%s/submissions_per_%s.png' % (destdir, key), format='png', dpi=80)
235 def mkpic_resources(db, destdir):
236 res = db.get_counts('software_resource')
238 x = np.arange(len(res))
239 pl.figure(figsize=(6.4, 4.8))
240 pl.title('Software resources')
241 pl.bar(x + (1./8), [s[1] for s in res], width=0.75, color = '#008200')
242 pl.xticks(x + 0.5, ['' for s in res])
243 for i, s in enumerate(res):
244 pl.text(i+.5, 0.1, db.get_nice_name(s[0]), rotation=90,
245 horizontalalignment='center',
246 verticalalignment='bottom',
247 bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
248 pl.ylabel('Number of submissions')
249 pl.savefig('%s/software_resources.png' % destdir, format='png', dpi=80)
251 def mkpic_software(db, destdir):
252 for typ in sw_categories.keys():
253 mkpic_submissions_per_key(
254 db, destdir, 'sw_%s' % typ,
255 title="Software popularity: %s" % db.get_nice_name(typ),
258 def mkpic_rating_by_os(db, env, items, destdir, title):
259 pl.figure(figsize=(6.4, 4.8))
260 for i, os in enumerate(os_order):
261 ratings = [db.select_match(env,
262 os_family[os]).get_not_none('%s' % (it,))[0]
264 plot_bars(ratings, offset=((i+1)*0.2)-0.1, color=os_colors[i],
265 title=title, ylabel="Mean rating", label=db.get_nice_name(os))
267 pl.xlim((0,len(items)))
268 pl.yticks((0, 3), ['Disagree', 'Agree'], rotation=90)
269 pl.xticks(np.arange(len(items))+0.5, [i[-2:] for i in items],
270 horizontalalignment='center')
271 pl.legend(loc='lower right')
272 pl.savefig('%s/ratings_%s.png' % (destdir, env), format='png', dpi=80)
275 def main(srcdir, destdir):
277 if not os.path.exists(destdir):
280 mkpic_submissions_per_key(
281 db, destdir, 'bg_datamod', sortby='count',
282 title='Submissions per data modality\n(multiple choices per submission possible)')
284 mkpic_submissions_per_key(
285 db, destdir, 'bg_position', title='Submissions per position', sortby='count')
287 mkpic_submissions_per_key(
288 db, destdir, 'bg_country', title='Submissions per country', sortby='count')
290 mkpic_submissions_per_key(
291 db, destdir, 'bg_employer', title='Submissions per venue', sortby='count')
293 for pic in [mkpic_os_per_env, mkpic_software,
296 mkpic_rating_by_os(db, 'pers_os', ['pers_r%i' % i for i in range(1, 9)], destdir,
297 "Ratings: Personal environment")
298 mkpic_rating_by_os(db, 'man_os', ['man_r%i' % i for i in range(1, 5)], destdir,
299 "Ratings: Managed environment")
300 mkpic_rating_by_os(db, 'virt_host_os', ['virt_r%i' % i for i in range(1, 4)], destdir,
301 "Ratings: Virtual environment (by host OS)")
302 # submission stats: this is RST
303 statsfile = open('%s/stats.txt' % destdir, 'w')
304 statsfile.write('::\n\n Number of submissions: %i\n' % len(db))
305 statsfile.write(' Statistics last updated: %s\n\n' \
306 % time.strftime('%A, %B %d %Y, %H:%M:%S UTC', time.gmtime()))
309 if __name__ == '__main__':
310 main(sys.argv[1], sys.argv[2])