-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
202 lines (161 loc) · 5.11 KB
/
index.php
File metadata and controls
202 lines (161 loc) · 5.11 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
class FoxFit
{
private int $protein = 4;
private int $carbon = 4;
private int $fat = 9;
private float $averageProtein = 2.6;
private int $caloNeedToUpgrade = 7700;
private float $proteinNeeded = 0;
private float $carbonNeeded = 0;
private float $fatNeeded = 0;
// https://www.thehinh.com/tool/TDEE/tinh-tdee.html
private $TDEE;
private $weight;
const NORMAL_CALCULATOR = 0;
const SPECIAL_CALCULATOR = 1;
private $list = [30, 35, 35];
private int $type;
private array $foodList;
private $foods = [
'chicken' => [25.2, 0, 1], // 100gr
'beef' => [26.1, 0, 11.8], // 100gr
'whey' => [24, 3, 1],
'apple' => [0.5, 13.8, 0.1], // max: 2
'avocado' => [2, 1.9, 19], // 100gr
'hamburger' => [13.3, 30.3, 10.1],
'rice' => [2.7, 28.2, 0.3],
'cheese' => [1.7, 0, 3.5],
'banana' => [1, 23, 0.3], // max: 2
'corn' => [0, 19, 1.4],
'pho' => [17, 31, 4],
'vinamilk_yaourt' => [3.1, 15.6, 2.7],
'bread' => [13.2, 30, 2.5],
'true_milk_no_sugar_220ml' => [6.6, 10.12, 7.26],
'watermelon' => [1.45, 17.97, 0.36],
'kinh_do_milk_bread' => [8, 44.16 ,4.08],
];
public function __construct(float $weight, float $TDEE, int $type = self::NORMAL_CALCULATOR)
{
$this->weight = $weight;
$this->TDEE = $TDEE;
$this->type = $type;
}
public function setList(array $list): void
{
$this->list = $list;
}
public function setFoodList(array $foodList): void {
$this->foodList = $foodList;
}
private function specialCalculator(): void
{
$this->proteinNeeded = $this->averageProtein * $this->weight;
$this->proteinNeeded = round($this->proteinNeeded);
$left = $this->TDEE - $this->proteinToCalo();
$this->fatNeeded = $left / 15;
$this->fatNeeded = round($this->fatNeeded);
$this->carbonNeeded = $this->fatNeeded * 1.5;
$this->carbonNeeded = round($this->carbonNeeded);
}
private function normalCalculator(): void
{
$this->proteinNeeded = (($this->TDEE / 100) * $this->list[0]) / $this->protein;
$this->proteinNeeded = round($this->proteinNeeded);
$this->carbonNeeded = (($this->TDEE / 100) * $this->list[1]) / $this->carbon;
$this->carbonNeeded = round($this->carbonNeeded);
$this->fatNeeded = (($this->TDEE / 100) * $this->list[2]) / $this->fat;
$this->fatNeeded = round($this->fatNeeded);
}
public function calculator(): void
{
if ($this->type == self::SPECIAL_CALCULATOR) {
$this->specialCalculator();
return;
}
$this->normalCalculator();
}
public function getTotalCalories(): float
{
return $this->proteinToCalo() + $this->carbonToCalo() + $this->fatToCalo();
}
public function showResult(): void
{
$this->calculator();
$lines = [
'Weight: ' . $this->weight,
'Protein: ' . $this->proteinNeeded,
'Carbon: ' . $this->carbonNeeded,
'Fat: ' . $this->fatNeeded,
'Total: ' . $this->getTotalCalories() . ' >< TDEE: ' . $this->TDEE,
];
$total = $this->calculateFood($this->foodList);
foreach ($lines as $k => $line) {
if ($k === 0) {
$this->printLine();
}
$this->printLine($line);
}
$this->printLine(implode('-', $total));
}
private function calculateFood(array $foodList): array {
$totalProtein = $totalCarbon = $totalFat = 0;
foreach ($foodList as $foodKey => $num) {
$food = $this->foods[$foodKey];
$protein = $food[0];
$carbon = $food[1];
$fat = $food[2];
if ($protein > 0) {
$totalProtein += $protein * $num;
}
if ($fat > 0) {
$totalFat += $fat * $num;
}
if ($protein > 0) {
$totalCarbon += $carbon * $num;
}
}
return [$totalProtein, $totalCarbon, $totalFat];
}
private function printLine(?string $line = null): void
{
$lineBreak = '<br/>';
if ($line === null) {
echo $lineBreak;
return;
}
echo $line . '<br/>';
}
public function proteinToCalo(): float
{
return $this->proteinNeeded * $this->protein;
}
public function carbonToCalo(): float
{
return $this->carbonNeeded * $this->carbon;
}
public function fatToCalo(): float
{
return $this->fatNeeded * $this->fat;
}
}
$TDEE = 1952;
$weight = 52;
//$fit = new FoxFit($weight, $TDEE, Freedom::SPECIAL_CALCULATOR);
//$fit->showResult();
//
//echo '---------------------';
$fit = new FoxFit($weight, $TDEE);
$fit->setList([30, 50, 20]);
$fit->setFoodList([
'chicken' => 2,
'rice' => 4,
'hamburger' => 1,
'banana' => 2,
'whey' => 2,
'vinamilk_yaourt' => 2,
'cheese' => 2,
'true_milk_no_sugar_220ml' => 2,
'watermelon' => 1,
]);
$fit->showResult();