summaryrefslogtreecommitdiff
path: root/lib/postrunner/HRV_Analyzer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/postrunner/HRV_Analyzer.rb')
-rw-r--r--lib/postrunner/HRV_Analyzer.rb17
1 files changed, 9 insertions, 8 deletions
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|