def Add_Meal_Button_Click(self, event): #click method for component ID=5 pass # >>>>>>insert any user code below this comment for section "compID=5" # replace, delete, or comment-out the following print("executed method Add_Meal_Button_Click") add_meal_popup = Input_Popup("new_meal", parent=self.master) self.Add_Meal_Button.configure(state=DISABLED) self.master.wait_window(add_meal_popup.popup_window) self.Add_Meal_Button.configure(state=NORMAL) meal_data = add_meal_popup.get_rv_data() if "name" in meal_data and meal_data["name"]: new_meal = Meal(meal_data["name"]) self.meals.append(new_meal) self.Listbox_1.delete(0, 'end') new_meal_idx = self.populate_meals(meal_data["name"]) self.Listbox_1.select_set(new_meal_idx) self.selected_meal = new_meal self.populate_ingredients() else: print("no input")
def load(self, filename): full_path = self.data_dir + filename with open(full_path) as f: data = json.load(f) meal = Meal(data) return meal
def main(screen): # Choose window size and mode (y, x, mode) = menu() max_y = curses.LINES - 1 max_x = curses.COLS - 1 screen.clear() screen.nodelay(True) screen.resize(y, x) curses.curs_set(False) speed = 150 if mode == "free": snake = FreeSnake(screen, length=3, speed=speed) elif mode == "cage": snake = CageSnake(screen, length=3, speed=speed) score_win = curses.newwin(1, 22, max_y, int((max_x - 11) / 2)) meal = Meal(screen) meal.generate(snake.body) while True: screen.clear() snake.move() snake.body_check() # if snake ate snack generate new one if snake.pos == meal.pos: snake.eat(meal.pos) meal.generate(snake.body) snake.show() meal.show() # add border screen.border( '#', '#', '#', '#', '#', '#', '#', '#', ) screen.refresh() # show actual score and maximum score score = "o: " + str(snake.score) + " / max: " + str((meal.max_y - 1) * (meal.max_x - 1) - snake.first_length) score_win.addstr(0, 0, score, curses.color_pair(2)) score_win.refresh() screen.refresh() curses.napms(snake.speed)
def createMeals(self): with open(self.path, 'r') as f: data = yaml.safe_load(f) for item in data: meal = Meal(item['name']) meal.set_protein(item['protein']) meal.set_health(item['health']) meal.set_frequency(item['frequency']) meal.set_difficulty(item['difficulty']) self.meals.append(meal)
def add_meals(self, pagecontent): options = pagecontent.find_all("h3") tables = pagecontent.find_all("table") foods = pagecontent.find_all("p") nbr_meals = len(tables) for i in range(nbr_meals): meal_descr = foods[i * 2].text.replace(" ", " ").strip() kitchen = options[i].text.split("|")[0].strip() table = tables[i] self.meals.append(Meal(kitchen, meal_descr, table))
def check_database_for(self, meal_name=None, beer_name=None, category_name=None, user_chat_id=None): """Checks the database for various things. Returns truth value.""" if meal_name: query = Meal.select().where(Meal.name == meal_name) elif beer_name: query = Beer.select().where(Beer.name == beer_name) elif category_name: query = MealCategory.select().where(MealCategory.name == category_name) elif user_chat_id: query = User.select().where(User.chat_id == user_chat_id) else: print 'No query specified!' return False if len(query) > 0: return True # return true when results are found return False
def prepare_non_veg_meal(self): """Make non-vegetarian meal builder Returns: non-vegetarian meal """ nvmeal = Meal() nvmeal.add_item(ChickenBurger()) nvmeal.add_item(Coke()) print "non-vegetarian meal created" return nvmeal
def prepare_veg_meal(self): """Make vegetarian meal builder method Returns: vegetarian meal """ vmeal = Meal() vmeal.add_item(VegBurger()) vmeal.add_item(Pepsi()) print "vegetarian meal created" return vmeal
def createDataStructure(lines): numberOfAvailablePeriods = int(lines[0]) iterator = 1 availablePeriods = {} while iterator <= numberOfAvailablePeriods: availablePeriod = lines[iterator].strip('\n').split(' ') availablePeriods[availablePeriod[0]] = (availablePeriod[1], availablePeriod[2]) iterator += 1 availableIntervals = createInvervalsForDays(availablePeriods) numberOfBusyPeriods = int(lines[iterator]) iterator += 1 busyPeriods = {} busyPeriodId = 1 while iterator <= (numberOfAvailablePeriods + numberOfBusyPeriods + 1): busyPeriodsPerDay = lines[iterator].strip('\n').split(' ') periods = {} periodsIterator = 2 for i in range(int(busyPeriodsPerDay[1])): periods[i + 1] = (busyPeriodsPerDay[periodsIterator], busyPeriodsPerDay[periodsIterator + 1]) periodsIterator += 2 busyPeriods[busyPeriodsPerDay[0]] = periods iterator += 1 busyIntervals = createBusyIntervals(busyPeriods) intervals = availableIntervals setBusyIntervals(intervals, busyIntervals) numberOfTasks = int(lines[iterator]) iterator += 1 tasks = {} while iterator <= (numberOfAvailablePeriods + numberOfBusyPeriods + numberOfTasks + 2): line = lines[iterator].strip('\n').split(' ') daysItMustBeDone = [] numberOfDaysItMustBeDone = int(line[2]) for i in range(numberOfDaysItMustBeDone): daysItMustBeDone.append(line[i + 3]) itMustBeDoneBeforeBusyInterval = False busyIntervalThatTheTaskMustBeDoneBefore = 0 if (line[int(line[2]) + 4] != '-1'): itMustBeDoneBeforeBusyInterval = True interval = line[int(line[2]) + 6].split(':') busyIntervalThatTheTaskMustBeDoneBefore = (line[int(line[2]) + 5], (int(interval[0]), int(interval[1]))) tasks[line[0]] = Task(line[0], int(line[1]) * 4, daysItMustBeDone, int(line[int(line[2]) + 3]) * 4, itMustBeDoneBeforeBusyInterval, busyIntervalThatTheTaskMustBeDoneBefore) iterator += 1 numberOfMeals = int(lines[iterator]) iterator += 1 meals = {} while iterator <= (numberOfAvailablePeriods + numberOfBusyPeriods + numberOfTasks + numberOfMeals + 3): line = lines[iterator].strip('\n').split(' ') meals[line[0]] = Meal(line[0], line[1], line[2], line[3]) iterator += 1 return intervals, busyIntervals, tasks, meals
self.meal_list = [] def add_meal(self, meal): self.meal_list.append(meal) def order_menu_cost(self): total = float(0.0) for m in self.meal_list: total += m.cost print("If I ordered everything in the menu it would cost ${}".format(total)) if __name__ == '__main__': restaurant = Restaurant('The Mona Lisa Chip Shop') meal1 = Meal('Fish and chips', 8.5) meal2 = Meal('Pie and chips', 5.35) restaurant.add_meal(meal1) restaurant.add_meal(meal2) restaurant.order_menu_cost() #or """ restaurant = Restaurant('The Mona Lisa Chip Shop') meal1 = Meal('Fish and chips', 8.5) meal2 = Meal('Pie and chips', 5.35) restaurant.add_meal(meal1)
def day(self, delay, draw, only_vel=True): self.hist_vel = [0] self.hist_ran = [0] self.meals = [Meal(self.screen, self.meal_map_size, i) for i in range(1, self.meals_numbers + 1)] for c in self.creatures: self.hist_vel.append(math.floor(c.velocity * 10) / 10) self.hist_ran.append(math.floor(c.range * 10) / 10) # print(math.floor(c.velocity*10)/10, end=" ") c.search(self.meals) if draw: pygame.draw.circle(self.screen, self.color(c.velocity), c.pos, 10) if draw: pygame.display.update() time.sleep(delay * 3) # print() while self.loop(delay, draw, only_vel): if draw: self.screen.fill(WHITE) pass to_drop = [] for c in self.creatures: if not c.is_alive and c.eaten_meals == 0: to_drop.append(c) for d in to_drop: self.creatures.remove(d) to_add = [] for c in self.creatures: if c.eaten_meals == 2: pos_0 = 0 pos_1 = 0 if c.pos[0] == 10 or c.pos[0] == self.map_size - 10: pos_0 = c.pos[0] pos_1 = c.pos[1] + (randrange(5) - 2) * 30 + 3 else: pos_0 = c.pos[0] + (randrange(5) - 2) * 30 + 3 pos_1 = c.pos[1] if pos_0 < 0 or pos_0 > self.map_size: pos_0 = c.pos[0] if pos_1 < 0 or pos_1 > self.map_size: pos_1 = c.pos[1] x = randrange(10) if x == 0: pos_0 = 10 pos_1 = math.floor(self.map_size / 2) if x == 1: pos_0 = self.map_size - 10 pos_1 = math.floor(self.map_size / 2) if x == 2: pos_1 = 10 pos_0 = math.floor(self.map_size / 2) if x == 3: pos_1 = self.map_size - 10 pos_0 = math.floor(self.map_size / 2) vel = c.velocity random_num = randrange(20) - 10 if random_num > 5: vel = vel + 0.22 * vel if random_num < -5: vel = vel - 0.22 * vel if not only_vel: ran = c.range random_num = randrange(20) - 10 if random_num > 5: ran = ran + 0.1 * ran if random_num < -5: ran = ran - 0.1 * ran else: ran = 600 to_add.append(Creature(pos_0, pos_1, 55, vel, ran)) c.actual_energy = c.max_energy c.is_eaten = False c.returned = False c.returning = False c.is_alive = True c.eaten_meals = 0 c.actual_step = 0 c.actual_step_to_home = 0 c.move_plan = [] c.move_home_plan = [] for a in to_add: self.creatures.append(a) del self.meals self.screen.fill(WHITE) time.sleep(delay * 3)
from school_data import SchoolData from meal import Meal from PyQt5.QtWidgets import QApplication import sys from main_window import MainWindow school_data = SchoolData() meal = Meal() # school_data.crawl_db() # print(meal.get_month(list(school_data.get_db(schl_nm=('천안쌍용고등학교', '=')))[0], 2020, 5)) app = QApplication(sys.argv) main_window = MainWindow(school_data, meal) main_window.show() sys.exit(app.exec_())
def entries(self, entries): if entries == []: print("Entries can't be empty") return self.__entries = [Meal.from_dict(entry) for entry in entries]
def add_meal(self, name, price): meal = Meal(name,price) self.__entries.append(meal)
def log_cabin_file(self, cabin_file): #sort keys to standardize output all_keys = [] for key in self.order_info: all_keys += [key] all_keys.sort() #collect all order info text = "" for key in all_keys: text += key + " " + str(self.order_info[key]).upper() + "\n" cabin_file.write(text) cabin_file.write("\n") #collect all meals all_meals = [] for item in self.order_info["item_list"]: meal = Meal(item) all_meals += [meal] #calculate all supplies and ingredients all_supplies = {} all_ingredients = {} all_pp = {} for meal in all_meals: meal_supplies = meal.get_supplies() meal_ingredients = meal.get_ingredients() meal_pp = meal.get_per_person_supplies() meal_people = meal.get_people() # print(meal.meal) # print(meal_supplies) # print(meal_ingredients) # print(meal_people) #adds supplies if supply hasn't been added yet for supply in meal_supplies: if supply[0] not in all_supplies: all_supplies[supply[0]] = int(supply[1]) else: old_supply_num = all_supplies[supply[0]] new_supply_num = int(supply[1]) if (old_supply_num < new_supply_num): all_supplies[supply[0]] = new_supply_num # print("ingred list 1", all_ingredients) #adds ingredient for ingredient in meal_ingredients: num_to_add = math.ceil(float(ingredient[1]) * (self.order_info["num_people"] / meal_people)) if ingredient[0] in all_ingredients: all_ingredients[ingredient[0]] = all_ingredients[ingredient[0]] + num_to_add else: all_ingredients[ingredient[0]] = num_to_add # print("ingred list 2", all_ingredients) for per_person in meal_pp: num_to_add = (int(per_person[1]) * self.order_info["num_people"]) if per_person[0] not in all_pp: all_pp[per_person[0]] = num_to_add else: old_pp_num = all_pp[per_person[0]] new_pp_num = int(per_person[1]) if (old_pp_num < new_pp_num): all_pp[per_person[0]] = new_pp_num #sort lists so that each output is deterministic supplies_list = self.dictionary_to_sorted_list(all_supplies) ingredients_list = self.dictionary_to_sorted_list(all_ingredients) pp_list = self.dictionary_to_sorted_list(all_pp) #prints to file, overwriting anything that was written before cabin_file.write("SUPPLIES\n") for supply in supplies_list: cabin_file.write(supply + " " + str(all_supplies[supply]) + "\n") cabin_file.write("\n") for per_person in pp_list: cabin_file.write(per_person + " " + str(all_pp[per_person]) + "\n") cabin_file.write("\n") cabin_file.write("INGREDIENTS\n") for ingredient in ingredients_list: cabin_file.write(ingredient + " " + str(all_ingredients[ingredient]) + "\n")
LOADING_MEALS_NUMBER = 100 myclient = pymongo.MongoClient('mongodb://localhost:27017/') my_db = myclient['test'] my_col = my_db['Meals'] def parse_ingredients(body): ingredients = [] for i in range(1,21): ingredient = body['strIngredient{}'.format(i)] if ingredient == '': break else: ingredients.append(ingredient) return ingredients if __name__ == '__main__': for i in range(LOADING_MEALS_NUMBER): response = requests.get('https://www.themealdb.com/api/json/v1/1/random.php') body = response.json()['meals'][0] meal = Meal( name = body['strMeal'], cuisine = body['strArea'], category = body['strCategory'], ingredients = parse_ingredients(body) ) print(meal) if not my_col.find_one({'name': meal.name}): my_col.insert_one(meal.to_dict())
""" Building a complex product from many simple sub-component by common way or choosing any component which you want to. ref: https://www.tutorialspoint.com/design_pattern/builder_pattern.htm """ from meal_builder import MealBuilder from meal import Meal from burger import ChickenBurger, VegBurger from drink import Pepsi, Coke if __name__ == "__main__": combo = MealBuilder() print("===Combo 1===") combo_1 = combo.prepare_non_veg_meal() combo_1.show_items() print("Total cost: ", combo_1.get_cost()) print("===Combo 2===") combo_2 = combo.prepare_combo_burger() combo_2.show_items() print("Total cost: ", combo_2.get_cost()) print("===Ordering by customer===") ordering = Meal() ordering.add_item(ChickenBurger()) ordering.add_item(VegBurger()) ordering.add_item(Pepsi()) ordering.add_item(Pepsi()) ordering.show_items() print("Total cost: ", ordering.get_cost())
from ingredient import Ingredient, IngredientType from dish import Dish from meal import Meal import logging logging.basicConfig(filename='test.log', level=logging.DEBUG, format='%(asctime)s:%(name)s:%(levelname)s:%(message)s') grnPepper = Ingredient('green pepper', IngredientType.VEGETABLE) banana = Ingredient('banana', IngredientType.FRUIT) strawberry = Ingredient('strawberry', IngredientType.FRUIT) spinach = Ingredient('spinach', IngredientType.VEGETABLE) sampleDish1 = Dish('Dish 1', [grnPepper, spinach], 'Cut 4oz of spinach and 1 oz of green pepprs. Place in pot with 16oz of water. Boil for one hour. Serve') sampleDish2 = Dish('Dish 2', [strawberry, banana], 'Cut 4oz of strawberries and 2 oz of bananas. Place in bowl and toss.') sampleMeal = Meal([sampleDish1, sampleDish2, banana]) logging.debug(sampleMeal.getMeal())
def readFile(lines): numberOfDays = int(lines[0]) iterator = 1 D = {} while iterator <= numberOfDays: availablePeriod = lines[iterator].strip('\n').split(' ') D[availablePeriod[0]] = (availablePeriod[1], availablePeriod[2]) iterator += 1 U = createInvervalsForDays(D) daysId = {} i = 1 for day in D.keys(): D[day] = i daysId[i] = day i += 1 numberOfBusyPeriods = int(lines[iterator]) iterator += 1 busyPeriods = {} busyPeriodId = 1 while iterator <= (numberOfDays + numberOfBusyPeriods + 1): busyPeriodsPerDay = lines[iterator].strip('\n').split(' ') periods = {} periodsIterator = 2 for i in range(int(busyPeriodsPerDay[1])): periods[i + 1] = (busyPeriodsPerDay[periodsIterator], busyPeriodsPerDay[periodsIterator + 1]) periodsIterator += 2 busyPeriods[busyPeriodsPerDay[0]] = periods iterator += 1 busyIntervals = createBusyIntervals(busyPeriods) A = {} E = {} c = {} b = {} intervals = U numberOfTasks = int(lines[iterator]) iterator += 1 tasks = {} while iterator <= (numberOfDays + numberOfBusyPeriods + numberOfTasks + 2): line = lines[iterator].strip('\n').split(' ') daysItMustBeDone = [] numberOfDaysItMustBeDone = int(line[2]) for i in range(numberOfDaysItMustBeDone): daysItMustBeDone.append(line[i + 3]) itMustBeDoneBeforeBusyInterval = False busyIntervalThatTheTaskMustBeDoneBefore = 0 if (line[int(line[2]) + 4] != '-1'): itMustBeDoneBeforeBusyInterval = True interval = line[int(line[2]) + 6].split(':') busyIntervalThatTheTaskMustBeDoneBefore = (line[int(line[2]) + 5], (int(interval[0]), int(interval[1]))) A[line[0]] = None E[line[0]] = daysItMustBeDone c[line[0]] = int(line[1]) * 4 b[line[0]] = int(line[int(line[2]) + 3]) * 4 tasks[line[0]] = Task(line[0], int(line[1]) * 4, daysItMustBeDone, int(line[int(line[2]) + 3]) * 4, itMustBeDoneBeforeBusyInterval, busyIntervalThatTheTaskMustBeDoneBefore) iterator += 1 N = {} m = {} h = {} for task in tasks.keys(): if (tasks[task].busyIntervalThatTheTaskMustBeDoneBefore != 0): N[task] = None m[task] = U[ tasks[task].busyIntervalThatTheTaskMustBeDoneBefore[0]][( tasks[task].busyIntervalThatTheTaskMustBeDoneBefore[1][0], tasks[task].busyIntervalThatTheTaskMustBeDoneBefore[1][1])] h[task] = D[tasks[task].busyIntervalThatTheTaskMustBeDoneBefore[0]] R = {} t = {} y = {} numberOfMeals = int(lines[iterator]) iterator += 1 meals = {} while iterator <= (numberOfDays + numberOfBusyPeriods + numberOfTasks + numberOfMeals + 3): line = lines[iterator].strip('\n').split(' ') R[line[0]] = int(int(line[3]) / 15) t[line[0]] = {} y[line[0]] = {} meals[line[0]] = Meal(line[0], line[1], line[2], line[3]) for day in U.keys(): startInterval = meals[line[0]].possibleIntervals[0] endInterval = meals[line[0]].possibleIntervals[-1] t[line[0]][day] = U[day][(int(startInterval[0]), (int(startInterval[1])))] y[line[0]][day] = U[day][(int(endInterval[0]), (int(endInterval[1])))] iterator += 1 L = A.copy() for meal in R.keys(): L[meal] = None I = copy.deepcopy(U) for day in busyIntervals.keys(): for interval in busyIntervals[day].keys(): del I[day][interval] return D, U, A, E, c, b, N, m, h, R, t, y, L, I, busyIntervals, daysId
tui.run() food_dao = DAO() oats = FoodItem('oats', '40', 'g', '150', '25', '4', '4', '4', '2') banana = FoodItem('banana', '1', 'banana', '75', '12', '0', '1', '1', '8') #print(oats) #print(banana) #breakfast = Meal() #breakfast.add_ingredient(oats, 100) #breakfast.add_ingredient(banana, 0.5) #print(breakfast) #breakfast.calc_meal_macros() breakfast = Meal() breakfast.add_ingredient(oats, 125) #print(breakfast) #print(breakfast.get_ingredients()) #oats.proportionalize(125)