-
Notifications
You must be signed in to change notification settings - Fork 170
/
flatten.py
52 lines (39 loc) · 995 Bytes
/
flatten.py
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
#! /usr/bin/env python
import sys
from collections import defaultdict
# todo
# interval based summary
# tall vs wide vs super wide output
def help():
print("flatten.py input.csv")
print("turns any rtl_power csv into a more compact summary")
sys.exit()
if len(sys.argv) <= 1:
help()
if len(sys.argv) > 2:
help()
path = sys.argv[1]
sums = defaultdict(float)
counts = defaultdict(int)
def frange(start, stop, step):
i = 0
f = start
while f <= stop:
f = start + step*i
yield f
i += 1
for line in open(path):
line = line.strip().split(', ')
low = int(line[2])
high = int(line[3])
step = float(line[4])
weight = int(line[5])
dbm = [float(d) for d in line[6:]]
for f,d in zip(frange(low, high, step), dbm):
sums[f] += d*weight
counts[f] += weight
ave = defaultdict(float)
for f in sums:
ave[f] = sums[f] / counts[f]
for f in sorted(ave):
print(','.join([str(f), str(ave[f])]))