-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate TRIMP score for running? #48
Comments
Calculating the TRIMP score requires changes to the source code of the application. While calculating the TRIMP value is easy enough, there are several options for displaying it, ranging from showing it in the session inspector only (easy), storing it in the database and showing it in the activity list + some reports (medium) and all the way of implementing a custom metric definition and storage mechanism -- this would be a lot of work, but would be the most flexible solution. However, I am unable to implement any of these things in the short to medium term, as I have little time to work on ActivityLog2 and what time I have other things planned. I will leave this issue open, for possible future implementation. |
I'm not really familiar with Racket, but I might have a look at the code in free time for the easy solution at least as a first step. |
If you decide to try that, here are some things to get you started. This function below will calculate TRIMP, and it is similar to the Python one. You can place the code in a file in the "etc" folder of the source code. The "al-interactive.rkt" library will give you access to the same database that ActivityLog2 is using, so to test it out, find the session id for the session you want (use the "Activities / Copy Session Id To Clipboard..." in the application), than use the call:
Once you got that working and are happy with it, you will need to place the function in an appropriate file (or create a new one) inside the application (the "rkt" folder), as the "etc" folder and "al-interactive" are only for testing things out. You can than hook this function to the session inspector to display the value by adding an entry here:
There is a lot more work to get this "production ready", such as getting the min / max heart rate from the sport zones and caching values to avoid recalculating it every time, but for your own use, it might be sufficient. #lang racket
(require "al-interactive.rkt")
(define (is-running? sport)
(equal? (vector-ref sport 0) 1))
(define (compute-trimp df min-hr max-hr is-male?)
;; NOTE use the "elapsed" series if you want to compute TRIMP over periods
;; where recording was stopped. See docs/sesion-df.md for available data
;; series.
(define previous-timestamp #f)
(define gender-factor (if is-male? 1.92 1.67))
(if (and (df-contains? df "timer" "hr")
(is-running? (df-get-property df 'sport)))
(df-fold
df
'("timer" "hr")
0 ; initial TRIMP
(lambda (curent-trimp current-entry)
(match-let ([(list timestamp hr) current-entry])
;; make sure we have a previous-timestamp (not the first call) and
;; this is a good sample (good HR).
(begin0
(if (and previous-timestamp hr)
(let ([dt (/ (- timestamp previous-timestamp) 60.0)]
[hrr (/ (- hr min-hr) (- max-hr min-hr))])
(+ curent-trimp (* dt hrr 0.64 (exp gender-factor))))
curent-trimp)
(set! previous-timestamp timestamp)))))
;; Return false if TRIMP cannot be computed
#f)) |
That's really helpful, thank you! Not sure if I should open a separate issue btw, after pulling the latest commits building fails with this error:
Reverting back to commit 562cf2b fixes the issue. |
I would recommend you follow the instructions for building the application here I think you may have installed some extra packages, I suggest you remove them first. If you don't remember what packages you installed, you can run the command:
You can than remove the packages using Also, given that you are about to work on the application, It might be simpler to just run compile the application, than run it directly (build.rkt is for when you want to build a standalone distribution). This is also explained in the readme file I linked above. Finally, the readme file is not perfect, if you have any suggestions on how to improve it, let me know. |
I had installed the dependencies with raco before. It's my fault, the README is fine as is, it warns that this could cause issues. It's just the error message was pretty cryptic to and there was nothing I could find online that would help understand it. After removing the packages and following the instructions for setting up the local catalog it now works fine. |
I made some attempts to get the TRIMP calculation working but didn't get far unfortunately. Meanwhile I've gotten a Stryd pod and TRIMP is no longer very relevant for me. |
Is this something that could be calculated and shown in a column for running activities with heart rate data?
I have a small python script that can calculate it given a FIT file, would be nice if it could be integrated into ActivityLog2 though.
The text was updated successfully, but these errors were encountered: