-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUIHelpers.js
More file actions
50 lines (41 loc) · 1.56 KB
/
Copy pathUIHelpers.js
File metadata and controls
50 lines (41 loc) · 1.56 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
.pragma library
function getRecipeStats(recipe, dataManager, serving) {
return null
var nutritionModel = ["Carbs", "Proteins", "Fats"];
var recipeWeight = 0;
var nutritionWeight = 0;
var nutritionsData = {};
var calories = 0;
var servingFactor = serving / recipe["Servings"]
for (var j = 0; j < recipe["Ingredients"].length; ++j)
{
var food = dataManager.getFoodById(recipe["Ingredients"][j]["FoodId"]);
var foodAmount = recipe["Ingredients"][j]["Amount"];
var amountFactor = foodAmount / food["Weight"];
recipeWeight += foodAmount * servingFactor;
calories += food["FoodCalories"]["TotalCalories"] * amountFactor * servingFactor;
for (var i = 0; i < nutritionModel.length; ++i)
{
var nutritionKey = nutritionModel[i];
var weight = food["FoodCalories"][nutritionKey] * amountFactor * servingFactor;
nutritionWeight += weight;
if (!(nutritionKey in nutritionsData))
{
nutritionsData[nutritionKey] = 0;
}
nutritionsData[nutritionKey] += weight;
}
}
for (var i = 0; i < nutritionModel.length; ++i)
{
nutritionKey = nutritionModel[i];
nutritionsData[nutritionKey] = parseFloat(nutritionsData[nutritionKey].toFixed(2));
}
return {
"recipeWeight": parseFloat(recipeWeight.toFixed(2)),
"nutritionWeight": parseFloat(nutritionWeight.toFixed(2)),
"nutritions": nutritionsData,
"calories": Math.round(calories),
};
}
//11 1,2