-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps.py
executable file
·71 lines (56 loc) · 1.65 KB
/
steps.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
#!/usr/bin/env python
import datetime
import matplotlib.pyplot as plt
from fitparse import FitFile
import sys
import os
from os import path
ff = FitFile(os.path.abspath(sys.argv[1]))
mm = ff.get_messages()
stepsc = []
acttimec = []
diffstepspertime = []
times = []
for m in mm:
try:
x = m.as_dict()['fields']
except:
continue
steps = None
time = None
acttime = None
if m.as_dict()['name'] != 'monitoring': continue
valid = False
count = False
for xx in x:
if xx['name'] == 'current_activity_type_intensity':
valid = True
if xx['name'] == 'activity_type':
if xx['value'] == 'walking':
count = True
if xx['value'] == 'running':
count = True
if xx['name'] == 'cycles':
steps = xx['raw_value']
if xx['name'] == 'timestamp_16':
time = xx['value']
if xx['name'] == 'active_time':
acttime = xx['value']
if valid and count and steps is not None and time is not None and acttime is not None:
stepsc.append(steps)
acttimec.append(acttime)
if len(stepsc) > 1:
times.append(time)
diffstepspertime.append(0)
ds = stepsc[-1] - stepsc[-2]
diffacttime = acttimec[-1] - acttimec[-2]
dspt = ds/diffacttime
times.append(time)
diffstepspertime.append(dspt)
times.append(time+diffacttime)
diffstepspertime.append(dspt)
times.append(time+diffacttime)
diffstepspertime.append(0)
import matplotlib
plt.plot(times,diffstepspertime)
plt.show()