after doing a some research I reached the point that I decided to ask here for advice as I am not sure how to proceeed.
The problem:
I have an array of RR (IBI) data
Example: [679, 686, 650...]
How can I convert this to heart rate?
My research:
My approach which of course is defective:
for (const ibiInMilliseconds of eventJSONObject.DeviceLog["R-R"].Data) {
ibiBuffer.push(ibiInMilliseconds);
const ibiBufferTotal = ibiBuffer.reduce((a, b) => a + b, 0);
// If adding the ibi to the start of the activity is greater or equal to 2.5 second then empty the buffer there
if ((lastDate.getTime() + ibiBufferTotal) >= lastDate.getTime() + 2500) {
const average = ibiBuffer.reduce((total, ibi) => {
return total + ibi;
}) / ibiBuffer.length;
const avg = 1000 * 60 / average;
// I save this avg to a 1s list but it's very error prone
ibiBuffer = [];
lastDate = new Date(lastDate.getTime() + ibiBufferTotal);
}
}
I would appreciate any kind of help or pointers as where to look.
After a lot of time testing etc the correct answer is:
/**
* Converts the RR array to HR instantaneus (what user sees)
* @param rrData
* @return {any}
*/
public static convertRRtoHR(rrData): Map<number, number> {
let totalTime = 0;
return rrData.reduce((hrDataMap: Map<number, number>, rr) => {
totalTime += rr;
hrDataMap.set(totalTime, Math.round(60000 / rr));
return hrDataMap;
}, new Map());
}