diff --git a/resources/interface.py b/resources/interface.py index 36181a312e27a3bcd81490793f67c8fa655fe205..efce8745f03aab14f66d10c62a2efbd73e1e596d 100644 --- a/resources/interface.py +++ b/resources/interface.py @@ -35,37 +35,37 @@ class UserInterface(): # Get user's input. user_input = input() - print('') + logger.info('') # Handle based on input. if user_input == '1': self.set_program_values_menu() - print('') + logger.info('') elif user_input == '2': self.display_program_values() - print('') + logger.info('') elif user_input == '3': self.solve_knapsack_problem() - print('') + logger.info('') elif user_input == '4': self._run_program_bool_ = False - print('Exiting Program') - print('') + logger.info('Exiting Program') + logger.info('') else: - print('Unrecognized user input. Please try again.') + logger.info('Unrecognized user input. Please try again.') def display_main_menu(self): """ Displays "Main Menu" to user. """ - print('') - print('MAIN MENU') - print('Select an option:') - print(' 1) Set program values.') - print(' 2) Display current program values.') - print(' 3) Solve Knapsack Problem with current program values.') - print(' 4) Exit program.') - print('') + logger.info('') + logger.info('MAIN MENU') + logger.info('Select an option:') + logger.info(' 1) Set program values.') + logger.info(' 2) Display current program values.') + logger.info(' 3) Solve Knapsack Problem with current program values.') + logger.info(' 4) Exit program.') + logger.info('') #region Program Values Menu @@ -80,44 +80,44 @@ class UserInterface(): # Get user's input. user_input = input() - print('') + logger.info('') # Handle based on input. if user_input == '1': self.set_max_weight() - print('') + logger.info('') elif user_input == '2': self.clear_max_weight() - print('') + logger.info('') elif user_input == '3': self.set_item_set_by_json() - print('') + logger.info('') elif user_input == '4': self.add_to_item_set() - print('') + logger.info('') elif user_input == '5': self.clear_item_set() - print('') + logger.info('') elif user_input == '6': stay_in_menu = False - print('') + logger.info('') else: - print('Unrecognized user input. Please try again.') + logger.info('Unrecognized user input. Please try again.') def display_set_program_values_menu(self): """ Displays "Set Program Values" menu to user. """ - print('') - print('PROGRAM VALUES MENU') - print('Select an option:') - print(' 1) Set "Max Weight" value.') - print(' 2) Clear "Max Weight" value.') - print(' 3) Set "Item Set" by JSON import.') - print(' 4) Add value to "Item Set" manually.') - print(' 5) Clear entire "Item Set".') - print(' 6) Back') - print('') + logger.info('') + logger.info('PROGRAM VALUES MENU') + logger.info('Select an option:') + logger.info(' 1) Set "Max Weight" value.') + logger.info(' 2) Clear "Max Weight" value.') + logger.info(' 3) Set "Item Set" by JSON import.') + logger.info(' 4) Add value to "Item Set" manually.') + logger.info(' 5) Clear entire "Item Set".') + logger.info(' 6) Back') + logger.info('') def set_max_weight(self): """ @@ -126,20 +126,20 @@ class UserInterface(): stay_in_function = True while stay_in_function: - print('Enter a positive integer for "Max Weight":') + logger.info('Enter a positive integer for "Max Weight":') # Get user's input. user_input = input() - print('') + logger.info('') # Attempt to set user's input as weight. try: user_input = int(user_input.strip()) self._knapsack_algorithm.set_max_weight(user_input) stay_in_function=False - print('"Max Weight" set to {0}'.format(user_input)) + logger.info('"Max Weight" set to {0}'.format(user_input)) except ValueError: - print('Input value was not a positive integer.') + logger.info('Input value was not a positive integer.') def clear_max_weight(self): """ @@ -151,11 +151,11 @@ class UserInterface(): """ Sets "Item Set" value by importing from JSON file. """ - print('Enter a JSON formatted file to import from:') + logger.info('Enter a JSON formatted file to import from:') # Get user's input. user_input = input() - print('') + logger.info('') # Attempt to set file contents as new item set. try: @@ -166,29 +166,29 @@ class UserInterface(): # Check that JSON data is formatted in way we expect. if self._knapsack_algorithm.set_item_set(json_data): # Successfully set JSON data as new item set. - print('Successfully set new Item Set from JSON data.') + logger.info('Successfully set new Item Set from JSON data.') self._knapsack_algorithm.display_item_set() else: # Validation failure. - print('Failed to validate file contents for Item Set.') + logger.info('Failed to validate file contents for Item Set.') except FileNotFoundError: - print('Failed to locate file "{0}".'.format(user_input)) + logger.info('Failed to locate file "{0}".'.format(user_input)) def add_to_item_set(self): """ Adds new "Item" to "Item Set" by manual input. """ - print('Enter Item "Benefit" amount (must be a positive integer):') + logger.info('Enter Item "Benefit" amount (must be a positive integer):') # Get user's input. benefit_input = input() - print('') + logger.info('') - print('Enter Item "Cost" amount (must be a positive integer):') + logger.info('Enter Item "Cost" amount (must be a positive integer):') # Get user's input. cost_input = input() - print('') + logger.info('') # Create new item. new_item = { @@ -199,11 +199,11 @@ class UserInterface(): # Attempt to add new item. if self._knapsack_algorithm.add_item_to_item_set(new_item): # Item successfully added. - print('Successfully added new item.') + logger.info('Successfully added new item.') self._knapsack_algorithm.display_item_set() else: # Failed to add item. - print('Failed to add new item. Benefit or cost were not positive integers.') + logger.info('Failed to add new item. Benefit or cost were not positive integers.') def clear_item_set(self): """ @@ -227,5 +227,5 @@ class UserInterface(): self._knapsack_algorithm.display_max_weight() self._knapsack_algorithm.display_item_set() results = self._knapsack_algorithm.calculate_fractional_knapsack() - print('Optimal backpack contents, by weight of each item to take:') - print(results) + logger.info('Optimal backpack contents, by weight of each item to take:') + logger.info(results) diff --git a/resources/knapsack.py b/resources/knapsack.py index cfb4c5fc10d1424666a8e5a44aed9c91e6758e35..e2669e0fa6a75da9d297b0886b648816863136de 100644 --- a/resources/knapsack.py +++ b/resources/knapsack.py @@ -159,13 +159,13 @@ class FractionalKnapsackAlgorithm(): """ Prints current item set with logging. """ - print('Current Item Set: {0}'.format(self._item_set_)) + logger.info('Current Item Set: {0}'.format(self._item_set_)) def display_max_weight(self): """ Prints current max weight with logging. """ - print('Current Max Weight: {0}'.format(self._max_weight_)) + logger.info('Current Max Weight: {0}'.format(self._max_weight_)) def calculate_fractional_knapsack(self): """ diff --git a/resources/logging.py b/resources/logging.py index 58a300e7202d92d53b2acd36ca5b39d10b4c388c..a1f62bf9ac4fe82af1f3d64ff9b694aca1c9812f 100644 --- a/resources/logging.py +++ b/resources/logging.py @@ -62,7 +62,7 @@ LOGGING = { 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', - 'formatter': 'simple', + 'formatter': 'minimal', }, # Debug Level - To file. 'file_debug': {