diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/ChartView.rb | 7 | ||||
-rw-r--r-- | lib/postrunner/HRV_Analyzer.rb | 17 |
2 files changed, 13 insertions, 11 deletions
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| |