forked from cmaion/polar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolar_rrrecord2txt
executable file
·50 lines (42 loc) · 1.67 KB
/
polar_rrrecord2txt
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
#!/usr/bin/env ruby
# Converts RAW Polar RR recording result data files in txt file format (same format as Polar Flow export)
require "#{File.dirname(__FILE__)}/lib/polar_data_parser"
def usage
puts "Usage:"
puts " #{__FILE__} <directory> [<txt file>]"
end
dir = ARGV[0]
unless dir
usage
exit -2
end
output_file = ARGV[1] || File.join(dir, 'output.txt')
def output_txt(parsed)
result = parsed[:result]
rr = parsed[:rr]
start_time = DateTime.new(result.start_time.date.year, result.start_time.date.month, result.start_time.date.day, result.start_time.time.hour, result.start_time.time.minute, result.start_time.time.seconds, "%+i" % (result.start_time.time_zone_offset / 60)).to_time
end_time = DateTime.new(result.end_time.date.year, result.end_time.date.month, result.end_time.date.day, result.end_time.time.hour, result.end_time.time.minute, result.end_time.time.seconds, "%+i" % (result.end_time.time_zone_offset / 60)).to_time
puts "Started : #{start_time}"
puts "Ended : #{end_time}"
puts "Heart rate min: #{result.hr_min}"
puts "Heart rate avg: #{result.hr_avg}"
puts "Heart rate max: #{result.hr_max}"
time = 0.0
result = "0.000 #{(rr.rr_intervals.first.to_f / 1000).round(3)}\n"
rr.rr_intervals.each do |i|
i = i.to_f / 1000
time += i
result << "#{time.round(3)} #{i.round(3)}\n"
end
result
end
puts "Converting Polar RR recording result in '#{dir}' to TXT format as '#{output_file}'..."
parsed = PolarDataParser.parse_rr_recording_result(dir)
if parsed.key?(:result) && parsed.key?(:rr)
File.open(output_file, 'w') do |f|
f << output_txt(parsed)
end
puts "Done"
else
puts "Error: couldn't find RR recording result"
end