-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathpolar_training2test
executable file
·210 lines (190 loc) · 9.57 KB
/
polar_training2test
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env ruby
# Parses RAW Polar training session data files and prints some parsed data for testing purposes
require "#{File.dirname(__FILE__)}/lib/polar_data_parser"
def usage
puts "Usage:"
puts " #{__FILE__} <directory>"
end
dir = ARGV[0]
unless dir
usage
exit -2
end
def output_test(parsed)
sport = parsed[:sport]
training_session = parsed[:training_session]
sensors = parsed[:sensors]
samples = parsed[:samples]
route_samples = parsed[:route_samples]
swimming_samples = parsed[:swimming_samples]
laps = parsed[:exercise_laps]
recording_interval = samples.recording_interval.hours * 3600 + samples.recording_interval.minutes * 60 + samples.recording_interval.seconds + (samples.recording_interval.millis.to_f / 1000)
samples_count = samples.speed_samples.count
route_samples_count = route_samples.latitude.count
laps_count = laps ? laps.laps.count : 0
puts "Training session: #{training_session.sport.value if training_session.sport} (#{training_session.session_name.text})"
puts "Sport: #{sport.identifier.value} (#{sport.translation.map { |t| t.text.text if t.id.language == 'en' }.compact.join('/')})"
puts "Notes: #{training_session.note.text}" if training_session.note && training_session.note.text != ''
puts "Start: #{pb_sysdatetime_to_string training_session.start, training_session.start.time_zone_offset}"
puts "GPS first fix: #{pb_sysdatetime_to_string route_samples.first_location_time}" if route_samples_count > 0
puts "Duration: #{pb_duration_to_string training_session.duration}"
puts "Distance: #{"%.1f" % training_session.distance}m"
puts "Geo: latitude #{training_session.latitude}/longitude #{training_session.longitude}"
puts "Heart rate: avg #{training_session.heart_rate.average}, max #{training_session.heart_rate.maximum}" if training_session.heart_rate
puts "Exercise samples: HR=#{samples.heart_rate_samples.count}, speed=#{samples.speed_samples.count}, cadence=#{samples.cadence_samples.count}, distance=#{samples.speed_samples.count}, alt=#{samples.altitude_samples.count}, temperature=#{samples.temperature_samples.count}, moving types=#{samples.moving_type_samples.count}, forward acc=#{samples.forward_acceleration.count}"
if samples.rr_samples
puts "RR intervals: #{samples.rr_samples.rr_intervals.join(',')}"
end
puts "Route samples: #{route_samples_count}"
if sensors
sensors.sensors.each do |sensor|
puts "Sensor used: #{sensor.mac.mac.unpack('H*').first.scan(/../).join(':') }"
end
end
if samples.pause_times && samples.pause_times.count > 0
r = []
samples.pause_times.each do |pause|
r << "#{pb_duration_to_string pause.start}: #{pb_duration_to_string pause.duration}"
end
puts "Pauses: #{r.join(', ')}"
end
puts "Altitude calibration samples:"
altitude_delta = 0
for i in 0..samples.altitude_calibration.count - 1
r = []
r << "start_index=#{samples.altitude_calibration[i].start_index}" if samples.altitude_calibration[i].start_index
r << "value=#{samples.altitude_calibration[i].value}" if samples.altitude_calibration[i].value
r << "operation=#{samples.altitude_calibration[i].operation}" if samples.altitude_calibration[i].operation
puts " #{r.join(', ')}"
if samples.altitude_calibration[i].operation == :SUM
altitude_delta = samples.altitude_calibration[i].value
else
STDERR.puts "Warning: Altitude calibration data of unsupported operation type ignored"
end
end
puts "Stride calibration samples:"
for i in 0..samples.stride_calibration.count - 1
r = []
r << "start_index=#{samples.stride_calibration[i].start_index}" if samples.stride_calibration[i].start_index
r << "value=#{samples.stride_calibration[i].value}" if samples.stride_calibration[i].value
r << "operation=#{samples.stride_calibration[i].operation}" if samples.stride_calibration[i].operation
puts " #{r.join(', ')}"
end
puts "Left power calibration samples:"
for i in 0..samples.left_power_calibration.count - 1
r = []
r << "start_index=#{samples.left_power_calibration[i].start_index}" if samples.left_power_calibration[i].start_index
r << "value=#{samples.left_power_calibration[i].value}" if samples.left_power_calibration[i].value
r << "operation=#{samples.left_power_calibration[i].operation}" if samples.left_power_calibration[i].operation
puts " #{r.join(', ')}"
end
puts "Right power calibration samples:"
for i in 0..samples.right_power_calibration.count - 1
r = []
r << "start_index=#{samples.right_power_calibration[i].start_index}" if samples.right_power_calibration[i].start_index
r << "value=#{samples.right_power_calibration[i].value}" if samples.right_power_calibration[i].value
r << "operation=#{samples.right_power_calibration[i].operation}" if samples.right_power_calibration[i].operation
puts " #{r.join(', ')}"
end
if samples.heart_rate_offline.count > 0
r = []
for i in 0..samples.heart_rate_offline.count - 1
r << "#{samples.heart_rate_offline[i].start_index}->#{samples.heart_rate_offline[i].stop_index}"
end
puts "HR OFFLINE: #{r.join(', ')}"
end
if samples.altitude_offline.count > 0
r = []
for i in 0..samples.altitude_offline.count - 1
r << "#{samples.altitude_offline[i].start_index}->#{samples.altitude_offline[i].stop_index}"
end
puts "Altitude OFFLINE: #{r.join(', ')}"
end
if samples.speed_offline.count > 0
r = []
for i in 0..samples.speed_offline.count - 1
r << "#{samples.speed_offline[i].start_index}->#{samples.speed_offline[i].stop_index}"
end
puts "Speed OFFLINE: #{r.join(', ')}"
end
if samples.cadence_offline.count > 0
r = []
for i in 0..samples.cadence_offline.count - 1
r << "#{samples.cadence_offline[i].start_index}->#{samples.cadence_offline[i].stop_index}"
end
puts "Cadence OFFLINE: #{r.join(', ')}"
end
if samples.distance_offline.count > 0
r = []
for i in 0..samples.distance_offline.count - 1
r << "#{samples.distance_offline[i].start_index}->#{samples.distance_offline[i].stop_index}"
end
puts "Distance OFFLINE: #{r.join(', ')}"
end
if samples.temperature_offline.count > 0
r = []
for i in 0..samples.temperature_offline.count - 1
r << "#{samples.temperature_offline[i].start_index}->#{samples.temperature_offline[i].stop_index}"
end
puts "Temperature OFFLINE: #{r.join(', ')}"
end
if samples.left_pedal_power_offline.count > 0
r = []
for i in 0..samples.left_pedal_power_offline.count - 1
r << "#{samples.left_pedal_power_offline[i].start_index}->#{samples.left_pedal_power_offline[i].stop_index}"
end
puts "Left power OFFLINE: #{r.join(', ')}"
end
if samples.right_pedal_power_offline.count > 0
r = []
for i in 0..samples.right_pedal_power_offline.count - 1
r << "#{samples.right_pedal_power_offline[i].start_index}->#{samples.right_pedal_power_offline[i].stop_index}"
end
puts "Right power OFFLINE: #{r.join(', ')}"
end
timestamp = Time.at(0).utc
for i in 0..samples_count-1
timestamp += recording_interval
r = []
r << timestamp.strftime("%H:%M:%S")
r << "#{"%7.1f" % samples.distance_samples[i]} m" if samples.distance_samples[i]
r << "#{"%3.2f" % (60.0 / samples.speed_samples[i])} min/km" if samples.speed_samples[i]
r << "HR=#{"%3.0f" % samples.heart_rate_samples[i]} bpm" if samples.heart_rate_samples[i]
r << "alt=#{"%4.1f" % samples.altitude_samples[i]}#{" (corrected=#{"%4.1f" % (samples.altitude_samples[i] + altitude_delta)})" if altitude_delta != 0} m" if samples.altitude_samples[i]
r << "temp=#{"%2.1f" % samples.temperature_samples[i]} °C" if samples.temperature_samples[i]
r << "cadence=#{samples.cadence_samples[i]}" if samples.cadence_samples[i]
r << "stride length=#{samples.stride_length_samples[i]}" if samples.stride_length_samples[i]
r << "left power=#{samples.left_pedal_power_samples[i].current_power}" if samples.left_pedal_power_samples[i]
r << "right power=#{samples.right_pedal_power_samples[i].current_power}" if samples.right_pedal_power_samples[i]
r << "forward acceleration=#{samples.forward_acceleration[i]}" if samples.forward_acceleration[i]
r << "moving type=#{samples.moving_type_samples[i]}" if samples.moving_type_samples[i]
puts r.join(', ')
end
if route_samples_count > 0
p = nil
for i in 0..route_samples_count-1
timestamp = Time.at(route_samples.duration[i].to_f / 1000).utc
puts "#{timestamp.strftime("%H:%M:%S")}, latitude=#{route_samples.latitude[i]}, longitude=#{route_samples.longitude[i]}, gps_altitude=#{route_samples.gps_altitude[i]}, satellites=#{route_samples.satellite_amount[i]}"
end
end
if swimming_samples && swimming_samples.pool_metric.count > 0
puts "Swimming samples:"
for i in 0..swimming_samples.pool_metric.count-1
puts "#{pb_duration_to_string swimming_samples.pool_metric[i].start_offset}: duration=#{pb_duration_to_string swimming_samples.pool_metric[i].duration}, style=#{swimming_samples.pool_metric[i].style}, strokes=#{swimming_samples.pool_metric[i].strokes}"
end
end
if laps_count > 0
puts "Laps: #{laps_count}"
puts "Best lap duration: #{pb_duration_to_string laps.summary.best_lap_duration}"
puts "Average lap duration: #{pb_duration_to_string laps.summary.average_lap_duration}"
laps.laps.each_with_index do |lap, i|
puts "#{pb_duration_to_string lap.header.split_time}, lap #{i + 1}: #{pb_duration_to_string lap.header.duration}, #{lap.header.distance} m"
end
end
end
parsed = PolarDataParser.parse_training_session(dir)
if parsed.key?(:training_session)
output_test(parsed)
else
puts "Error: couldn't find training session"
end