32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import { computed } from '@ember/object';
|
|
|
|
export default Controller.extend({
|
|
queryParams: ['p', 'c', 'f', 'height', 'weight', 'age', 'sex', 'kcal'],
|
|
|
|
pcfByPercentages: computed('p', 'c', 'f', function() {
|
|
if (this.p > 0 || this.c > 0 || this.f > 0) {
|
|
let sum = parseInt(this.p) + parseInt(this.c) + parseInt(this.f);
|
|
return [
|
|
{ name: 'Białko', percent: Math.round(this.p / sum * 100) },
|
|
{ name: 'Weglowodany', percent: Math.round(this.c / sum * 100) },
|
|
{ name: 'Tłuszcz', percent: Math.round(this.f / sum * 100) }
|
|
];
|
|
}
|
|
}),
|
|
|
|
demand: computed('height', 'weight', 'age', 'sex', function() {
|
|
let ret = {};
|
|
if (this.sex === 'male') {
|
|
ret.kcal = 66 + 13.7 * this.weight + 5 * this.height - 6.76 * this.age;
|
|
} else {
|
|
ret.kcal = 655 + 9.6 * this.weight + 1.8 * this.height - 4.7 * this.age;
|
|
}
|
|
ret.p = Math.round(ret.kcal * 0.2 / 4 * 100) / 100;
|
|
ret.c = Math.round(ret.kcal * 0.5 / 4 * 100) / 100;
|
|
ret.f = Math.round(ret.kcal * 0.3 / 9 * 100) / 100;
|
|
|
|
return ret;
|
|
})
|
|
});
|