def sort_selection(database): """Menu for selecting which way to sort. Args: database (dict): Canteen database. """ if sort_option(): print("1: Sort by rank") print("2: Sort by distance") print("3: Sort by price") print("4: Sort by category") print("0: Back to main menu") user_option = check.user_input_index(0, 4) if user_option == 0: main_menu() elif user_option == 1: sorted_data = sort.by_rank(database) elif user_option == 2: sorted_data = sort.by_distance(database) elif user_option == 3: sorted_data = sort.by_price(database) elif user_option == 4: sorted_data = sort.by_category(database) # display sorted database using table display_table(sorted_data) choose_canteen(sorted_data) else: choose_canteen(database)
def menu_delete_data(list_canteen): """Menu for deleting data. Args: list_canteen ([[str, str, str,...]] -> list): List of all stall data imported from csv file. List has the same format as the data in the file. Returns: stall ([str, str, str,...] -> list): List of one stall data. Same format as data in csv file. """ # display table so that user can easily select which data to remove table = PrettyTable(['No.', 'Canteen', 'Stall Name', 'Category']) num = 1 for canteen in list_canteen: table.add_row([num, canteen[0], canteen[1], canteen[2]]) num += 1 print(table) print("Enter the corresponding number of a stall to delete it.") print("0: Back") # allow digit input from 0 to max number of stall user_option = check.user_input_index(0, len(list_canteen)) if user_option > 0: stall = list_canteen[user_option - 1] return stall else: return None
def get_canteen_name(): """Displays the list of canteen for the data input and lets the user to choose. Returns: canteen_name (str): The name of the canteen of which the user choose. """ print("Here is a list of canteen name") print("1: North Spine Food Court") print("2: Koufu") print("3: Canteen 1") print("4: Canteen 2") print("5: Canteen 9") print("6: Canteen 11") print("7: Canteen 13") print("8: Canteen 14") print("9: Canteen 16") print("10: The Quad Cafe") print("11: Foodgle Food Court") print("12: North Hill Food Court") print("Enter the option for canteen name:", end=" ") # only allow inputs from 1 to 12 for the 12 options option = check.user_input_index(1, 12) if option == 1: canteen_name = "North Spine Food Court" elif option == 2: canteen_name = "Koufu" elif option == 3: canteen_name = "Canteen 1" elif option == 4: canteen_name = "Canteen 2" elif option == 5: canteen_name = "Canteen 9" elif option == 6: canteen_name = "Canteen 11" elif option == 7: canteen_name = "Canteen 13" elif option == 8: canteen_name = "Canteen 14" elif option == 9: canteen_name = "Canteen 16" elif option == 10: canteen_name = "The Quad Cafe" elif option == 11: canteen_name = "Foodgle Food Court" elif option == 12: canteen_name = "North Hill Food Court" return canteen_name
def choose_canteen(database): """Asks the user to choose a canteen stall from the table. The number options are displayed on the table. Args: database (dict): Canteen database. """ list_canteen = list(database.items()) print("Enter the corresponding number of a stall to choose it.") print("0: Back to main menu") # allows inputs ranging from 0, to go back to main menu, # until the last number of canteen stall user_option = check.user_input_index(0, len(list_canteen)) if user_option > 0: stall = list_canteen[user_option - 1] display_info(database, stall) else: main_menu()
def menu_edit_database(): """Menu for modifying data.""" while True: print("1: Input data") print("2: Delete data") print("0: Back to main menu") option = check.user_input_index(0, 2) if option == 1: stall_data = menu_input_data() input_data(stall_data) elif option == 2: # get data from file with open("data/canteen_data.txt", "r") as csv_file: list_canteen = list(csv.reader(csv_file)) stall_data = menu_delete_data(list_canteen) if stall_data: delete_data(stall_data, list_canteen) else: break
def get_stall_category(): """Displays the list of stall categories for the data input and lets the user choose. Returns: stall_category (str): The stall category which the user chooses. """ print("Here is a list of stall categories") print("1: Halal") print("2: Chinese") print("3: Indian") print("4: Vegetarian") print("5: Japanese") print("6: Korean") print("7: Seafood") print("8: Singaporean") print("9: Others") print("Enter the option for stall category:", end=" ") # only allows inputs from 1 to 9 for the 9 options option = check.user_input_index(1, 9) if option == 1: stall_category = "Halal" elif option == 2: stall_category = "Chinese" elif option == 3: stall_category = "Indian" elif option == 4: stall_category = "Vegetarian" elif option == 5: stall_category = "Japanese" elif option == 6: stall_category = "Korean" elif option == 7: stall_category = "Seafood" elif option == 8: stall_category = "Singaporean" elif option == 9: stall_category = "Others" return stall_category
def main_menu(): """Main command line interface menu structure.""" search_result = {} # imports canteen database from file database = data.import_canteen_database(user_location) print("\nWelcome to the NTU F/B Recommendation System!") print( "Please enter the input number that corresponds to the option you'd like to choose.", end="\n\n") print("1: Search by price") print("2: Search by food (category)") print("3: Display all") print("4: Edit canteen database") print("5: Back to location selection") print("0: Quit program") # ask user for input, digit from 0-5 user_option = check.user_input_index(0, 5) if user_option == 1: search_result = price_search(database) elif user_option == 2: search_result = food_search(database) elif user_option == 3: search_result = database elif user_option == 4: data_input.menu_edit_database() return main_menu() elif user_option == 5: # goes back to main loop, and run the pygame program return None else: # exit python os._exit(1) if search_result: display_table(search_result) sort_selection(search_result) else: print("Not Found!") return main_menu()
def menu_input_data(): """Menu for adding new canteen data to the database. Stores the data inside a list. Returns: stall_data (list): A list containing with data of a new stall. Format: [canteen_name, stall_name, stall_category, stall_rating, food1, price1, food2, price2, ...] """ # ask user input for the new stall data canteen_name = get_canteen_name() print("Enter stall name:", end=" ") # stall name cannot be empty stall_name = check.non_empty_input() stall_category = get_stall_category() print("Enter stall rating (0-5):", end=" ") stall_rating = check.user_input_index(0, 5) # data order is adjusted according to the file stall_data = [canteen_name, stall_name, stall_category, stall_rating] menu = 0 while True: # user needs to enter at least 1 menu for each stall # food name cannot be empty if menu < 1: print("Enter food name:", end=" ") food_name = check.non_empty_input() else: # user can input '####' if they want to stop adding menu print("Enter '####' to terminate, Enter food name:", end=" ") food_name = check.non_empty_input() if food_name == "####": break print("Enter price:", end=" ") food_price = check.user_input_float() stall_data.extend([food_name, food_price]) menu += 1 # convert the data to string to be written to file stall_data = [str(data) for data in stall_data] return stall_data
def display_info(database, stall): """Displays information of stall in the form of table. Args: database (dict): Canteen database. stall ((key, value) -> tuple): Data of a stall. Format is similar to database but type is tuple. """ key, value = stall # format data for display purposes avg_price = convert.float_to_dollar(value[1]) distance = convert.pixel_to_meter(value[2]) distance = " ".join([str(distance), "m"]) menu = display_food_menu(value[3]) # displays directions in pygame and command line directions = transport.display_directions(stall, user_location) # create table object table = PrettyTable() # table header is on the leftmost column table.add_column('', [ 'Canteen', 'Stall Name', 'Category', 'Rating', 'Average Price', 'Distance', 'Menu', 'Directions' ]) table.add_column('Information', [ key[0], key[2], key[3], value[0], avg_price, distance, menu, directions ]) print(table) print("0: Back to main menu") print("1: Back to canteen stall selection") user_option = check.user_input_index(0, 1) if user_option == 0: main_menu() elif user_option == 1: # go back to table of all stalls display_table(database) choose_canteen(database)