def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ list_options = ["1. Add new record to table", "2. Remove a record with a given id from the table", "3. Update specified record in the table", "4. How many different kinds of game are available of each manufacturer?", "5. What is the average amount of games in stock of a given manufacturer?"] program_works = True while program_works: table = store.get_table() title_list = ["ID", "TITLE", "MANUFACTURER", "PRICE (in $)", "IN STOCK"] terminal_view.print_table(table, title_list) answer = terminal_view.get_choice(list_options) if answer == "1": record = terminal_view.get_inputs(["ID: ","Title of the game: ","Manufacturer: ","Price in dollars: ","In stock (number): "],"Please provide information: \n") common.add(table, record) store.save_table(table) elif answer == "2": id_ = terminal_view.get_input("Please enter id number: ") common.remove(table, id_) store.save_table(table) elif answer == "3": id_ = terminal_view.get_input("Please enter id number: ") record = terminal_view.get_inputs(["ID: ","Title of the game: ","Manufacturer: ","Price in dollars: ","In stock (number): "],"Please provide information: \n") common.update(table, id_, record) store.save_table(table) elif answer =="4": store.get_counts_by_manufacturers(table) elif answer == "5": store.get_average_by_manufacturer(table, manufacturer) elif answer == "0": program_works = False else: terminal_view.print_error_message("There is no such choice. Choose from 1 to 5") return
def run(): options = [ "Add", "Remove", "Update", "Count by manufacturer", "Average games in stock by manufacturer" ] common_options = ["Title: ", "Manufacturer: ", "Price: ", "In stock: "] file = "model/store/games.csv" title_list = ["Id", "Title", "Manufacturer", "Price", "In stock"] choice = None terminal_clear = True while choice != '0': if terminal_clear: table = common.clear_instructions(file, title_list) choice = terminal_view.get_choice_submenu(options) terminal_clear = True if choice == '1': common.add(file, common_options) elif choice == '2': common.remove(file) elif choice == '3': common.update(file, common_options) elif choice == '4': msg = "Products by manufacturer:\n" terminal_view.print_result( store.get_counts_by_manufacturers(table), msg) terminal_clear = False elif choice == '5': manufacturer = terminal_view.get_inputs( ["Manufacturer: "], "Please provide manufacturer name") msg = "Average by " + manufacturer[0] + ":" value = store.get_average_by_manufacturer(table, manufacturer[0]) terminal_view.print_result(value, msg) terminal_clear = False else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ # your code menu_store = [ "Print store list", "Add to store list", "Remove form store list", "Update record in store list", "Number of games in the manufacture", "Average amount of games in stock of a given manufacturer " ] title = ["ID", "Title", "Manufacturer", "Price", "In_stock"] title_del = ["Input ID: "] choice = None while choice != "0": choice = terminal_view.get_choice(menu_store) if choice == "1": terminal_view.print_table(store.get_data(), title) if choice == "2": store.new_record( common.get_user_inp_record( terminal_view.get_inputs(title[1:], "")), "model/store/games.csv") if choice == "3": store.delete_record( store.get_data(), common.get_user_inp_record( terminal_view.get_inputs(title_del, "")), "model/store/games.csv") if choice == "4": store.update_record( store.get_data(), common.get_user_inp_record( terminal_view.get_inputs(title_del, "")), terminal_view.get_inputs(title[1:], ""), "model/store/games.csv") if choice == "5": terminal_view.print_result( store.get_counts_by_manufacturers(store.get_data()), "Different kinds of game are available of each manufacturer: ") if choice == "6": terminal_view.print_result( store.get_average_by_manufacturer( store.get_data(), common.get_user_inp_record( terminal_view.get_inputs(["Input manufactures: "], ""))), "Average games in manufacturer: ")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ table_headers = ['ID', 'Title', 'Manufacturer', 'Price', 'In Stock'] choice = None filename = 'model/store/games.csv' columns_headers = ['Title', 'Manufacturer', 'Price', 'In Stock'] ask_information = "Please provide your personal information" common.print_art(0) while choice != "0": choice = terminal_view.get_submenu_choice(['Add', 'Remove', 'Update',\ 'How many different kinds of game are available of each manufacturer?',\ 'What is the average amount of games in stock of a given manufacturer?']) table = common.get_table_from_file(filename) if choice[0] == "1": common.clear_terminal() common.adding(table, table_headers, filename, columns_headers, ask_information) elif choice[0] == "2": common.clear_terminal() common.removing(table, table_headers, id, filename) elif choice == "3": common.clear_terminal() common.updating(table, table_headers, id, filename, columns_headers, ask_information) elif choice == "4": common.clear_terminal() terminal_view.print_table(table, table_headers) games_count = store.get_counts_by_manufacturers(table) terminal_view.print_result('Manufacturer', games_count) elif choice == "5": common.clear_terminal() terminal_view.print_table(table, table_headers) manufacturer = terminal_view.get_inputs(['Manufacturer'], 'Which manufacturer?') games_average = store.get_average_by_manufacturer( table, manufacturer[0]) terminal_view.print_result('Avarage amount in stock: ', games_average) elif int(choice) >= 6: common.clear_terminal() terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. """ list_options = [ 'Store', 'Show all data', 'Add', 'Remove', 'Update', 'Get counts by manufacturers', 'Get average by manufacturer', 'Exit to main menu' ] list_labels = [['Title', str], ['Manufacturer', str], ['Price', int], ['In stock', int]] data_file = "model/store/games.csv" crud_module = store while True: table = data_manager.get_table_from_file(data_file) max_id = len(table) user_choice = terminal_view.get_choice(list_options) if user_choice in ['1', '2', '3', '4']: make_crud(crud_module, list_labels, list_options, max_id, table, user_choice) elif user_choice == '5': terminal_view.print_result( store.get_counts_by_manufacturers(table), 'Counts by manufactures') elif user_choice == '6': manufacturer = terminal_view.get_inputs([ ['Manufacturer to get average', str], ], 'Manufacturer') terminal_view.print_result( store.get_average_by_manufacturer(table, *manufacturer), 'Average by {}'.format(*manufacturer)) elif user_choice == '0': break else: terminal_view.print_error_message("There is no such choice.")
def test_get_average_by_manufacturer(self): table = data_manager.get_table_from_file(self.data_file) result = store.get_average_by_manufacturer(table, "Ensemble Studios") self.assertEqual(result, 12.25)
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ common.clear() title = 'Store menu' options = [ "Add new record to table", "Remove a record with a given id from the table.", "Updates specified record in the table.", "How many different kinds of game are available of each manufacturer?", "What is the average amount of games in stock of a given manufacturer?" ] exit_message = "Back to main menu" title_list = ["ID", "TITLE", "MANUFACTURER", "PRICE", "IN STOCK"] table = store.data_manager.get_table_from_file('model/store/games.csv') choice = None while choice != "0": terminal_view.print_table(table, title_list) choice = terminal_view.get_choice(title, options, exit_message) if choice == "1": record = terminal_view.get_inputs( title_list, 'Please add following informations :', table) updated_table = store.add(table, record) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "2": id_ = terminal_view.get_inputs(['Id'], 'Please give ID to remove :', table) updated_table = store.remove(table, id_) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "3": id_ = terminal_view.get_inputs(['Id'], 'Please give ID of changed line :', table) record = terminal_view.get_inputs( title_list, 'Please add following informations :', table) updated_table = store.update(table, id_, record) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "4": label = "The kinds of game that are available of each manufacturer: " result = store.get_counts_by_manufacturers(table) terminal_view.print_result(result, label) common.exit_prompt() common.clear() elif choice == "5": manufacturer = terminal_view.get_inputs( ['Manufacturer : '], 'Please select a manufacturer :') manufacturer = manufacturer[0] result = str(store.get_average_by_manufacturer( table, manufacturer)) label = "The average amount of games in stock of {} ".format( manufacturer) terminal_view.print_result(result, label) common.exit_prompt() common.clear() elif choice != 0: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ title = "Store manager" options = ["Add item", "Remove item", "Update item", "Show how many different kinds of game are available of each manufacturer", "Show average amount of games in stock of a given manufacturer"] exit_message = "Back to main menu" title_list = [ ['Name'], ['Manufacturer'], ['Price'], ['Number in stock']] data_file = "model/store/games.csv" table = data_manager.get_table_from_file(data_file) terminal_view.print_table(table, title_list) choice = None while choice != "0": choice = terminal_view.get_choice(title, options, exit_message) if choice == "1": record = [] index = 0 inputs = terminal_view.get_inputs(title_list, title) for i in inputs: record.insert(index, i) index += 1 store.add(table, record) terminal_view.print_table(table, title_list) elif choice == "2": user_input = terminal_view.get_inputs(["Enter ID: "], "") store.remove(table, user_input[0]) terminal_view.print_table(table, title_list) elif choice == "3": record = [] index = 0 user_input = terminal_view.get_inputs(["Enter ID: "], "") inputs = terminal_view.get_inputs(title_list, title) for i in inputs: record.insert(index, i) index += 1 store.update(table, user_input[0], record) terminal_view.print_table(table, title_list) elif choice == "4": store.get_counts_by_manufacturers(table) terminal_view.print_result(store.get_counts_by_manufacturers( table), 'how many different kinds of game are available of each manufacturer: ') elif choice == "5": user_input = input('Enter manufacturer:') store.get_average_by_manufacturer(table, user_input) terminal_view.print_result(store.get_average_by_manufacturer( table, user_input), 'Average amount of games in stock. Manufacturer: ' + user_input) else: terminal_view.print_error_message("You have chosen back to menu.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ _FILENAME = 'model/store/games.csv' _options = [ "Add a new game", "Remove a game", "Update a game", "See count of games for each manufacturer", "See the average games stock for an specific manufacturer" ] title_list = ['Id', 'Title', 'Manufacturer', 'Price', 'Stock'] is_running = True while is_running is True: table = common.get_table(_FILENAME) choice = terminal_view.get_choice('Store menu', _options, 'Back to main menu') if choice == "1": game = terminal_view.get_inputs( ['Title', 'Manufacturer', 'Price', 'in stock'], 'Please provide game information') updated_table = store.add(table, game) common.write_table(updated_table, _FILENAME) elif choice == "2": terminal_view.print_table(table, title_list) index = terminal_view.get_inputs( ['Choose Id of the game to be removed: '], '') id_ = common.find_id(table, int(index[0])) updated_table = store.remove(table, id_) common.write_table(updated_table, _FILENAME) elif choice == "3": terminal_view.print_table(table, title_list) index = terminal_view.get_inputs( ['Choose Id of the game to be edited: '], '') id_ = common.find_id(table, int(index[0])) game = terminal_view.get_inputs( ['Title', 'Manufacturer', 'Price', 'in stock'], 'Please provide updated information for this game: ') updated_table = store.update(table, id_, game) common.write_table(updated_table, _FILENAME) elif choice == "4": count = store.get_counts_by_manufacturers(table) terminal_view.print_result( count, 'Count of games available for each manufacturer: ') elif choice == "5": manufacturer = terminal_view.get_inputs(['Manufacturer: '], '') average_stock = store.get_average_by_manufacturer( table, manufacturer[0]) terminal_view.print_result(str(average_stock), 'Average game stock: ') elif choice == "0": is_running = False else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ table = store.get_store_table_from_file() title_list = ["ID", "Title", "Manufacturer", "Price [$]", "In stock"] options = [ "View records", "Add record", "Remove record", "Update record", "How many different kinds of game are available of each manufacturer?", "What is the average amount of games in stock of a given manufacturer?" ] choice = None while choice != "0": choice = terminal_view.get_choice_inner_menu(options, "Store manager") if choice == "1": terminal_view.print_table(table, title_list) elif choice == "2": record = terminal_view.get_inputs(title_list[1::], "Please provide new item data") if record[2].isdigit() and record[3].isdigit(): table = store.add(table, record) else: terminal_view.print_error_message("Wrong input!") elif choice == "3": id_to_delete_table = terminal_view.get_inputs(["ID"], "Item to delete") id_to_delete = id_to_delete_table[0] table = store.remove(table, id_to_delete) elif choice == "4": records = terminal_view.get_inputs(title_list, "Edit item") record_id = records[0] table = store.update(table, record_id, records) elif choice == "5": amount_of_games = store.get_counts_by_manufacturers(table) list_from_dict = amount_of_games.items() manufacturer_count = ["MANUFACTURERS", "GAMES"] terminal_view.print_table(list_from_dict, manufacturer_count) elif choice == "6": choose_manufacturer = terminal_view.get_inputs([ "Manufacturer" ], "For which manufacturer would you like to check the average amount of games in stock?" ) manufacturer = choose_manufacturer[0] avg_amount = store.get_average_by_manufacturer(table, manufacturer) while avg_amount == False: choose_manufacturer = terminal_view.get_inputs( ["Put existing manufacturer"], "No such manufacturer in list:") manufacturer = choose_manufacturer[0] avg_amount = store.get_average_by_manufacturer( table, manufacturer) title_two = ["Manufacturer", "Average amount of games in stock"] table_two = [[manufacturer, str(avg_amount)]] terminal_view.print_table(table_two, title_two) elif choice != "0": terminal_view.print_error_message("There is no such choice.")
def run(): terminal_view.clear() options = [ "Print list", "Add record", "Update record", "Remove record", "Get counts by manufacturers", "Get averege by manufacturer", "Get oldest game", "Get chepest game", "Get age by", "Get game by" ] file_list = "./model/store/games.csv" list_labels = [ 'id: ', 'title: ', 'manufacturer: ', 'price: ', 'release_date (yyyy-mm-dd): ' ] remove = [''] choice = None while choice != "0": choice = terminal_view.get_choice('GAMES MENU', options) terminal_view.clear() if choice == "1": terminal_view.print_table( data_manager.get_table_from_file(file_list), 'GAMES list') elif choice == "2": store.create( data_manager.get_table_from_file(file_list), terminal_view.get_inputs(list_labels, 'Enter personal data here:', file_list), file_list) elif choice == "3": store.update( data_manager.get_table_from_file(file_list), terminal_view.get_inputs( remove, 'Enter id, name or e-mail to update: ', ''), terminal_view.get_inputs(list_labels[1:], 'Enter id, name or e-mail to remove', file_list), file_list) elif choice == "4": store.delete( data_manager.get_table_from_file(file_list), terminal_view.get_inputs( remove, 'Enter id, name or e-mail to remove: ', ''), file_list) elif choice == "5": terminal_view.print_table( store.get_counts_by_manufacturers( data_manager.get_table_from_file(file_list)), 'The record is') elif choice == "6": terminal_view.print_result( store.get_average_by_manufacturer( data_manager.get_table_from_file(file_list), terminal_view.get_inputs(remove, 'Enter the game title', '')), 'Average by manufacturer: ') elif choice == "7": terminal_view.print_result( store.get_oldest_game( data_manager.get_table_from_file(file_list)), 'Get the oldest game') elif choice == "8": terminal_view.print_result( store.get_cheapest_game( data_manager.get_table_from_file(file_list)), 'Get the the cheapest game') elif choice == "9": terminal_view.print_result( store.get_age_by( terminal_view.get_inputs(remove, 'Enter the game title', ''), data_manager.get_table_from_file(file_list), terminal_view.get_inputs(remove, 'Enter the current year: ', '')), 'The age is: ') elif choice == "10": terminal_view.print_table( store.get_game_by( terminal_view.get_inputs(remove, 'Enter the game title', ''), data_manager.get_table_from_file(file_list)), 'The game is/are: ') else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ options = [ "Add new record to table", "Remove a record with a given id from the table", "Update specified record in the table", "Number of different kinds of game that are available of each manufacturer", "Average amount of games in stock of a given manufacturer", "Print table" ] title_list = ["*id", "* title", "* manufacturer", "* price", "* in_stock"] os.system('clear') choice = None while choice != "0": terminal_view.print_menu("What do you want to do:", options, "Back to main menu") choice = terminal_view.get_choice(options) os.system('clear') if choice == "1": # to jest dzialajacy plik model/store/games.csv file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) record = terminal_view.get_inputs(title_list, "Enter data: ") table = store.add(table, record) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been added ***') common.waiting() os.system("clear") elif choice == "2": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) id_ = common.get_input("Get id to removed: ") table = store.remove(table, id_) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been removed ***') common.waiting() os.system("clear") elif choice == "3": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) id_ = common.get_input("Enter id to update: ") record = terminal_view.get_inputs(title_list, "Enter data: ") table = store.update(table, id_, record) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been updated ***') common.waiting() os.system("clear") elif choice == "4": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) dictionary = store.get_counts_by_manufacturers(table) terminal_view.print_dictionary( "Number of different kinds of game that are" + "available of each manufacturer:", dictionary) common.waiting() os.system("clear") elif choice == "5": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) manufacturer = common.get_input("Enter a manufacturer: ") print(store.get_average_by_manufacturer(table, manufacturer)) common.waiting() os.system("clear") elif choice == "6": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) common.waiting() os.system("clear") else: if choice != "0": terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ list_of_games = store.get_data_to_list() # your code options = [ "Add new record", "Remove a record", "Update record", "Count games each manufacturer", "Average of games", "Print table" ] choice = None title_list = ["ID", "TITLE", "MANUFACTURER", "PRICE", "IN STOCK"] while choice != "0": choice = terminal_view.get_choice(options, "Back to main menu") if choice == "1": new_record = terminal_view.get_inputs( ["Title: ", "Manufacturer: ", "Price: ", "In stock: "], "Please enter value: ") new_record.insert(0, store.get_random_id(list_of_games)) list_of_games = store.add(list_of_games, new_record) elif choice == "2": id_of_record_to_remove = ask_untill_correct(list_of_games) list_of_games = store.remove( list_of_games, common.check_id_by_number(list_of_games, int(id_of_record_to_remove))) elif choice == "3": id_of_record_to_update = ask_untill_correct(list_of_games) updated_record = terminal_view.get_inputs( ["Title: ", "Manufacturer: ", "Price: ", "In stock: "], "Please enter value: ") list_of_games = store.update( list_of_games, common.check_id_by_number(list_of_games, int(id_of_record_to_update)), updated_record) elif choice == "4": label = "The kinds of game that are available of each manufacturer: " result = store.get_counts_by_manufacturers(list_of_games) terminal_view.print_result(result, label) elif choice == "5": manufacturer = terminal_view.get_inputs( ['Manufacturer : '], 'Please select a manufacturer :') manufacturer = manufacturer[0] result = str( store.get_average_by_manufacturer(list_of_games, manufacturer)) label = "The average amount of games in stock of {} ".format( manufacturer) terminal_view.print_result(result, label) elif choice == '6': terminal_view.print_table(list_of_games, title_list) elif choice == "0": store.export_list_to_file(list_of_games) else: terminal_view.print_error_message("There is no such choice.")