Hozifa Elgharbawy commited on
Commit
20cfe10
1 Parent(s): 9a93a6a
models/nutrition_model.py CHANGED
@@ -6,7 +6,7 @@ import os
6
 
7
  SERVER_FILE_DIR = os.path.dirname(os.path.abspath(__file__))
8
  NUTRITION_MODEL_PATH = os.path.join(SERVER_FILE_DIR, "../resources/models/nutrition_model.pkl")
9
- MEALS_JSON_PATH = os.path.join(SERVER_FILE_DIR, "../resources/datasets/meals.json")
10
 
11
  # Ensure the file exists
12
  if not os.path.exists(MEALS_JSON_PATH):
@@ -14,64 +14,67 @@ if not os.path.exists(MEALS_JSON_PATH):
14
 
15
  df = pd.read_json(MEALS_JSON_PATH)
16
 
17
-
18
  class NutritionModel:
19
  def __init__(self):
20
  self.load()
21
 
22
  def generate_plan(self, calories):
23
  lunch_attr = {
24
- "Calories": calories * 0.5,
25
- "FatContent": random.uniform(19, 97),
26
- "SaturatedFatContent": random.uniform(6, 12),
27
- "CholesterolContent": random.uniform(77, 299),
28
- "SodiumContent": random.uniform(565, 2299),
29
- "CarbohydrateContent": random.uniform(28, 317),
30
- "FiberContent": random.uniform(2, 38),
31
  "SugarContent": random.uniform(0, 38),
32
- "ProteinContent": random.uniform(20, 123)
 
33
  }
34
 
35
  lunch_df = pd.DataFrame(lunch_attr, index=[0])
36
 
37
  breakfast_attr = {
38
- "Calories": calories * 0.30,
39
- "FatContent": random.uniform(8.7, 20),
40
- "SaturatedFatContent": random.uniform(1.7, 3.7),
41
- "CholesterolContent": random.uniform(0, 63),
42
- "SodiumContent": random.uniform(163, 650),
43
- "CarbohydrateContent": random.uniform(23, 56),
44
- "FiberContent": random.uniform(2.6, 8),
45
  "SugarContent": random.uniform(3.5, 13),
46
- "ProteinContent": random.uniform(6, 25)
 
47
  }
48
 
49
  breakfast_df = pd.DataFrame(breakfast_attr, index=[0])
50
 
51
  dinner_attr = {
52
- "Calories": calories * 0.30,
53
- "FatContent": random.uniform(8.7, 20),
54
- "SaturatedFatContent": random.uniform(1.7, 3.7),
55
- "CholesterolContent": random.uniform(0, 63),
56
- "SodiumContent": random.uniform(163, 650),
57
- "CarbohydrateContent": random.uniform(23, 56),
58
- "FiberContent": random.uniform(2.6, 8),
59
- "SugarContent": random.uniform(3.5, 13),
60
- "ProteinContent": random.uniform(6, 25)
 
61
  }
62
 
63
  dinner_df = pd.DataFrame(dinner_attr, index=[0])
64
 
65
  snack_attr = {
66
- "Calories": random.uniform(90, 190),
67
- "FatContent": random.uniform(1.7, 10),
68
- "SaturatedFatContent": random.uniform(0.7, 3),
69
- "CholesterolContent": random.uniform(2, 16),
70
- "SodiumContent": random.uniform(47, 200),
71
- "CarbohydrateContent": random.uniform(10, 31),
72
- "FiberContent": random.uniform(0.4, 2.5),
73
  "SugarContent": random.uniform(5.7, 21),
74
- "ProteinContent": random.uniform(3, 20)
 
75
  }
76
 
77
  snack_df = pd.DataFrame(snack_attr, index=[0])
@@ -83,12 +86,10 @@ class NutritionModel:
83
 
84
  meals = np.concatenate((breakfast, lunch, dinner, snack), axis=0)
85
  meals = np.transpose(meals)
86
-
87
  days = []
88
  for i in range(7):
89
  day_meals = df.iloc[meals[i]].to_dict(orient="records")
90
  days.append(day_meals)
91
-
92
  return days
93
 
94
  def load(self):
 
6
 
7
  SERVER_FILE_DIR = os.path.dirname(os.path.abspath(__file__))
8
  NUTRITION_MODEL_PATH = os.path.join(SERVER_FILE_DIR, "../resources/models/nutrition_model.pkl")
