/
garmin-ruuning-visualization.py
89 lines (61 loc) · 2.38 KB
/
garmin-ruuning-visualization.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
import pandas as pd
from bokeh.plotting import figure, show, output_file, ColumnDataSource
from bokeh.models import HoverTool
from bokeh.models.formatters import DatetimeTickFormatter
from bokeh.models.ranges import Range1d
from bokeh.models.axes import LinearAxis
from lxml import etree
from dateutil import parser
# Get data from .tcx
tree = etree.parse("activity_4019358445.tcx")
root = tree.getroot()
points = root.findall('.//Trackpoint', root.nsmap)
all_data = []
for pt in points:
t = pt.find('./Time', root.nsmap)
bmp = pt.find('./HeartRateBpm/Value', root.nsmap)
cad = pt.find('./Extensions/ns3:TPX/ns3:RunCadence', root.nsmap)
dis = pt.find('./DistanceMeters', root.nsmap)
spd = pt.find('./Extensions/ns3:TPX/ns3:Speed', root.nsmap)
all_data.append( { 'time' : parser.parse(t.text),
'bmp' : int(bmp.text),
'cad' : float(cad.text),
'dis' : float(dis.text),
'spd' : float(spd.text)
}
)
# Visualize
output_file("final.html")
df = pd.DataFrame(all_data)
hover = HoverTool(
tooltips=[
( 'time', '@time{%R}'),
( 'bmp', '@bmp{000.}'),
( 'cad', '@cad'),
( 'spd', '@spd')
],
formatters={
'time' : 'datetime',
},
mode='vline'
)
p = figure(x_axis_type="datetime", plot_width=600, plot_height=300, tools=[hover], title="all-data_time_hover")
# range for each data field
p.y_range = Range1d(0, 220) # bmp
p.extra_y_ranges = {"cad": Range1d(start=0, end=140), # RunCadence
"spd": Range1d(start=0, end=10.0) } # Speed
# add the extra range to the right of the plot
p.add_layout(LinearAxis(y_range_name="cad"), 'right')
p.add_layout(LinearAxis(y_range_name="spd"), 'right')
# set axis text color
p.yaxis[0].major_label_text_color = "red"
p.yaxis[1].major_label_text_color = "blue"
p.yaxis[2].major_label_text_color = "purple"
## plot !
p.line(df['time'], df['bmp'], legend='bmp', line_color="red", muted_color='red', muted_alpha=0.2)
p.line(df['time'], df['cad'], legend='cad', line_color="blue", muted_color='blue', muted_alpha=0.2, y_range_name='cad')
p.line(df['time'], df['spd'], legend='spd', color="purple", muted_color='purple', muted_alpha=0.2, y_range_name='spd')
# setting for legend
p.legend.location = "top_right"
p.legend.click_policy="mute"
show(p)