-
Notifications
You must be signed in to change notification settings - Fork 1
/
lantern-analyze-all
executable file
·71 lines (66 loc) · 2.37 KB
/
lantern-analyze-all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
#
# This file is part of Lantern.
#
# Copyright 2015 Canonical Ltd.
# Written by:
# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
#
# Lantern is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3,
# as published by the Free Software Foundation.
#
# Lantern is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Lantern. If not, see <http://www.gnu.org/licenses/>.
import argparse
import json
import os
import statistics
import collections
def main():
parser = argparse.ArgumentParser()
parser.parse_args()
population = collections.defaultdict(list)
props = ('brightness', 'max_brightness', 'type')
stat_fns = ("mean", "median", "median_low", "median_high",
"median_grouped", "mode", "pstdev", "pvariance", "stdev",
"variance",)
for item in sorted(os.listdir('submissions-v1')):
if not item.endswith('.json'):
continue
filename = os.path.join('submissions-v1', item)
with open(filename, 'rt', encoding='UTF-8') as stream:
data = json.load(stream)
try:
bl_id_list = sorted(data['backlight'])
except KeyError:
continue
for bl_id in bl_id_list:
for prop in props:
try:
value = data['backlight'][bl_id][prop]
except KeyError:
continue
else:
population[prop].append(value)
population['num-devices'].append(len(bl_id_list))
for prop in sorted(population.keys()):
print("[{}]".format(prop))
print("population size", len(population[prop]))
print("population: ", population[prop])
for fn in stat_fns:
try:
stat = getattr(statistics, fn)(population[prop])
except TypeError:
pass
except statistics.StatisticsError as exc:
print("{:15} {}".format(fn, exc))
else:
print("{:15} {}".format(fn, stat))
if __name__ == '__main__':
main()