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. Which year has the highest profit?", "5. What is the average (per item) profit in a given year?" ] program_works = True while program_works: table = accounting.get_table() title_list = ["ID", "MONTH", "DAY", "YEAR", "TYPE", "AMOUNT"] terminal_view.print_table(table, title_list) answer = terminal_view.get_choice(list_options) if answer == "1": record = terminal_view.get_inputs([ "ID: ", "Month of the transaction: ", "Day of the transaction: ", "Year of the transaction: ", "Type - income/outflow (in.out): ", "Amount of transaction in USD: " ], "Please provide information: \n") common.add(table, record) accounting.save_table(table) elif answer == "2": id_ = terminal_view.get_input("Please enter id number: ") common.remove(table, id_) accounting.save_table(table) elif answer == "3": id_ = terminal_view.get_input("Please enter id number: ") record = terminal_view.get_inputs( ["ID: ", "Month: ", "Day: ", "Year: ", "Type: ", "Ammount: "], "Please provide new information") common.update(table, id_, record) accounting.save_table(table) elif answer == "4": accounting.which_year_max(table) elif answer == "5": accounting.avg_amount(table, year) 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(): """ 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_list = [ "* ID", "* Month of the transaction", "* Day of the transaction", "* Year of the transaction", "* Type", "* Amount in USD" ] options = [ "Add new record to table", "Remove a record with a given id from the table", "Update specified record in the table", "Year of the highest profit", "Average profit in a given year", "Print table" ] os.system('clear') file = "model/accounting/items.csv" 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) if choice == "1": common.all_add(title_list, file) elif choice == "2": common.all_remove(title_list, file) elif choice == "3": common.all_updates(title_list, file) elif choice == "4": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = file table = common.get_table_from_file(file_name) year_of_highest_profit = accounting.which_year_max(table) os.system("clear") print("Year of the highest profit:", year_of_highest_profit) common.waiting() os.system("clear") elif choice == "5": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = file table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) year = int(common.get_input("Enter year: ")) print(accounting.avg_amount(table, year)) common.waiting() os.system("clear") elif choice == "6": common.all_print_table(title_list, file) 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 """ # your code menu_accounting = [ "Print accounting list", "Add to accounting list", "Remove form accounting list", "Update record in accounting list", "Show year with highest profit", "Show average profit per item in a given year" ] title = ["Id", "Month", "Day", "Year", "Type", "Amount"] title_del = ["Input ID: "] choice = None while choice != "0": choice = terminal_view.get_choice(menu_accounting) if choice == "1": terminal_view.print_table(accounting.get_data(), title) if choice == "2": accounting.new_record( common.get_user_inp_record( terminal_view.get_inputs(title[1:], "")), "model/accounting/items.csv") if choice == "3": accounting.delete_record( accounting.get_data(), common.get_user_inp_record( terminal_view.get_inputs(title_del, "")), "model/accounting/items.csv") if choice == "4": accounting.update_record( accounting.get_data(), common.get_user_inp_record( terminal_view.get_inputs(title_del, "")), terminal_view.get_inputs(title[1:], ""), "model/accounting/items.csv") if choice == "5": terminal_view.print_result( accounting.which_year_max(accounting.get_data()), "Year with max profit") if choice == "6": year = terminal_view.get_inputs(["Year:"], "") terminal_view.print_result( accounting.avg_amount(accounting.get_data(), year[0]), "Averange profit per item")
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 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', 'Month', 'Day', 'Year', 'Type', 'Amount'] choice = None filename = 'model/accounting/items.csv' columns_headers = ['Month', 'Day', 'Year', 'Type', 'Amount'] ask_information = "Please provide your personal information" common.print_art(0) while choice != "0": choice = terminal_view.get_submenu_choice(['Add', 'Remove', 'Update', 'Which year has the highest profit?',\ 'What is the average (per item) profit in a given year?']) 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) accounting_result = accounting.which_year_max(table) terminal_view.print_result("The year with the highest profit is: ", accounting_result) elif choice == "5": common.clear_terminal() terminal_view.print_table(table, table_headers) year = terminal_view.get_inputs(['Year'], 'Which year?') result = accounting.avg_amount(table, int(year[0])) terminal_view.print_result( 'The average profit (per item) in a given year is/are: ', result) 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. Returns: None """ list_options = [ 'Accounting', 'Show all data', 'Add', 'Remove', 'Update', 'Year with the highest profit', 'Average amount', 'Exit to main menu' ] list_labels = [['Month', 'month'], ['Day', 'day'], ['Year', 'year'], ['Type', 'type'], ['Amount', int]] data_file = "model/accounting/items.csv" crud_module = accounting 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(accounting.which_year_max(table), 'Year with the highest income') elif user_choice == '6': year = terminal_view.get_inputs(['must'] + [ ['Year to get average', 'year'], ], '') terminal_view.print_result(accounting.avg_amount(table, year[0]), 'Average') elif user_choice == '0': break else: terminal_view.print_error_message("There is no such choice.")
def test_avg_amount(self): table = data_manager.get_table_from_file(self.data_file) result = accounting.avg_amount(table, 2016) self.assertEqual(result, 48.125)
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 """ MAX_YEAR = 2020 list_of_accounting = accounting.get_data_to_list() # your code options = [ "Add new record", "Remove a record", "Update record", "Which year has the highest profit?", "What is the average per item", "Print table" ] title_list = ["ID", "Month", "Day", "Year", "Type", "Amount"] choice = None while choice != "0": choice = terminal_view.get_choice(options, "Back to main menu") if choice == "1": new_record = terminal_view.get_inputs( ["Month: ", "Day: ", "Year: ", "Type: ", "Amount: "], "Please enter value: ") new_record.insert(0, accounting.get_random_id(list_of_accounting)) list_of_accounting = accounting.add(list_of_accounting, new_record) elif choice == "2": id_of_record_to_remove = ask_untill_correct( ["Please insert ID"], len(list_of_accounting)) list_of_accounting = accounting.remove( list_of_accounting, common.check_id_by_number(list_of_accounting, int(id_of_record_to_remove))) elif choice == "3": id_of_record_to_update = ask_untill_correct( ["Please insert ID"], len(list_of_accounting)) updated_record = terminal_view.get_inputs( ["Month: ", "Day: ", "Year: ", "Type: ", "Amount :"], "Please enter value: ") list_of_accounting = accounting.update( list_of_accounting, common.check_id_by_number(list_of_accounting, int(id_of_record_to_update)), updated_record) elif choice == "4": result = accounting.which_year_max(list_of_accounting) terminal_view.print_result(str(result), "Year of the highest profile ") elif choice == "5": year_of_check = ask_untill_correct(["Year of publishing: "], MAX_YEAR) result = accounting.avg_amount(list_of_accounting, year_of_check) terminal_view.print_result(str(result), "Avernage items by year") elif choice == "6": terminal_view.print_table(list_of_accounting, title_list) elif choice == "0": accounting.export_list_to_file(list_of_accounting) else: terminal_view.print_error_message( "There is no such choice.") # your code
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 = 'Accounting menu' options = [ "Add new record to table", "Remove a record with a given id from the table.", "Updates specified record in the table.", "Which year has the highest profit? (profit = in - out)", "What is the average (per item) profit in a given year? [(profit)/(items count)]" ] exit_message = "Back to main menu" title_list = ["ID", "MONTH", "DAY", "YEAR", 'TYPE', 'DURABILITY'] table = accounting.data_manager.get_table_from_file( 'model/accounting/items.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 = accounting.add(table, record) accounting.data_manager.write_table_to_file( 'model/accounting/items.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 = accounting.remove(table, id_) accounting.data_manager.write_table_to_file( 'model/accounting/items.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 = accounting.update(table, id_, record) accounting.data_manager.write_table_to_file( 'model/accounting/items.csv', updated_table) common.exit_prompt() common.clear() elif choice == "4": label = "Which year has the highest profit?" result = str(accounting.which_year_max(table)) terminal_view.print_result(result, label) common.exit_prompt() common.clear() elif choice == "5": year = terminal_view.get_inputs(['year : '], 'Please give a year :') year = year[0] result = str(accounting.avg_amount(table, year)) label = "the average (per item) profit in {} ".format(year) 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 """ table = accounting.get_accounting_table_from_file() title_list = [ "ID", "Month".upper(), "Day".upper(), "Year".upper(), "Type".upper(), "Amount".upper() ] options = [ "View records", "Add record", "Remove record", "Update record", "Which year has the highest profit?", "What is the average (per item) profit in a given year?" ] choice = None while choice != "0": choice = terminal_view.get_choice_inner_menu(options, "Accounting manager") if choice == "1": terminal_view.print_table(table, title_list) elif choice == "2": item_month = item_day = 0 trans_type = trans_ammount = item_year = "" while item_day < 1 or item_day > 31 or not str(item_day).isdigit(): item_days = terminal_view.get_inputs( ["Day of transaction"], "Please provide new item data") try: item_day = int(item_days[0]) except: pass if item_day < 1 or item_day > 31 or not str( item_day).isdigit(): terminal_view.print_error_message("Incorrect day.") while item_month < 1 or item_month > 12 or not str( item_month).isdigit(): item_months = terminal_view.get_inputs( ["Month of transaction"], "") try: item_month = int(item_months[0]) except: pass if item_month < 1 or item_month > 12 or not str( item_month).isdigit(): terminal_view.print_error_message("Incorrect month.") while not item_year.isdigit(): item_years = terminal_view.get_inputs(["Year of transaction:"], "") item_year = item_years[0] if not item_year.isdigit(): terminal_view.print_error_message("Incorrect year.") while not trans_type == "out" and not trans_type == "in": trans_types = terminal_view.get_inputs( ["Type of transaction (out / in):"], "") trans_type = trans_types[0] if not trans_type == "out" and not trans_type == "in": terminal_view.print_error_message("Incorrect type.") while not trans_ammount.isdigit(): trans_ammounts = terminal_view.get_inputs( ["Ammount of transaction:"], "") trans_ammount = trans_ammounts[0] if not trans_ammount.isdigit(): terminal_view.print_error_message("Incorrect ammount.") table = accounting.add( table, [item_month, item_day, item_year, trans_type, trans_ammount]) elif choice == "3": id_to_delete_table = terminal_view.get_inputs(["ID"], "Item to delete") id_to_delete = id_to_delete_table[0] table = accounting.remove(table, id_to_delete) elif choice == "4": records = terminal_view.get_inputs(title_list, "Edit item") record_id = records[0] table = accounting.update(table, record_id, records) elif choice == "5": max_year = accounting.which_year_max(table) terminal_view.print_result(max_year, "Year of the highest profit") elif choice == "6": year_input = terminal_view.get_inputs( ["Year"], "Average (per item) profit in a given year") year = year_input[0] avg_amount = accounting.avg_amount(table, year) terminal_view.print_result(avg_amount, "Avarage profit in {}".format(year)) 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 = "Accounting options" options = ["Add item", "Remove item", "Update item", "Which year has a maximum profit", "What is an avarange profit in a given year"] exit_message = "Back to main menu" title_list = [ ['Month'], ['Day'], ['Year'], ['Type'], ['Amount']] data_file = "model/accounting/items.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 accounting.add(table, record) data_manager.write_table_to_file(data_file, table) terminal_view.print_table(table, title_list) elif choice == "2": user_input = terminal_view.get_inputs(["Enter ID: "], "") accounting.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 accounting.update(table, user_input[0], record) terminal_view.print_table(table, title_list) elif choice == "4": terminal_view.print_result(accounting.which_year_max( table), "Year with the highest income: ") elif choice == "5": year = terminal_view.get_inputs(['Year to get average: '], "") terminal_view.print_result( accounting.avg_amount(table, year[0]), "Average: ") else: terminal_view.print_error_message("You have chosen back to menu.")