-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
54 lines (36 loc) · 1.56 KB
/
test.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
from mock import fetchTestMpuReading, postToRemoteDatabase, BASE_URL
CURRENT_TEST_KEY = "demo-3-test"
MPU1_RESOURCE_PATH = "pi/test1_mpu1"
MPU2_RESOURCE_PATH = "pi/test1_mpu2"
def printReadings(o):
print("MPU1 = x={x:.5f}, y={y:.5f}, z={z:.5f}".format(x=o[0].x, y=o[0].y, z=o[0].z))
print("MPU2 = x={x:.5f}, y={y:.5f}, z={z:.5f}".format(x=o[1].x, y=o[1].y, z=o[1].z))
def fetchReadings():
mpu1_readings = fetchTestMpuReading(timestamp, MPU1_RESOURCE_PATH)
mpu2_readings = fetchTestMpuReading(timestamp, MPU2_RESOURCE_PATH)
return [mpu1_readings, mpu2_readings]
def performSlouchDetection(result, t, r, n):
result.append([0, t, 50])
print("!!! Adding fake POSTURE event value=50")
print("!!! 0 " + str(t) + " " + str(50) + ";")
print("")
print('Reading mock MPU1 and MPU2 ...\n')
print('... from ' + BASE_URL + MPU1_RESOURCE_PATH)
print('... from ' + BASE_URL + MPU2_RESOURCE_PATH)
print('')
app_readings = []
timestamp = 0 # ms
while timestamp < 10000:
readings = fetchReadings()
print("Time = " + str(timestamp) + " (" + str(timestamp/1000) + "s)")
printReadings(readings)
output = []
normal = 0
performSlouchDetection(app_readings, timestamp, readings, normal)
timestamp += 500 # ms
# Upload to remote server
output = ';'.join(list(map(lambda x: ' '.join(list(map(lambda y: str(y), x))), app_readings)))
print("Uploading to remote server id=" + CURRENT_TEST_KEY + "...")
postToRemoteDatabase(CURRENT_TEST_KEY, output)
print("Uploaded to remote server, available at " + BASE_URL + "app/" + CURRENT_TEST_KEY)
print("")