9 # some meaningful groups of OSes
10 redhat_family = ["rhel", "centos", "fedora", "scilinux"]
11 debian_family = ["debian", "ubuntu", "biolinux"]
12 suse_family = ["suse", "slel"]
13 other_linux_family = ["gentoo", "mandriva", "arch", "slackware", "otherlinux"]
14 other_family = ["starbsd", "unix", "qnx", "beos", "solaris", "other"]
26 'linux': redhat_family + debian_family + suse_family + other_linux_family,
27 'otheros': other_family
29 # end the reverse mapping
32 for os in os_family[ost]:
33 os_family_rev[os] = ost
37 def __init__(self, srcdir):
38 # eats the whole directory
39 datafilenames = glob('%s/*.json' % srcdir)
40 for dfn in datafilenames:
41 rawdata = json.load(open(dfn))
42 self[rawdata['timestamp']] = rawdata
44 self.os_dict = load_list2dict('oslist.txt')
46 def get_unique(self, key):
47 # return a set of all (unique) values for a field id
49 for d in self.values():
52 if isinstance(el, list):
55 uniq = uniq.union((el,))
58 def get_not_none(self, key):
59 # return a list of all values of a specific field id
60 # the second return value is count of submission that did not have data
64 for d in self.values():
67 if isinstance(el, list):
78 def get_counts(self, key):
79 # return a dict with field values as keys and respective submission
81 vals = self.get_not_none(key)[0]
82 uniq = np.unique(vals)
83 counts = dict(zip(uniq, [vals.count(u) for u in uniq]))
86 def select_match(self, key, values):
87 # return a db with all submissions were a field id has one of the
90 for k, v in self.items():
94 if isinstance(el, list):
95 if len(set(values).intersection(el)):
101 def get_nice_name(self, id):
102 srcs = [self.os_dict, os_cat_names]
106 # not found, nothing nicer
110 def load_list2dict(name):
115 d[kv[0]] = kv[1].strip().strip('"')
118 def mkpic_os_per_env(db, destdir):
119 envs = ['pers_os', 'man_os', 'virt_host_os', 'virt_guest_os']
120 env_names = ['Personal', 'Managed', 'Virt. Host', 'Virt. Guest']
124 counts = db.get_counts(env)
125 stats = dict(zip(os_family.keys(), [0] * len(os_family)))
127 stats[os_family_rev[os]] += counts[os]
128 total_count = np.sum(stats.values())
130 stats[osf] = float(stats[osf]) / total_count
131 env_stats[env] = stats
132 # make stacked barplot
133 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
134 x = np.arange(len(envs))
135 bottoms = np.zeros(len(envs))
136 os_order = ['linux', 'mac', 'win', 'otheros']
137 colors = ['#B63537', '#4E4DA0', '#008200', 'gray']
138 for i, os in enumerate(os_order):
139 stat = [env_stats[e][os] for e in envs]
140 pl.bar(x, stat, bottom=bottoms, color=colors[i],
141 label=db.get_nice_name(os), width=0.8)
143 pl.legend(loc='lower right')
144 pl.xticks(x + 0.4, [db.get_nice_name(e) for e in env_names])
145 pl.xlim(-0.25, len(envs))
146 pl.title("Operating system preference by environment")
147 pl.ylabel("Fraction of submissions")
148 pl.savefig('%s/ospref_by_env.png' % destdir, format='png')
150 def mkpic_submissions_per_datamod(db, destdir):
152 dmd = load_list2dict('datamodlist.txt')
153 spd = db.get_counts('bg_datamod')
154 spd = sorted(spd.items(), cmp=lambda x, y: cmp(x[1], y[1]))[::-1]
155 x = np.arange(len(spd))
156 pl.figure(figsize=(6.4, 4.8), facecolor='w', edgecolor='k')
157 pl.title('Submissions per data modality')
158 pl.bar(x, [s[1] for s in spd])
159 pl.xticks(x + 0.5, [dmd[k[0]] for k in spd], rotation=-10)
160 pl.ylabel('Survey submissions per data modality\n(multiple choices per submission possible)')
161 pl.savefig('%s/submissions_per_datamod.png' % destdir, format='png')
163 def main(srcdir, destdir):
165 for pic in [mkpic_submissions_per_datamod, mkpic_os_per_env]:
168 if __name__ == '__main__':
169 main(sys.argv[1], sys.argv[2])