-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_movement.py
79 lines (73 loc) · 2.33 KB
/
detect_movement.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
from correlate import *
def pravila(acc_data, times=[],
duration=0.5, debug=False):
""" Dobi acc_data
ob casih times
ali v zadnjem casu dolzine duration
debug vklopi vec outputov
"""
ret = ''
l = len(acc_data)
if not l:
return ret
if times != []:
endT = times[-1]
for i in range(l - a, -1, -1):
if (endT - times[i]) > duration:
startI = i
else:
startI = 0
else:
startI = 0
if max(acc_data[0][startI:]) > 500:
ret += 'dol '
if min(acc_data[0][startI:]) < -500:
ret += 'gor '
if max(acc_data[2][startI:]) > 250:
ret += 'ndesno '
if min(acc_data[2][startI:]) < -500:
ret += 'nlevo '
if min(acc_data[0][startI:]) < -300 and \
max(acc_data[0][startI:]) > 200 and \
max(acc_data[2][startI:]) > 200:
ret += 'obrat '
if min(acc_data[0][startI:]) < -900 and \
max(acc_data[0][startI:]) > 1100:
ret += 'metal '
ret = ret.strip()
if not debug:
return ret
r2 = ''
for i in range(3):
r2 += '{:^10}'.format("%.2f" % (min(acc_data[i][startI:])))
r2 += '{:^10}'.format("%.2f" % (max(acc_data[i][startI:])))
return ret, r2
def split_inputs(filename, sensor, splits):
mmax = 500
mmin = -500
times, data = parse(filename, sensor)
# dt = (times[-1] - times[0]) / len(times)
for i in range(3):
mmin = min(mmin, min(data[i]))
mmax = max(mmax, max(data[i]))
f, ax = plt.subplots(3, 1, sharex=True) # , sharey=True)
for i in range(3):
ax[i].plot(times, data[i], label=str(i))
# odvod = np.gradient(data[i], dt)
# ax[i].plot(times, odvod)
for j in splits:
pass
# ax[i].plot([j, j], [mmin, mmax], 'r-')
plt.xlim(min(times), max(times))
# plt.ylim(mmin, mmax)
f.set_size_inches(11, 5)
plt.savefig('head_movement_grafi/' +
filename.split('/')[1].split('.')[0] + '.png',
bbox_inches='tight', dpi=300)
if __name__ == "__main__":
sensor = '/muse/acc'
files = 'dol.csv gor.csv nagib-levo.csv nagib-desno.csv\
obrat-desno.csv obrat-levo.csv'.split()
for i in range(len(files)):
files[i] = 'data/' + files[i]
split_inputs(files[i], sensor, [2])