From cf31aaad665791fb317d27e4eee10795a0df001f Mon Sep 17 00:00:00 2001 From: Cedric Maion Date: Sat, 7 Jan 2017 15:21:48 +0100 Subject: [PATCH] polar_rrrecord2txt: converts RR recording results to txt file (same format as Polar Flow export feature) --- README.md | 13 +++++++++++- polar_rrrecord2test => polar_rrrecord2txt | 26 +++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) rename polar_rrrecord2test => polar_rrrecord2txt (60%) diff --git a/README.md b/README.md index a6fd276..9e9bf4a 100755 --- a/README.md +++ b/README.md @@ -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 @@ -112,6 +112,17 @@ $ polar_ftp SYNC # Copy watch file system to ~/Polar/ $ polar_training2sml ~/Polar//U/0//E// /tmp/output.sml ``` + +Read RR recording result and converts to txt file: + +```sh +$ polar_rrrecord2txt [] + +# Example: +$ polar_ftp SYNC # Copy watch file system to ~/Polar/ +$ polar_rrrecord2txt ~/Polar//U/0//RRREC// /tmp/output.txt +``` + ## Author [Cédric Maïon](https://github.com/cmaion) diff --git a/polar_rrrecord2test b/polar_rrrecord2txt similarity index 60% rename from polar_rrrecord2test rename to polar_rrrecord2txt index c2a5d11..1423178 100755 --- a/polar_rrrecord2test +++ b/polar_rrrecord2txt @@ -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__} " + puts " #{__FILE__} []" end dir = ARGV[0] @@ -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] @@ -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