def select_vegetables(self, calories=None): if self.isYogurt: percent = 0.25 else: percent = 0.18 if not calories: calories = percent * self.calories_goal food_list = self.marked.filter(vegetable=1).filter( grains_cereals=0).filter(cuisine="Generic") if self.disease and hasattr(self.disease, "vegetable_filter"): food_list = food_list.filter(self.disease.vegetable_filter) if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter(vegetable=1).filter( grains_cereals=0).filter( cuisine="Generic").filter(extra_filter) m = Manipulator(items=food_list, categorizers=[VegetablePulseCategoriser]) food_list = m.categorize().get_final_list() self.vegetable = self.select_best_minimum(food_list, calories, "vegetable") if isinstance(self.vegetable, Food): steps = round( (calories - self.vegetable.calarie) * self.vegetable.weight / (self.vegetable.calarie * 10)) new_weight = min(250, self.vegetable.weight + steps * 10) self.vegetable.update_weight(new_weight / self.vegetable.weight)
def select_pulses(self, calories=None, extra_filter=Q()): if self.isYogurt: percent = 0.23 else: percent = 0.18 if not calories: calories = percent * self.calories_goal else: calories = calories food_list = self.marked.filter(pulses=1).filter( grains_cereals=0).filter(cuisine="Generic") food_list = food_list.filter(extra_filter) if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter(pulses=1).filter( grains_cereals=0).filter(cuisine="Generic").filter( self.exclusion_conditions).filter(extra_filter) m = Manipulator(items=food_list, categorizers=[VegetablePulseCategoriser]) food_list = m.categorize().get_final_list() try: self.pulses = self.select_best_minimum(food_list, calories, "pulse") except Exception as e: self.pulses = min(food_list, key=lambda x: abs(calories - x.calarie)) self.select_item(self.pulses, "pulse")
def select_snack(self): ''' Select a snack for breakfast ''' calories = self.calories_goal #if dairy is not excluded by user, only allocated 85% of calories to snack if ("dairy", 0) not in self.exclusion_conditions: calories *= 0.85 food_list = self.marked.filter(snaks='1').filter(dairy=0) #if egg has been allocated, deduct 36 calories from the snack calories if not ("egg", 0) in self.exclusion_conditions.children: food_list = food_list.exclude(egg=1) calories -= 36 #Get multiple sizes/portions of items m = Manipulator(items=food_list, categorizers=[ParanthaCategoriser]) food_list = m.categorize().get_final_list() #Select the best item self.snack = self.select_best_minimum(food_list, calories, name="snack")
def makeCombination(self): food_list = self.marked.filter(cuisine="Combination") m = Manipulator(items=food_list, categorizers=[CombinationCategoriser]) food_list = m.categorize().get_final_list() self.combination = self.select_best_minimum(food_list, self.calories_goal, name="combination")
def select_salad(self, calories=0): print("Calling Select Salad") if calories == 0: calories = 0.85 * self.calories_goal self.option = "salad" salad_items = self.marked.filter( salad=1).filter(~Q(name__startswith="Handful")).all() m = Manipulator(items=salad_items, categorizers=[SaladCategoriser]) salad_items = m.categorize().get_final_list() self.salad = self.select_best_minimum(salad_items, calories, "salad")
def select_drink(self): calories = 0.15 * self.calories_goal food_list = self.marked.filter(drink=1) m = Manipulator(items=food_list, categorizers=[DrinkCategoriser]) food_list = m.categorize().get_final_list() if self.disease == Osteoporosis: food_list.filter(Q(name__contains="Lassi")) try: self.drink = self.select_best_minimum(food_list, calories, "drink") except Exception as e: self.drink = random.choice(food_list) self.select_item(self.drink, "drink")
def select_pulses(self, percent=0.39, extra_filter=Q()): calories = percent * self.calories_goal food_list = self.marked.filter(pulses=1).filter( grains_cereals=0).filter(cuisine="Generic") food_list = food_list.filter(extra_filter) if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter( pulses=1).filter(extra_filter).filter( self.exclusion_conditions) m = Manipulator(items=food_list, categorizers=[VegetablePulseCategoriser]) food_list = m.categorize().get_final_list() self.pulse = self.select_best_minimum(food_list, calories, "pulse")
def makeCombinations(self): calories = self.calories_remaining if self.make_dessert: calories *= 0.88 else: calories *= 0.85 food_list = self.marked.filter(cuisine="Combination") m = Manipulator(items=food_list, categorizers=[CombinationCategoriser]) food_list = m.categorize().get_final_list() self.combination = self.select_best_minimum(food_list, calories, name="combination")
def select_vegetables(self, percent=0.22): calories = percent * self.calories_goal self.vegetable_calories = calories food_list = self.marked.filter(vegetable=1).filter( grains_cereals=0).filter(cuisine="Generic") if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter(vegetable=1).filter( grains_cereals=0).filter(cuisine="Generic") food_list = food_list.filter(exclusion_conditions) if self.disease and hasattr(self.disease, "m5_vegetable_filter"): food_list = food_list.filter(self.disease.m5_vegetable_filter) m = Manipulator(items=food_list, categorizers=[VegetablePulseCategoriser]) food_list = m.categorize().get_final_list() self.vegetable_list = food_list self.vegetables = self.select_best_minimum(food_list, calories, "vegetable")
def get_drink(self): #Get the list from which drink is to be selected self.drink_list = self.marked.filter(drink='1').filter(size="Teacup") #If the user does not want dairy, remove all dairy items from drink list if ('dairy', 0) not in self.exclusion_conditions.children: self.drink_list = self.drink_list.filter(dairy='1') if not self.drink_list.count(): return #Get multiple sizes/portions for drinks m = Manipulator(items=self.drink_list, categorizers=[DrinkCategoriser]) self.drink_list = m.categorize().get_final_list() return min(self.drink_list, key=lambda x: abs(self.calories_goal * 0.15 - x.calorie))
def select_yogurt(self): self.isYogurt = True calories = 0.15 * self.calories_goal food_list = self.marked.filter(yogurt=1) food_list = food_list.filter(self.exclusion_conditions) if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter(yogurt=1) m = Manipulator(items=food_list, categorizers=[YogurtCategoriser]) food_list = m.categorize().get_final_list() # ipdb.set_trace() self.yogurts = self.select_best_minimum(food_list, calories, name="yogurt") if isinstance(self.yogurts, Food): steps = round((calories - self.yogurts.calorie) * self.yogurts.weight / (self.yogurts.calorie * 10)) new_weight = min(250, self.yogurts.weight + steps * 10) self.yogurts.update_weight(new_weight / self.yogurts.weight)
def select_cereals(self, extra_filter=Q()): calories = 0.39 * self.calories_goal if self.exclude2: food_list = self.getQuerysetFromGoal().exclude( name__in=self.exclude2).exclude(name__in=self.exclude).filter( grains_cereals=1).filter(cuisine="Generic") food_list = food_list.filter(self.exclusion_conditions) else: food_list = self.marked.filter(grains_cereals=1).filter( cuisine="Generic") if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter( grains_cereals=1).filter(cuisine="Generic") food_list = food_list.filter(self.exclusion_conditions) food_list = food_list.filter(extra_filter) m = Manipulator(items=food_list, categorizers=[GrainsCerealsCategoriser]) final_food_list = m.categorize().get_final_list() self.cereals = self.select_best_minimum(final_food_list, calories, "cereal")
def select_cereals(self, percent=0.37, extra_filter=Q()): calories = percent * self.calories_goal if self.exclude2: food_list = self.getQuerysetFromGoal().exclude( name__in=self.exclude2).filter(grains_cereals=1) food_list = food_list.filter(self.exclusion_conditions) else: food_list = self.marked.filter(grains_cereals=1) food_list = food_list.filter(self.exclusion_conditions) food_list = food_list.filter(cuisine="Generic").filter(extra_filter) # ipdb.set_trace() if food_list.count() < 3: food_list = self.getQuerysetFromGoal().filter( grains_cereals=1).exclude( name__in=self.exclude[len(self.exclude) // 2:]) food_list = food_list.filter( self.exclusion_conditions).filter(extra_filter) m = Manipulator(items=food_list, categorizers=[GrainsCerealsCategoriser]) food_list = m.categorize().get_final_list() print("Selecting Cereals") self.cereal = self.select_best_minimum(food_list, calories, "cereals")