Ejemplo n.º 1
0
 public function createRecipe()
 {
     $scope = array('title' => 'Make Fit Real User Area', 'website' => $this->website, 'csrf' => $this->csrf, 'intro-title' => Lang::get('intro-title-diet'));
     $navbar_stuff = $this->navbar_stuff();
     $scope['navbar-stuff'] = $navbar_stuff['stuff'];
     $scope['navbar-links'] = $navbar_stuff['links'];
     $scope['coaching-status'] = MfrUsers::current_status();
     $scope['ingredients'] = MfrAlimentos::all();
     $scope['average-status']['kcals'] = $scope['coaching-status'][2]['value'] / 4;
     $scope['average-status']['protein'] = $scope['coaching-status'][3]['value'] / 4;
     $scope['average-status']['carbs'] = $scope['coaching-status'][4]['value'] / 4;
     $scope['average-status']['fat'] = $scope['coaching-status'][5]['value'] / 4;
     $scope['average-status']['macros'] = $scope['coaching-status'][6]['value'];
     $scope['recipes'] = MfrUserRecipes::all();
     View::render('coaching/user/diet/create/index.php', $scope);
 }
Ejemplo n.º 2
0
 public function calcSingleRecipe($carbs, $proteins, $fats, $recipe_id)
 {
     $carbsHC = 0;
     $carbsP = 0;
     $carbsF = 0;
     $fatsHC = 0;
     $fatsP = 0;
     $fatsF = 0;
     $proteinsHC = 0;
     $proteinsP = 0;
     $proteinsF = 0;
     /**
      * @desc: value builder = builds the ammount of hc, proteins and fats from the aliments(?)
      */
     $array_of_alimentos = array();
     $new_array_of_alimentos = array();
     $value_builder = MfrUserRecipesAlimentos::where('recipe_id', $recipe_id)->get();
     foreach ($value_builder as $value) {
         $quantity = $value->quantity;
         $alimento = MfrAlimentos::find($value->alimento_id)[0];
         $alimento->quantity = $quantity;
         array_push($array_of_alimentos, $alimento);
         if ($alimento->product_group == 'h') {
             $carbsHC += (int) ($alimento->carbs_100g / 100 * $quantity);
             $carbsP += (int) ($alimento->protein_100g / 100 * $quantity);
             $carbsF += (int) ($alimento->fat_100g / 100 * $quantity);
         }
         if ($alimento->product_group == 'p') {
             $proteinsHC += (int) ($alimento->carbs_100g / 100 * $quantity);
             $proteinsP += (int) ($alimento->protein_100g / 100 * $quantity);
             $proteinsF += (int) ($alimento->fat_100g / 100 * $quantity);
         }
         if ($alimento->product_group == 'g') {
             $fatsHC += (int) ($alimento->carbs_100g / 100 * $quantity);
             $fatsP += (int) ($alimento->protein_100g / 100 * $quantity);
             $fatsF += (int) ($alimento->fat_100g / 100 * $quantity);
         }
     }
     /**  @matriz: */
     /** Organizar a matriz em array */
     $A = array(11 => $carbsHC, 12 => $proteinsHC, 13 => $fatsHC, 21 => $carbsP, 22 => $proteinsP, 23 => $fatsP, 31 => $carbsF, 32 => $proteinsF, 33 => $fatsF);
     /*
      $A = array(
          11 => $carbsHC,
          12 => $carbsP,
          13 => $carbsF,
          21 => $proteinsHC,
          22 => $proteinsP,
          23 => $proteinsF,
          31 => $fatsHC,
          32 => $fatsP,
          33 => $fatsF,
      );
     */
     $B = array(1 => $carbs, 2 => $proteins, 3 => $fats);
     /**
      * @calculo matricial á mão
      */
     $matrix = new MakeFitReal\Helpers\MatriceEquations\matriceEquation();
     $matrix->addA(array($A[11], $A[12], $A[13]));
     $matrix->addA(array($A[21], $A[22], $A[23]));
     $matrix->addA(array($A[31], $A[32], $A[33]));
     $matrix->addB(array($B[1], $B[2], $B[3]));
     $X = $matrix->cramer();
     $x1 = $X[0];
     $x2 = $X[1];
     $x3 = $X[2];
     $returned_kcals = 0;
     $returned_protein = 0;
     $returned_carbs = 0;
     $returned_fats = 0;
     foreach ($array_of_alimentos as $alimento) {
         $new_alimento = array();
         $new_alimento['id'] = $alimento->id;
         $new_alimento['name'] = $alimento->name_pt;
         $new_alimento['id'] = $alimento->id;
         if ($alimento->product_group == 'h') {
             $new_alimento['quantity'] = (int) ($alimento->quantity * $x1);
             $returned_protein += $alimento->protein_100g * $x1;
             $returned_carbs += $alimento->carbs_100g * $x1;
             $returned_fats += $alimento->fat_100g * $x1;
         }
         if ($alimento->product_group == 'p') {
             $new_alimento['quantity'] = (int) ($alimento->quantity * $x2);
             $returned_protein += $alimento->protein_100g * $x2;
             $returned_carbs += $alimento->carbs_100g * $x2;
             $returned_fats += $alimento->fat_100g * $x2;
         }
         if ($alimento->product_group == 'g') {
             $new_alimento['quantity'] = (int) ($alimento->quantity * $x3);
             $returned_protein += $alimento->protein_100g * $x3;
             $returned_carbs += $alimento->carbs_100g * $x3;
             $returned_fats += $alimento->fat_100g * $x3;
         }
         array_push($new_array_of_alimentos, $new_alimento);
     }
     $returned_kcals = ($returned_protein + $returned_carbs) * 4 + $returned_fats * 9;
     return array('alimentos' => $new_array_of_alimentos, 'macros' => array('protein' => (double) $returned_protein, 'carbs' => (int) $returned_carbs, 'fats' => (int) $returned_fats, 'kcals' => (int) $returned_kcals));
 }