def main(filename, output_format='xlsx', output_dir='', sheet_name_usr=''): ''' Main function to run DEA models from terminal. Args: filename (str): path to file with parameters. output_format (str, optional): file format of solution file. This value is used only if OUTPUT_FILE in parameters is empty or set to auto. Defaults to xlsx. output_dir (str, optional): directory where solution must be written. If it is not given, solution will be written to current folder. This value is used only if OUTPUT_FILE in parameters is empty or set to auto. sheet_name_usr (str, optional): name of the sheet in xls- or xlsx-file with input data from which data will be read. If input data file is in csv format, this value is ignored. ''' print('Params file', filename, 'output_format', output_format, 'output_dir', output_dir, 'sheet_name_usr', sheet_name_usr) logger = get_logger() logger.info('Params file "%s", output format "%s", output directory "%s", sheet name "%s".', filename, output_format, output_dir, sheet_name_usr) params = parse_parameters_from_file(filename) params.print_all_parameters() run_method = RunMethodTerminal(params, sheet_name_usr, output_format, output_dir) run_method.run(params) clean_up_pickled_files() logger.info('pyDEA exited.')
def main(): ''' Runs main application GUI. ''' logger = get_logger() logger.info('pyDEA started as a GUI application.') root = Tk() root.report_callback_exception = show_error # load logo if "nt" == os.name: iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.ico') root.wm_iconbitmap(bitmap=iconfile) else: iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.gif') img = PhotoImage(file=iconfile) root.tk.call('wm', 'iconphoto', root._w, img) # change background color of all widgets s = Style() s.configure('.', background=bg_color) # run the application app = MainFrame(root) root.protocol("WM_DELETE_WINDOW", (lambda: ask_quit(app))) center_window(root, root.winfo_screenwidth() - root.winfo_screenwidth()*0.15, root.winfo_screenheight() - root.winfo_screenheight()*0.15) root.mainloop() logger.info('pyDEA exited.')
def main(): ''' Runs main application GUI. ''' logger = get_logger() logger.info('pyDEA started as a GUI application.') root = Tk() root.report_callback_exception = show_error # load logo if "nt" == os.name: iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.ico') root.wm_iconbitmap(bitmap=iconfile) else: iconfile = pkg_resources.resource_filename(PACKAGE, 'pyDEAlogo.gif') img = PhotoImage(file=iconfile) root.tk.call('wm', 'iconphoto', root._w, img) # change background color of all widgets s = Style() s.configure('.', background=bg_color) # run the application app = MainFrame(root) root.protocol("WM_DELETE_WINDOW", (lambda: ask_quit(app))) center_window(root, root.winfo_screenwidth() - root.winfo_screenwidth() * 0.15, root.winfo_screenheight() - root.winfo_screenheight() * 0.15) root.mainloop() logger.info('pyDEA exited.')
logger = get_logger() logger.info('Params file "%s", output format "%s", output directory "%s", sheet name "%s".', filename, output_format, output_dir, sheet_name_usr) params = parse_parameters_from_file(filename) params.print_all_parameters() run_method = RunMethodTerminal(params, sheet_name_usr, output_format, output_dir) run_method.run(params) clean_up_pickled_files() logger.info('pyDEA exited.') if __name__ == '__main__': args = sys.argv[1:] logger = get_logger() logger.info('pyDEA started as a console application.') print('args = {0}'.format(args)) if len(args) < 1 or len(args) > 4: logger.error('Invalid number of input arguments. At least one ' 'argument must be given, no more than 4 arguments, but %d were given.', len(args)) raise ValueError('Invalid number of input arguments. At least one ' 'argument must be given, no more than 4 arguments' ' are expected. Input arguments are:\n (1) path to' ' file with parameters (compulsory)\n' '(2) output file format, possible values: xls, xlsx' ' and csv, default value is xlsx (optional), this' ' value is used only if auto or empty string was set' ' for OUTPUT_FILE in parameters file \n' '(3) output directory (optional, if not specified,'
def show_error(self, message): ''' See base class. ''' logger = get_logger() logger.error(message) showerror('Error', message)
def run(self, params): ''' Executes solution routine - create data instance, solve LPs, post-process solutions. Args: params (Parameters): parameters of a given problem instance ''' logger = get_logger() logger.info('Started solving given DEA model(s).') logger.info('Parameters: %s', params.get_all_params_as_string()) categories = self.get_categories() coefficients, has_same_dmus = self.get_coefficients() if has_same_dmus: self.show_error('Some DMUs have the same name') else: if validate_data(categories, coefficients): try: self.validate_weights_if_needed() # MUST be called # before model_builder, because it might # update parameters model_input = construct_input_data_instance( categories, coefficients) models, all_params = model_builder.build_models( params, model_input) self.init_before_run(len(models), coefficients) solutions = [] state = True param_strs = [] all_ranks = [] run_date = datetime.datetime.today() start_time = datetime.datetime.now() for count, model_obj in enumerate(models): model = self.decorate_model(model_obj) call_peel_the_onion = params.get_parameter_value( 'PEEL_THE_ONION') if call_peel_the_onion: model_solution, ranks, state = ( peel_the_onion_method(model)) all_ranks.append(ranks) else: model_solution = model.run() str_to_write = create_params_str(all_params[count]) param_strs.append(str_to_write) solutions.append(model_solution) try: solutions.append(model.second_solution) param_strs.append(str_to_write + ' second phase') except AttributeError: pass end_time = datetime.datetime.now() diff = end_time - start_time total_seconds = diff.total_seconds() if params.get_parameter_value('RETURN_TO_SCALE') == 'both': derive_returns_to_scale_classification( param_strs, solutions) self.post_process_solutions(solutions, params, param_strs, all_ranks, run_date, total_seconds) if state is False: self.show_error('For one of the runs of the ' 'peel-the-onion problem is infeasible' ' or unbounded') self.show_success() except Exception as excinfo: self.show_error(excinfo) else: logger.info('Given DEA model(s) successfully solved.') else: self.show_error('Some of the input data is not correct')
def show_error(self, message): ''' See base class. ''' logger = get_logger() logger.error(message) print(message)
def show_error(*args): logger = get_logger() err = traceback.format_exception(*args) logger.error(err) # show only short error message to the user without traceback showerror('Error', args[1])
def run(self, params): ''' Executes solution routine - create data instance, solve LPs, post-process solutions. Args: params (Parameters): parameters of a given problem instance ''' logger = get_logger() logger.info('Started solving given DEA model(s).') logger.info('Parameters: %s', params.get_all_params_as_string()) categories = self.get_categories() coefficients, has_same_dmus = self.get_coefficients() if has_same_dmus: self.show_error('Some DMUs have the same name') else: if validate_data(categories, coefficients): try: self.validate_weights_if_needed() # MUST be called # before model_builder, because it might # update parameters model_input = construct_input_data_instance(categories, coefficients) models, all_params = model_builder.build_models(params, model_input) self.init_before_run(len(models), coefficients) solutions = [] state = True param_strs = [] all_ranks = [] run_date = datetime.datetime.today() start_time = datetime.datetime.now() for count, model_obj in enumerate(models): model = self.decorate_model(model_obj) call_peel_the_onion = params.get_parameter_value( 'PEEL_THE_ONION') if call_peel_the_onion: model_solution, ranks, state = ( peel_the_onion_method(model)) all_ranks.append(ranks) else: model_solution = model.run() str_to_write = create_params_str(all_params[count]) param_strs.append(str_to_write) solutions.append(model_solution) try: solutions.append(model.second_solution) param_strs.append(str_to_write + ' second phase') except AttributeError: pass end_time = datetime.datetime.now() diff = end_time - start_time total_seconds = diff.total_seconds() if params.get_parameter_value('RETURN_TO_SCALE') == 'both': derive_returns_to_scale_classification(param_strs, solutions) self.post_process_solutions(solutions, params, param_strs, all_ranks, run_date, total_seconds) if state is False: self.show_error('For one of the runs of the ' 'peel-the-onion problem is infeasible' ' or unbounded') self.show_success() except Exception as excinfo: self.show_error(excinfo) else: logger.info('Given DEA model(s) successfully solved.') else: self.show_error('Some of the input data is not correct')