-
Notifications
You must be signed in to change notification settings - Fork 0
/
Predictor.js
54 lines (45 loc) · 1.45 KB
/
Predictor.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
54
import React from 'react';
import { Store } from "./Store";
export class Predictor {
constructor(props) {
this.store = new Store();
}
getRecommendationFor(card, field, unit) {
let number, text, value;
switch(card) {
case 'nutrition':
number = this.nutritionRecommendation;
text = <>Your recommended intake for today so far is <strong>{Number(number).toLocaleString()} {unit}</strong>.</>;
value = Number(number);
break;
case 'hydration':
number = this.hydrationRecommendation;
text = <>Your recommended intake for today so far is <strong>{Number(number).toLocaleString()} {unit}</strong>.</>;
value = Number(number);
break;
default:
text = <></>;
value = 0;
}
return { text, value };
}
get nutritionRecommendation() {
// this is the recommendation for keeping your weight
// TODO: branching for gaining or losing weight
// https://www.fitness-emotion.at/berechnung-grundumsatz/#Mifflin-StJeor-Formel
const modifier = this.store.user.physicalActivity || 1;
const w = 9.99 * this.store.user.weight;
const h = 6.25 * this.store.user.height;
const a = 4.92 * this.store.age;
let value = w + h - a;
if (this.store.user.sex === 'f') {
value -= 161;
} else {
value += 5;
}
return Math.round(value * modifier);
}
get hydrationRecommendation() {
return this.store.user.weight * 30;
}
}