def result_stock_data_container_list_changed(self): """ Update the columns and data of the view, of stock data container list changed. Additionally, it adds the not already available columns to the MvcModel and fill not available columns with dummy. :return: - """ tree = w.Scrolledtreeview1 tree.delete(*tree.get_children()) stock_data_container_list = self.model.result_stock_data_container_list.get( ) # sort the list by rank newlist = sorted(stock_data_container_list, key=lambda x: x.get_rank(), reverse=True) for result_container in newlist: try: is_updated = self.model.update_column_list( result_container.get_names_and_values().keys()) if is_updated: init_result_table(self.view.Scrolledtreeview1, self.model.get_column_list()) GuiUtils.insert_into_treeview( self.view.Scrolledtreeview1, self.model.get_column_list(), result_container.get_names_and_values(), "Stock") # append all COLUMNS to file --> new layout leads to new line with header FileUtils.append_text_list_to_file( self.model.get_column_list(), GlobalVariables.get_data_files_path() + "ScreeningResults.csv", True, ",") # append VALUES to file values = result_container.get_names_and_values().values() text = ','.join(str(e) for e in values) FileUtils.append_textline_to_file( text, GlobalVariables.get_data_files_path() + "ScreeningResults.csv", True) except Exception as e: logger.error("Exception: " + str(e) + "\n" + str(traceback.format_exc())) continue # add a sort functionality for each column, when click on header GuiUtils.advanced_sorting(self.view.Scrolledtreeview1, self.model.get_column_list(), True) # add a color for the entries in tree view for color in GlobalVariables.get_row_colors().keys(): tree.tag_configure( GlobalVariables.get_row_colors()[color], background=GlobalVariables.get_row_colors()[color])
def print_and_save_mean(self, file_name=""): """ Print the mean text, and save all diff values and mean value to the given file, if file name not empty. :param file_name: file_name to save the values, can be empty --> do not save to file :return: mean value as float """ from Utils.FileUtils import FileUtils mean_value = np.mean(self.get_diff_list_seconds()) mean_text = "Mean: " + str(mean_value).replace('.', ',') print(mean_text) if len(file_name) > 0: for diff in self.get_diff_list_seconds(): FileUtils.append_text_list_to_file( [str(diff).replace('.', ',')], file_name, False) FileUtils.append_text_list_to_file([mean_text], file_name, False) return mean_value
def test_append_text_list_to_file__write_and_read_again__2x_only_new_data__1x_all_data( self): filename = GlobalVariables.get_data_files_path( ) + "TestData\\ScreeningResults.csv" test_1 = "Test 1" text_list = [test_1, "Test2", "Test3"] self.assertFalse( FileUtils.append_text_list_to_file(text_list, filename, True)) text_list_2 = [str(datetime.now()) + ", Test Eintrag"] self.assertTrue( FileUtils.append_text_list_to_file(text_list_2, filename, True)) self.assertTrue( FileUtils.append_text_list_to_file([test_1], filename, False)) text_to_find = text_list text_to_find.extend(text_list_2) with open(filename, 'r') as myfile: file_content = myfile.read() for text in text_to_find: self.assertTrue(str(text) in file_content)