9
+ MEALS_JSON_PATH = os.path.join(SERVER_FILE_DIR, "../../src/resources/meals.json")
10
 
11
  # Ensure the file exists
12
  if not os.path.exists(MEALS_JSON_PATH):
 
14
 
15
  df = pd.read_json(MEALS_JSON_PATH)
16
 
 
17
  class NutritionModel:
18
  def __init__(self):
19
  self.load()
20
 
21
  def generate_plan(self, calories):
22
  lunch_attr = {
23
+ "Calories":calories*0.4,
24
+ "FatContent":random.uniform(19, 97),
25
+ "SaturatedFatContent":random.uniform(6, 12),
26
+ "CholesterolContent": random.uniform(77, 299),
27
+ "SodiumContent":random.uniform(565, 2299),
28
+ "CarbohydrateContent":random.uniform(28, 317),
29
+ "FiberContent": random.uniform(2, 38),
30
  "SugarContent": random.uniform(0, 38),
31
+ "ProteinContent":random.uniform(20, 123),
32
+ 'weight' : 30
33
  }
34
 
35
  lunch_df = pd.DataFrame(lunch_attr, index=[0])
36
 
37
  breakfast_attr = {
38
+ "Calories":calories*0.30,
39
+ "FatContent":random.uniform(8.7, 20),
40
+ "SaturatedFatContent":random.uniform(1.7, 3.7),
41
+ "CholesterolContent": random.uniform(0, 63),
42
+ "SodiumContent":random.uniform(163, 650),
43
+ "CarbohydrateContent":random.uniform(23, 56),
44
+ "FiberContent": random.uniform(2.6, 8),
45
  "SugarContent": random.uniform(3.5, 13),
46
+ "ProteinContent":random.uniform(6, 25),
47
+ 'weight' : 0
48
  }
49
 
50
  breakfast_df = pd.DataFrame(breakfast_attr, index=[0])
51
 
52
  dinner_attr = {
53
+ "Calories":calories*0.30,
54
+ "FatContent":random.uniform(15, 33),
55
+ "SaturatedFatContent":random.uniform(6, 8),
56
+ "CholesterolContent": random.uniform(22, 86),
57
+ "SodiumContent":random.uniform(265, 775),
58
+ "CarbohydrateContent":random.uniform(14, 44),
59
+ "FiberContent": random.uniform(201, 210),
60
+ "SugarContent": random.uniform(3, 13),
61
+ "ProteinContent":random.uniform(11, 25),
62
+ 'weight' :10
63
  }
64
 
65
  dinner_df = pd.DataFrame(dinner_attr, index=[0])
66
 
67
  snack_attr = {
68
+ "Calories":random.uniform(90, 190),
69
+ "FatContent":random.uniform(1.7, 10),
70
+ "SaturatedFatContent":random.uniform(0.7, 3),
71
+ "CholesterolContent": random.uniform(2, 16),
72
+ "SodiumContent":random.uniform(47, 200),
73
+ "CarbohydrateContent":random.uniform(10, 31),
74
+ "FiberContent": random.uniform(0.4, 2.5),
75
  "SugarContent": random.uniform(5.7, 21),
76
+ "ProteinContent":random.uniform(3, 20),
77
+ 'weight' :40
78
  }
79
 
80
  snack_df = pd.DataFrame(snack_attr, index=[0])
 
86
 
87
  meals = np.concatenate((breakfast, lunch, dinner, snack), axis=0)
88
  meals = np.transpose(meals)
 
89
  days = []
90
  for i in range(7):
91
  day_meals = df.iloc[meals[i]].to_dict(orient="records")
92
  days.append(day_meals)
 
93
  return days
94
 
95
  def load(self):
resources/datasets/meals.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0149719d8294fc792dfe053133b3c9edce076b5d69978b26185e96cfec9a5140
3
- size 4038577
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51acbeea46fac5d8ccbc8d3a4640c06e7be141e740a2079fda91c0ab9aae8cac
3
+ size 3369182
resources/models/nutrition_model.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9cd0dc84cc9dcc0c985725e8d5cda8d9f9b0571c6c3219bdef2309f177b46ae1
3
- size 258480
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b69a06d48ce8d41617e979f87bdc82bbe5c4b2cff80234f688a642509ee55673
3
+ size 278272