Skip to content

Commit

Permalink
polar_rrrecord2txt: converts RR recording results to txt file (same f…
Browse files Browse the repository at this point in the history
…ormat as Polar Flow export feature)
  • Loading branch information
cmaion committed Jan 7, 2017
1 parent dd35263 commit cf31aaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A set of command line tools written in Ruby to interact with Polar watches and d
* download raw files
* backup complete content
* `polar_training2sml`: convert raw polar training sessions data files to the Suuntu SML file format
* `polar_rrrecord2test`: displays content of RR recording results test
* `polar_rrrecord2txt`: displays content of RR recording results and exports to txt file

Tested with:
* Polar M200
Expand Down Expand Up @@ -112,6 +112,17 @@ $ polar_ftp SYNC # Copy watch file system to ~/Polar/<device_id>
$ polar_training2sml ~/Polar/<device_id>/U/0/<YYYYMMDD>/E/<training_session_id>/ /tmp/output.sml
```


Read RR recording result and converts to txt file:

```sh
$ polar_rrrecord2txt <path/to/raw/polar/rr_record_result> [<output_txt_file>]

# Example:
$ polar_ftp SYNC # Copy watch file system to ~/Polar/<device_id>
$ polar_rrrecord2txt ~/Polar/<device_id>/U/0/<YYYYMMDD>/RRREC/<rr_record_id>/ /tmp/output.txt
```

## Author
[Cédric Maïon](https://github.com/cmaion)

Expand Down
26 changes: 19 additions & 7 deletions polar_rrrecord2test → polar_rrrecord2txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# Parses RAW Polar RR record result data files and prints some parsed data for testing purposes
# 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>"
puts " #{__FILE__} <directory> [<txt file>]"
end

dir = ARGV[0]
Expand All @@ -14,7 +14,9 @@ unless dir
exit -2
end

def output_test(parsed)
output_file = ARGV[1] || File.join(dir, 'output.txt')

def output_txt(parsed)
result = parsed[:result]
rr = parsed[:rr]

Expand All @@ -26,13 +28,23 @@ def output_test(parsed)
puts "Heart rate min: #{result.hr_min}"
puts "Heart rate avg: #{result.hr_avg}"
puts "Heart rate max: #{result.hr_max}"
puts "RR intervals :"
puts rr.rr_intervals.join(', ')
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)
output_test(parsed)
File.open(output_file, 'w') do |f|
f << output_txt(parsed)
end
puts "Done"
else
puts "Error: couldn't find RR record result"
puts "Error: couldn't find RR recording result"
end

0 comments on commit cf31aaa

Please sign in to comment.