def main(): # creation variables cook = Cook(COOK_SURNAME, COOK_NAME) government = Government() food = [] panhandle_counter = 0 # greeting print(GREETING_MESSAGE + cook.surname + " " + cook.name + "\n") # cooking food for i in range(AMOUNT_OF_DISHES): food.append(cook.cook_food()) # the main action for i in range(AMOUNT_OF_CUSTOMERS): customer = Customer(random.choice(CUSTOMERS_SURNAMES), random.choice(CUSTOMERS_NAMES)) print(str(customer) + "\n") while(customer.calorie_requirement > 0): print_menu(food) print(PURCHASE_CHOICE_MESSAGE) food_choice = input_num() if (check_element(food_choice)): continue if(customer.money >= food[food_choice - 1].cost): sell_food(food, food_choice, customer, cook) if(customer.health == 0): customer.die() break else: print(NOT_ENOUGH_MONEY) no_money_choice = input_num() if(no_money_choice == 1): continue elif(no_money_choice == 21): panhandle_action(panhandle_counter, customer, food) if customer.health == 0 or customer.calorie_requirement > 0: customer.die() break else: print("You have entered the invalid element!") continue if not (customer.health == 0): print(THANKS_MESSAGE) if random.randint(1, 3) == 1: amount_of_seized = government.check_canteen(food, cook) if (amount_of_seized > 0): for i in range(amount_of_seized): food.append(cook.cook_food()) if cook.isBankrupt(): break print("Amount of created food: " + str(Food.counter_food()))
def setUp(self): self.o = Order({ u'id': u'a8cfcb76-7f24-4420-a5ba-d46dd77bdffd', u'prepTime': 4, u'name': u'Banana Split' }) cooking = MTList() cooking.put(self.o) self.c = Cook(MTList(), cooking)
def main(i): order_taker = OrderTaker(order_queue_name, queue_region, aws_access_key_id, aws_secret_access_key) cook = Cook(aws_access_key_id, aws_secret_access_key) order = order_taker.take_order() omelet = cook.do_tasks(order) if omelet: sqs = SQSUtils(result_queue_name, queue_region, aws_access_key_id, aws_secret_access_key, logger=None) result_set = dict() result_set['result'] = omelet result_set['ticketId'] = order.get_ticket_id() sqs.write_message(json.dumps(result_set))
def main(i): order_taker = OrderTaker(order_queue_name, queue_region, aws_access_key_id, aws_secret_access_key) cook = Cook(aws_access_key_id, aws_secret_access_key) results = list() tasks = order_taker.deliver_order() if tasks: for task in tasks: results = cook.do_task(task) #return a list if results: #print results sqs = SQSUtils(result_queue_name, queue_region, aws_access_key_id, aws_secret_access_key, logger=None) result_set = dict() result_set['result'] = results result_set['ticketId'] = tasks[0]['ticketId'] sqs.write_message(json.dumps(result_set))
def __init__(self, cook_num: int): self.__cook_number = cook_num self.__cooks = [Cook() for _ in range(cook_num)] self.__food_cooking_time = {1: 30, 2: 20, 3: 10, 4: 15} self.__food_name = {1: "스테이크", 2: "스파게티", 3: "마카로니", 4: "그라탱"} self.__order_queue = []
class Testing(unittest.TestCase): def setUp(self): self.o = Order({ u'id': u'a8cfcb76-7f24-4420-a5ba-d46dd77bdffd', u'prepTime': 4, u'name': u'Banana Split' }) cooking = MTList() cooking.put(self.o) self.c = Cook(MTList(), cooking) def test_cook_order(self): self.c.cook_order() self.assertEqual(self.o, self.c.get_delivery_queue().get()) def test_get_order(self): self.assertIsInstance(self.c.get_order(), Order)
def __init__(self, message): super().__init__(2, message) self.cook = Cook() self.category = None
print("***********************************************") select = get_int(0,4) return select def get_int(min, max): x = int(input("Enter the numbers ")) while x < min or x > max: x = int(input("Enter the numbers between {} and {} ".format(min, max))) return x menu = get_menu() while menu != 0: if menu == 1: os.system("cls") ck = Cook() check = ck.writeCus(0,1) os.system("pause") elif menu == 2: os.system("cls") ck = Cook() check = ck.writeCus(1,1) os.system("pause") elif menu == 3: os.system("cls") ck = Cook() check = ck.writeCus(2,1) os.system("pause") elif menu == 4: os.system("cls") ck = Cook()
def parse(self, path: str) -> None: """Parse the file and instantiate a configured Cook object. Parse critical data points from raw text and encapsulate them into a Cook object. Args: path: The file path to the cook data. """ config = {} # Cook attribute configuration # Obtain filename, product, and lot. file_name = path[path.rfind('\\') + 1:].strip() config["fname"] = file_name config["product"], config["lot"] = file_name.strip(".txt").split('_') with open(path, 'r') as f: text = f.readlines() # Obtain program, start time, and oven number. header = text[1].split(',') # Isolate the report header config["program"] = header[1] start_info = header[3].replace('/', '-').strip() config["start_time"] = dt.strptime(start_info, "%m-%d-%Y %H:%M:%S") config["oven"] = text[2].split(',')[1][5:].strip() counter = dt.strptime("00:00", "%H:%M") curr_stage = 1 stages = {} # Add to config once all stage data is gathered # Iterate over the main text body. for this_line in text: if this_line.strip().endswith(",,"): # Target cook data line = this_line.split(',') # Obtain starting temperatures. if line[2] == "START": config["start_temps"] = self._get_temps(line) # Obtain final stage duration and ending temperatures. elif line[2] == "END": end_dur = self._get_stage(line, counter, curr_stage)[0] stages[f"Stage {curr_stage}"] = end_dur config["end_temps"] = self._get_temps(line) # Obtain stage data. elif int(line[2]) > curr_stage: _ = self._get_stage(line, counter, curr_stage) stages[f"Stage {curr_stage}"], counter, curr_stage = _ # Obtain in and out weights. elif this_line.startswith("In-weight:"): config["in_weight"] = self._get_weight(this_line) elif this_line.startswith("Out-weight:"): config["out_weight"] = self._get_weight(this_line) else: config["in_weight"], config["out_weight"] = -1, -1 # TODO Parse Comments and Errors. config["comments"], config["errors"] = [], [] # Configure the final Cook attributes. config["stages"] = stages duration = int(sum(stages.values())) config["duration"] = duration config["end_time"] = self._get_end_time(config["start_time"], duration) _yield = self._get_yield(config["in_weight"], config["out_weight"]) config["cook_yield"] = _yield self._current_cook = Cook(config) # Create the Cook object
class OvenReader(object): """Parse and output raw cook data. OvenReader parses raw cook data (in the form of a .txt file) to create a Cook() object and output data in an easy to read format. Public Methods: parse(): Parse data. output(): Output formatted data. """ def __init__(self) -> None: self._current_cook = None def _get_temps(self, text: str) -> list: """Return a list of temperatures as floats. Iterate over a string and ignore invalid characters. Args: text: The text to parse. """ chars = ('D', '', '\n') temps = [float(i) for i in text[8:] if i not in chars] return temps def _get_stage(self, line: str, counter: dt, stage: int) -> tuple: """Get current stage duration and update parsing counters. This function is used when parsing the main text body to update stage data. Args: line: The current line of text being parsed. counter: The current stage counter in use. stage: The current stage number. Returns: Return a tuple (stage_duration, new_counter, new_stage). """ new_counter = dt.strptime(line[0], "%H:%M") duration = (new_counter - counter).total_seconds() / 60 new_stage = stage + 1 return (duration, new_counter, new_stage) def _get_weight(self, text: str) -> int: """Return the weight found within the given line of text. Args: text: The string to iterate over. """ start = text.index(':') + 1 weight = text[start:].strip() if weight.isdigit(): return int(weight) else: return -1 def _get_yield(self, in_weight: int, out_weight: int) -> Union[int, float]: """Return the Cook yield. Args: in_weight: The in_weight of the cook. out_weight: The out_weight of the cook. Returns: Return -1 if either the in | out weight is not specified (-1), else return the true cook yield. """ if in_weight != -1 and out_weight != -1: return out_weight / in_weight else: return -1 def _get_end_time(self, start_time: dt, duration: int) -> dt: """Return the ending date and time of the cook. Args: start_time: The starting date and time. duration: The total duration of the cook (in minutes). """ end_time = start_time + delta(minutes=duration) return end_time def parse(self, path: str) -> None: """Parse the file and instantiate a configured Cook object. Parse critical data points from raw text and encapsulate them into a Cook object. Args: path: The file path to the cook data. """ config = {} # Cook attribute configuration # Obtain filename, product, and lot. file_name = path[path.rfind('\\') + 1:].strip() config["fname"] = file_name config["product"], config["lot"] = file_name.strip(".txt").split('_') with open(path, 'r') as f: text = f.readlines() # Obtain program, start time, and oven number. header = text[1].split(',') # Isolate the report header config["program"] = header[1] start_info = header[3].replace('/', '-').strip() config["start_time"] = dt.strptime(start_info, "%m-%d-%Y %H:%M:%S") config["oven"] = text[2].split(',')[1][5:].strip() counter = dt.strptime("00:00", "%H:%M") curr_stage = 1 stages = {} # Add to config once all stage data is gathered # Iterate over the main text body. for this_line in text: if this_line.strip().endswith(",,"): # Target cook data line = this_line.split(',') # Obtain starting temperatures. if line[2] == "START": config["start_temps"] = self._get_temps(line) # Obtain final stage duration and ending temperatures. elif line[2] == "END": end_dur = self._get_stage(line, counter, curr_stage)[0] stages[f"Stage {curr_stage}"] = end_dur config["end_temps"] = self._get_temps(line) # Obtain stage data. elif int(line[2]) > curr_stage: _ = self._get_stage(line, counter, curr_stage) stages[f"Stage {curr_stage}"], counter, curr_stage = _ # Obtain in and out weights. elif this_line.startswith("In-weight:"): config["in_weight"] = self._get_weight(this_line) elif this_line.startswith("Out-weight:"): config["out_weight"] = self._get_weight(this_line) else: config["in_weight"], config["out_weight"] = -1, -1 # TODO Parse Comments and Errors. config["comments"], config["errors"] = [], [] # Configure the final Cook attributes. config["stages"] = stages duration = int(sum(stages.values())) config["duration"] = duration config["end_time"] = self._get_end_time(config["start_time"], duration) _yield = self._get_yield(config["in_weight"], config["out_weight"]) config["cook_yield"] = _yield self._current_cook = Cook(config) # Create the Cook object def output(self, comments: bool = False, errors: bool = False) -> None: """Output formatted cook data for the current cook. Args: comments: Flag to control the output of comments (default=False). errors: Flag to control the output of errors (default=False). """ print(self._current_cook.compile_data(comments, errors))
def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs): self.markAsRead(author_id) # mark read message log.info("Message {} from {} in {}".format( message_object, thread_id, thread_type)) # log message incoming self.apiaiCon() # use ai function msgtext = message_object.text # read message log.info(msgtext) # log message if author_id != self.uid and thread_type == ThreadType.USER: self.request.query = msgtext # throw message to dialogflow response = self.request.getresponse( ) # receive response from server obj = json.load(response) # decode json to array log.info(obj) # log object from server Action = obj['result']['action'] # access to action of bot reply = obj['result']['fulfillment'][ 'speech'] # access to reply bot if Action == "weather" or Action == "weather.temperature": Result = self.WeatherConnector(obj) if Result == 1: self.send(Message( text= "Sorry, \nwe cannot collect data from the past or forecast more than 5 days" ), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) else: if Action == "weather": self.send( Message(text="There are {} in {} {}!!".format( Result[0], Result[1], Result[2])), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) else: self.send(Message( text="{} temperature is {} Celsius in {}!".format( Result[2], Result[0], Result[1])), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) else: ckas = Cook() # Create Cook object linkCk = ckas.start(msgtext, author_id) if linkCk == 1: log.info("=====>" + author_id) self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) else: log.info(linkCk) self.send(Message(text=linkCk), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) elif author_id == self.uid and msgtext == "bot_shutdown": self.send(Message(text="Bot shutting down"), thread_id=thread_id, thread_type=thread_type) self.markAsDelivered(author_id, thread_id) self.logout()