-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (49 loc) · 2.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const common = require('./lib/common')
async function toSteps(exercise, intensity, minutes) {
common.checkType(exercise, 'string')
common.checkType(intensity, 'number')
common.checkType(minutes, 'number')
const conversions = await common.readFile('config/exerciseToSteps.json')
const thisExercise = (conversions[exercise.toLowerCase()]) ? conversions[exercise.toLowerCase()] : 'void'
const thisIntensity = intensity - 1
if (thisExercise !== 'void') {
if (common.isBetween(thisIntensity, -1, thisExercise.length)) return thisExercise[thisIntensity] * minutes
throw new Error(`Please provide an intensity between 1 and ${thisExercise.length}`)
}
throw new Error(`Unrecognised exercise: ${exercise}`)
}
async function toStepsAvgHR(exercise, ahr, minutes) {
common.checkType(exercise, 'string')
common.checkType(ahr, 'number')
common.checkType(minutes, 'number')
const conversions = await common.readFile('config/exerciseToSteps.json')
const thisExercise = (conversions[exercise.toLowerCase()]) ? conversions[exercise.toLowerCase()] : 'void'
const thisIntensity = common.convertToIntensity(ahr) - 1
if (thisExercise !== 'void') {
if (common.isBetween(thisIntensity, -1, thisExercise.length)) return thisExercise[thisIntensity] * minutes
}
throw new Error(`Unrecognised exercise: ${exercise}`)
}
async function toStepsHRpm(exercise, hrpm) {
let totalSteps = 0
common.checkType(exercise, 'string')
common.checkType(hrpm, 'object')
const conversions = await common.readFile('config/exerciseToSteps.json')
const thisExercise = (conversions[exercise.toLowerCase()]) ? conversions[exercise.toLowerCase()] : 'void'
hrpm.forEach((thishr) => {
const thisIntensity = common.convertToIntensity(thishr) - 1
if (thisExercise !== 'void') {
if (common.isBetween(thisIntensity, -1, thisExercise.length)) {
totalSteps += thisExercise[thisIntensity]
return 0
}
}
throw new Error(`Unrecognised exercise: ${exercise}`)
})
return totalSteps
}
module.exports = {
toSteps,
toStepsAvgHR,
toStepsHRpm,
}