diff options
author | Chris Schlaeger <chris@linux.com> | 2018-03-17 16:50:25 +0100 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2018-03-17 16:50:25 +0100 |
commit | 7caf6e842fd61975d3f402b1725ed0c9d9472c6c (patch) | |
tree | 225738a3edfcb03f7285416f16c7c6ed94860f2c /lib | |
parent | ca8a1fe5df72268f1110d74a928b4b33d1178f9a (diff) | |
download | postrunner-7caf6e842fd61975d3f402b1725ed0c9d9472c6c.zip |
New: Show TRIMP (Exp) in activity summary
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/ActivitySummary.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/postrunner/ActivitySummary.rb b/lib/postrunner/ActivitySummary.rb index 70546d8..f753ce9 100644 --- a/lib/postrunner/ActivitySummary.rb +++ b/lib/postrunner/ActivitySummary.rb @@ -145,6 +145,10 @@ module PostRunner t.row([ 'Aerobic Training Effect:', session.total_training_effect ]) end + if (trimp = trimp_exp) > 0.0 + t.row([ 'TRIMP (Exp):', trimp ]) + end + rec_info = @fit_activity.recovery_info t.row([ 'Ignored Recovery Time:', rec_info ? secsToDHMS(rec_info * 60) : '-' ]) @@ -362,7 +366,43 @@ module PostRunner end def trimp_exp + # According to http://fellrnr.com/wiki/TRIMP + # TRIMPexp = sum(D x HRr x 0.64e^y) + # Where + # + # D is the duration in minutes at a particular Heart Rate + # HRr is the Heart Rate as a fraction of Heart Rate Reserve + # y is the HRr multiplied by 1.92 for men and 1.67 for women. + return 0.0 unless (user_data = @fit_activity.user_data.first) + user_profile = @fit_activity.user_profiles.first + hr_zones = @fit_activity.heart_rate_zones.first + + unless (user_profile && (rest_hr = user_profile.resting_heart_rate)) || + (hr_zones && (rest_hr = hr_zones.resting_heart_rate)) + # We must have a valid resting heart rate to compute TRIMP. + return 0.0 + end + unless (user_data && (max_hr = user_data.max_hr)) || + (hr_zones && (max_hr = hr_zones.max_heart_rate)) + # We must have a valid maximum heart rate to compute TRIMP. + return 0.0 + end + + prev_timestamp = nil + sum = 0.0 + @activity.fit_activity.records.each do |r| + if prev_timestamp && r.timestamp && r.heart_rate + hr_r = (r.heart_rate - rest_hr).to_f / (max_hr - rest_hr) + y = user_data.gender == :male ? 1.92 : 1.67 * hr_r + factor = 0.64 * Math.exp(y) + sum += ((r.timestamp - prev_timestamp) / 60.0) * hr_r * factor + end + prev_timestamp = r.timestamp + end + # There are so many fudge factors in the formula that we don't want to + # suggest more precision than there really is. + sum.round end end |