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 """ options = [ "Add data", "Remove data", "Update data", "The customer ID with the Longest name", "Newsletter subscription", "Customer\'s name with the given ID" ] common_options = [ "Name: ", "E-mail: ", "Newsletter subscribtion ('1'-yes or '0'-no): " ] link_for_csv = "model/crm/customers.csv" title_list = ["ID", "Name", "E-mail", "Newsletter subscribtion"] choice = None dont_clear = False while choice != '0': if not dont_clear: os.system("clear") table = data_manager.get_table_from_file(link_for_csv) terminal_view.print_table(table, title_list) choice = terminal_view.get_choice_submenu(options) dont_clear = False if choice == '1': common.add(link_for_csv, common_options) elif choice == '2': common.remove(link_for_csv) elif choice == '3': common.update(link_for_csv, common_options) elif choice == '4': terminal_view.print_result( crm.get_longest_name_id(table), 'ID of the customer with the Longest name: ') dont_clear = True elif choice == '5': table_subscription = crm.get_subscribed_emails(table) terminal_view.print_result( table_subscription, 'Customers who has subscribed to the newsletter: ') dont_clear = True elif choice == '6': ID = terminal_view.get_input("ID: ", "Please enter ID: ") terminal_view.print_result( crm.get_name_by_id_from_table(table, ID), "Customer\'s name by given ID: ") dont_clear = True else: terminal_view.print_error_message( "There is no such choice, please try again")
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 item', 'Edit item', 'Remove item', 'Which items have not exceeded their durability yet', 'What are the average durability times for each manufacturer' ] link_to_csv = 'model/inventory/inventory.csv' common_options = [ 'Name of item: ', 'Manufacturer: ', 'Year of purchase: ', 'Years it can be used: ' ] title_list = [ "Id", "Name", "Manufacturer", "Year of purchase", "Years it can be used" ] choice = None dont_clear = False while choice != "0": if not dont_clear: os.system("clear") table = data_manager.get_table_from_file(link_to_csv) terminal_view.print_table(table, title_list) choice = terminal_view.get_choice_submenu(options) dont_clear = False if choice == "1": common.add(link_to_csv, common_options) elif choice == "2": common.update(link_to_csv, common_options) elif choice == "3": common.remove(link_to_csv) elif choice == "4": os.system("clear") table_to_print = inventory.get_available_items(table) terminal_view.print_table(table_to_print, labels) dont_clear = True elif choice == "5": terminal_view.print_result( inventory.get_average_durability_by_manufacturers(table), '\nWhat are the average durability times for each manufacturer: ' ) dont_clear = True else: terminal_view.print_error_message("There is no such choice.")
def run(): options = ["Add", "Remove", "Update", "Lowest price item ID", "Items sold between", "Game title by ID", "All the Customer\'s IDs", "The sales of each customer", "The sales of each customer", "The number of sales of each customer", "The number of sales of each customer: "] common_options = ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "] link_for_csv = "model/sales/sales.csv" title_list = ["ID", "Title", "Price", "Month", "Day", "Year", "Customer ID"] choice = None dont_clear = False while choice != '0': if not dont_clear: os.system("clear") table = data_manager.get_table_from_file(link_for_csv) terminal_view.print_table(table, title_list) choice = terminal_view.get_choice_submenu(options) dont_clear = False if choice == '1': common.add(link_for_csv, common_options) elif choice == '2': common.remove(link_for_csv) elif choice == '3': common.update(link_for_csv, common_options) elif choice == '4': lowest_price = sales.get_lowest_price_item_id(table) terminal_view.print_result(lowest_price, 'Lowest price game is: ') dont_clear = True elif choice == '5': dates_to_input = ['From month: ', 'From day: ', 'From year: ', 'To month:', 'To day: ', "To year: "] inputs = terminal_view.get_input(dates_to_input, "Please input appropriate data.") answer = sales.get_items_sold_between(table, int(inputs[0]), int(inputs[1]), int(inputs[2]), int(inputs[3]), int(inputs[4]), int(inputs[5])) terminal_view.print_table(answer, title_list) dont_clear = True elif choice == '6': dates_to_input = 'Input ID: ' inputs = terminal_view.get_input(dates_to_input, 'Please input appropriate data.') answer = sales.get_title_by_id(inputs) terminal_view.print_result(answer, 'Game title is: ') dont_clear = True elif choice == "7": terminal_view.print_result(sales.get_all_customer_ids_from_table(table), 'All the Customer\'s ID: ') dont_clear = True elif choice == "8": terminal_view.print_result(sales.get_all_sales_ids_for_customer_ids(), "The sales of each customer: ") dont_clear = True elif choice == "9": terminal_view.print_result(sales.get_all_sales_ids_for_customer_ids_form_table(table), "The sales of each customer: ") dont_clear = True elif choice == "10": terminal_view.print_result(sales.get_num_of_sales_per_customer_ids(), "The number of sales of each customer: ") dont_clear = True elif choice == "11": terminal_view.print_result(sales.get_num_of_sales_per_customer_ids_from_table(table), "The number of sales of each customer: ") dont_clear = True
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 data", "Remove data", "Update data", "Year with the highest profit", "The average profit for a given year" ] common_options = [ "Month: ", "Day: ", "Year: ", "Income (enter: 'in') or Outflow(enter:'out') money: ", "Amount: " ] link_for_csv = 'model/accounting/items.csv' title_list = [ "ID", "Month", "Day", "Year", "Income or Outflow money", "Amount" ] choice = None dont_clear = False while choice != "0": if not dont_clear: os.system("clear") table = data_manager.get_table_from_file(link_for_csv) terminal_view.print_table(table, title_list) choice = terminal_view.get_choice_submenu(options) dont_clear = False if choice == "1": common.add(link_for_csv, common_options) elif choice == "2": common.remove(link_for_csv) elif choice == "3": common.update(link_for_csv, common_options) elif choice == "4": terminal_view.print_result(accounting.which_year_max(table), "Year with the highest profit: ") dont_clear = True elif choice == "5": year = int( terminal_view.get_input( "Year: ", "Enter a year to find out an average profit: ")) terminal_view.print_result( accounting.avg_amount(table, year), 'The average profit for a given year: ') dont_clear = True else: terminal_view.print_error_message( "There is no such choice, please try again")
def add(common_options): """ Asks user for input and adds it into the table. Args: table (list): table to add new record to Returns: list: Table with a new record """ sales_table = common.get_table_from(sales_file) customers_table = common.get_table_from(customers_file) add_options = ["Add for an existing user", "Add new user"] customer_titles = ["ID", "Name", "E-mail", "Newsletter subscribtion"] customer_input_titles = ["Name: ", "E-mail: ", "Newsletter subscription: "] add_options = ["Add for an existing user", "Add new user"] os.system("clear") terminal_view.print_table(customers_table, customer_titles) adding_type = terminal_view.get_choice_submenu(add_options) if adding_type == '2': record = common.add(customers_file, customer_input_titles) os.system("clear") customers_table = common.get_table_from(customers_file) terminal_view.print_table(customers_table, customer_titles) if adding_type == '1' or adding_type == '2': id_ = sales_controller.input_for_add_menu() exists = False for element in customers_table: if element[0] == id_: exists = True if not exists: terminal_view.print_error_message("User not found") else: record = terminal_view.get_inputs( [opt for opt in common_options], "Please provide following data: ") record.append(id_) record.insert(0, model_common.generate_random(record)) sales_table.append(record) data_manager.write_table_to_file(sales_file, sales_table)
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", "Remove", "Update", "Oldest person", "Persons closest to average"] common_options = ["Name: ", "Year: "] file = "model/hr/persons.csv" title_list = ["Id", "Name", "Year"] choice = None dont_clear = False while choice != '0': if not dont_clear: os.system("clear") table = data_manager.get_table_from_file(file) terminal_view.print_table(table, title_list) choice = terminal_view.get_choice_submenu(options) dont_clear = False 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': terminal_view.print_result(hr.get_oldest_person(table), "Oldest persons:\n") dont_clear = True elif choice == '5': msg = "Persons with age closest to average:\n" terminal_view.print_result(hr.get_persons_closest_to_average(table), msg) dont_clear = True else: terminal_view.print_error_message("There is no such choice.")
def run(): options = [ "Add", "Remove", "Update", "Lowest price item ID", "Items sold between", "Game title by ID", "All the Customer\'s IDs", "Item that was sold most recently", "The sales of each customer", "The number of sales of each customer", "Sum of prices for given IDs", "Customer ID for Sale ID" ] common_options = ["Title: ", "Price: ", "Month: ", "Day: ", "Year: "] file = "model/sales/sales.csv" title_list = [ "ID", "Title", "Price", "Month", "Day", "Year", "Customer ID" ] choice = None terminal_clear = False while choice != '0': if not terminal_clear: os.system("clear") table = common.clear_instructions(file, title_list) choice = terminal_view.get_choice_submenu(options) terminal_clear = False if choice == '1': sales.add(common_options) elif choice == '2': sales.remove() elif choice == '3': sales.update(common_options) elif choice == '4': lowest_price = sales.get_lowest_price_item_id(table) terminal_view.print_result(lowest_price, 'Lowest price game is: ') terminal_clear = True elif choice == '5': dates_to_input = [ 'From month: ', 'From day: ', 'From year: ', 'To month:', 'To day: ', "To year: " ] inputs = terminal_view.get_input(dates_to_input, "Please input appropriate data.") answer = sales.get_items_sold_between(table, int(inputs[0]), int(inputs[1]), int(inputs[2]), int(inputs[3]), int(inputs[4]), int(inputs[5])) terminal_view.print_table(answer, title_list) terminal_clear = True elif choice == '6': dates_to_input = 'Input ID: ' inputs = terminal_view.get_input(dates_to_input, 'Please input appropriate Id.') answer = sales.get_title_by_id(inputs) terminal_view.print_result(answer + '\n', 'Game title is: \n') terminal_clear = True elif choice == "7": terminal_view.print_result( sales.get_all_customer_ids_from_table(table), 'All the Customer\'s ID: ') terminal_clear = True elif choice == "8": terminal_view.print_result(sales.get_item_id_sold_last(), 'Item that was sold most recently') terminal_clear = True elif choice == "9": terminal_view.print_result( sales.get_all_sales_ids_for_customer_ids_form_table(table), "The sales of each customer: ") terminal_clear = True elif choice == "10": terminal_view.print_result( sales.get_num_of_sales_per_customer_ids_from_table(table), "The number of sales of each customer: ") terminal_clear = True elif choice == "11": ids_amount = terminal_view.get_input( "Amount of IDs: ", "How many IDs would you like to sum up?") ids = [] for i in range(int(ids_amount)): ids.append("Sale ID: ") inputs = terminal_view.get_inputs(ids, "Please provide an ID") result = sales.get_the_sum_of_prices_from_table(table, inputs) terminal_view.print_result(result, "Sum of prices for given IDs: ") terminal_clear = True elif choice == "12": sale_id = terminal_view.get_input("Sale ID: ", "Please provide sale ID") result = sales.get_customer_id_by_sale_id_from_table( table, sale_id) terminal_view.print_result( result, "Customer ID for Sale ID you provided: ") terminal_clear = True else: terminal_view.print_error_message( "There is no such choice, please try again")
def run(): options = [ "Customer name of the last buyer", "Customer ID of the last buyer", "Customer who spent the most money", "Customer\'s ID who spent the most money", "Buyers, who effected more purchases", "Buyers\' ID, who effected more purchases" ] choice = None terminal_clear = False while choice != '0': if not terminal_clear: os.system("clear") choice = terminal_view.get_choice_submenu(options) terminal_clear = False if choice == '1': last_buyer = data_analyser.get_the_last_buyer_name() terminal_view.print_result(last_buyer, 'Customer name of the last buyer: ') terminal_clear = True elif choice == '2': last_buyer_id = data_analyser.get_the_last_buyer_id() terminal_view.print_result(last_buyer_id, 'Customer ID of the last buyer: ') terminal_clear = True elif choice == '3': customer_most_money = data_analyser.get_the_buyer_name_spent_most_and_the_money_spent( ) terminal_view.print_result(customer_most_money, "Customer who spent the most money: ") terminal_clear = True elif choice == '4': customer_id_most_money = data_analyser.get_the_buyer_id_spent_most_and_the_money_spent( ) terminal_view.print_result( customer_id_most_money, "Customer\'s ID who spent the most money: ") terminal_clear = True elif choice == '5': num = int( terminal_view.get_input( "Number of people: ", "Please enter a number of people, who you want to see, in the list of more purchases: " )) list_buyers_sales = data_analyser.get_the_most_frequent_buyers_names( num) terminal_view.print_result( list_buyers_sales, "Buyers, who effected more purchases: ") terminal_clear = True elif choice == '6': num = int( terminal_view.get_input( "Number of people: ", "Please enter a number of people, who you want to see, in the list of more purchases: " )) list_id_buyers_sales = data_analyser.get_the_most_frequent_buyers_ids( num) terminal_view.print_result( list_id_buyers_sales, "Buyers\' ID, who effected more purchases: ") terminal_clear = True else: terminal_view.print_error_message( "There is no such choice, please try again")