From 54719ca934e1b01dca10344bd3b392c686528a89 Mon Sep 17 00:00:00 2001 From: Chris Schlaeger Date: Mon, 23 Nov 2015 20:41:00 +0100 Subject: Show R-R intervals in ms instead of s. --- README.md | 7 +++++-- lib/postrunner/ChartView.rb | 7 ++++--- lib/postrunner/HRV_Analyzer.rb | 17 +++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8f443e8..734ef45 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,11 @@ PostRunner is an application to manage FIT files such as those produced by Garmin products like the Forerunner 620 (FR620) and Fenix 3. It allows you to import the files from the device and inspect them. -It can also update satellite orbit prediction (EPO) data on the device -to speed-up fix times. It is an offline alternative to Garmin Connect. +In addition to the common features like plotting pace, heart rates, +elevation and other captured values it also provides a heart rate +variability (HRV) analysis. It can also update satellite orbit prediction +(EPO) data on the device to speed-up fix times. It is an offline +alternative to Garmin Connect. ## Installation diff --git a/lib/postrunner/ChartView.rb b/lib/postrunner/ChartView.rb index b146ea4..8009954 100644 --- a/lib/postrunner/ChartView.rb +++ b/lib/postrunner/ChartView.rb @@ -46,7 +46,7 @@ module PostRunner chart_div(doc, 'altitude', "Elevation (#{select_unit('m')})") chart_div(doc, 'heart_rate', 'Heart Rate (bpm)') if @hrv_analyzer.has_hrv_data? - chart_div(doc, 'hrv', 'Heart Rate Variability (s)') + chart_div(doc, 'hrv', 'R-R Intervals/Heart Rate Variability (ms)') #chart_div(doc, 'hrv_score', 'HRV Score (30s Window)') end chart_div(doc, 'run_cadence', 'Run Cadence (spm)') @@ -187,9 +187,10 @@ EOT prev_intvl = @hrv_analyzer.rr_intervals[idx - 1] next unless curr_intvl && prev_intvl - dt = curr_intvl - prev_intvl + # Convert the R-R interval duration to ms. + dt = (curr_intvl - prev_intvl) * 1000.0 min_value = dt if min_value.nil? || min_value > dt - data_set << [ @hrv_analyzer.timestamps[idx] * 1000, dt] + data_set << [ @hrv_analyzer.timestamps[idx] * 1000, dt ] end else @activity.fit_activity.records.each do |r| diff --git a/lib/postrunner/HRV_Analyzer.rb b/lib/postrunner/HRV_Analyzer.rb index 8375a9b..664f7c9 100644 --- a/lib/postrunner/HRV_Analyzer.rb +++ b/lib/postrunner/HRV_Analyzer.rb @@ -130,6 +130,14 @@ module PostRunner private def collect_rr_intervals + # The rr_intervals Array stores the beat-to-beat time intervals (R-R). + # If one or move beats have been skipped during measurement, a nil value + # is inserted. + @rr_intervals = [] + # The timestamps Array stores the relative (to start of sequence) time + # for each interval in the rr_intervals Array. + @timestamps = [] + # Each Fit4Ruby::HRV object has an Array called 'time' that contains up # to 5 R-R interval durations. If less than 5 are present, they are # filled with nil. @@ -137,19 +145,12 @@ module PostRunner @fit_file.hrv.each do |hrv| raw_rr_intervals += hrv.time.compact end + return if raw_rr_intervals.empty? window = 20 intro_mean = raw_rr_intervals[0..4 * window].reduce(:+) / (4 * window) predictor = LinearPredictor.new(window, intro_mean) - # The rr_intervals Array stores the beat-to-beat time intervals (R-R). - # If one or move beats have been skipped during measurement, a nil value - # is inserted. - @rr_intervals = [] - # The timestamps Array stores the relative (to start of sequence) time - # for each interval in the rr_intervals Array. - @timestamps = [] - # The timer accumulates the interval durations. timer = 0.0 raw_rr_intervals.each do |dt| -- cgit v1.2.3