-
Notifications
You must be signed in to change notification settings - Fork 0
/
top_talker_strength_over_time.py
99 lines (74 loc) · 2.86 KB
/
top_talker_strength_over_time.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
import sqlite3
from matplotlib import pyplot
from matplotlib import ticker
from datetime import datetime
from operator import itemgetter
db = sqlite3.connect('signals_1.db')
cur = db.cursor()
ROWS = 3
COLS = 2
def do_plot(title, results, start_time, end_time):
# Assemble data into dictionaries/lists
macs = set()
strength_by_mac = {}
times_by_mac = {}
for mac, signal, time in results:
macs.add(mac)
if mac not in strength_by_mac:
strength_by_mac[mac] = []
if mac not in times_by_mac:
times_by_mac[mac] = []
time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
strength_by_mac[mac].append(signal / 100.0)
times_by_mac[mac].append(time)
# Sort times, filter macs with too few data points
filtered_macs = []
for mac in macs:
times = []
strengths = []
for time, strength in sorted(zip(times_by_mac[mac], strength_by_mac[mac]), key=itemgetter(0)):
if time not in times:
times.append(time)
strengths.append(strength)
times_by_mac[mac] = times
strength_by_mac[mac] = strengths
if len(times_by_mac[mac]) > 2:
filtered_macs.append(mac)
# Sort by the number of samples, to display the longest plots
lengths = [ len(times_by_mac[mac]) for mac in filtered_macs ]
filtered_macs = [ mac for _, mac in sorted(zip(lengths, filtered_macs), key=itemgetter(0), reverse=True) ]
colors = [
"red",
"green",
"blue",
"cyan",
"orange",
"magenta",
"brown",
"black",
"purple",
"teal",
]
fig, ax = pyplot.subplots(ROWS, COLS)
fig.suptitle(title, fontsize="x-large")
fig.tight_layout()
axf = ax.flatten()
for i, mac in enumerate(filtered_macs[ : int(ROWS * COLS) ]):
axf[i].set_title(mac)
axf[i].plot(times_by_mac[mac], strength_by_mac[mac], label=mac, marker='|', color=colors[i % len(colors)], linewidth=2)
axf[i].set_ylim([0, 1.1])
axf[i].yaxis.set_major_formatter(ticker.PercentFormatter(1))
axf[i].set_xlim([start_time, end_time])
print(mac, len(times_by_mac[mac]))
pyplot.show()
# Day1
day1_results = cur.execute("SELECT MAC, SIGNAL, TIME FROM SIGNALS_CLEAN WHERE TIME < DATE('2024-07-28')")
day1_start_time = datetime(2024, 7, 27, 12, 20)
day1_end_time = datetime(2024, 7, 27, 14, 50)
do_plot("Day 1", day1_results, day1_start_time, day1_end_time)
# Day2
day2_results = cur.execute("SELECT MAC, SIGNAL, TIME FROM SIGNALS_CLEAN WHERE TIME > DATE('2024-07-28')")
day2_start_time = datetime(2024, 8, 3, 17, 00)
day2_end_time = datetime(2024, 8, 3, 18, 20)
do_plot("Day 2", day2_results, day2_start_time, day2_end_time)