def plot_data_file(self): """ check if data can be plotted """ if self.pb_plot_data.text() == "Mostrar enredo": if self.tw_data_files.selectedIndexes() or self.tw_data_files.rowCount() == 1: if self.tw_data_files.rowCount() == 1: row_idx = 0 else: row_idx = self.tw_data_files.selectedIndexes()[0].row() filename = self.tw_data_files.item(row_idx, PLOT_DATA_FILEPATH_IDX).text() columns_to_plot = self.tw_data_files.item(row_idx, PLOT_DATA_COLUMNS_IDX).text() plot_title = self.tw_data_files.item(row_idx, PLOT_DATA_PLOTTITLE_IDX).text() # load converters in dictionary if self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text(): column_converter = eval(self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text()) ''' for idx_conv in self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text().split(","): idx, conv = idx_conv.split(":") column_converter[int(idx)] = conv ''' else: column_converter = {} variable_name = self.tw_data_files.item(row_idx, PLOT_DATA_VARIABLENAME_IDX).text() time_interval = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEINTERVAL_IDX).text()) time_offset = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEOFFSET_IDX).text()) substract_first_value = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_SUBSTRACT1STVALUE_IDX).currentText() plot_color = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_PLOTCOLOR_IDX).currentText() data_file_path = project_functions.media_full_path(filename, self.project_path) if not data_file_path: QMessageBox.critical(self, programName, ("Arquivo de dados não encontrado:\n{}\n" "Se o caminho do arquivo não estiver armazenado, o arquivo de dados " "deve estar no mesmo diretório que seu projeto").format(filename)) return self.test = plot_data_module.Plot_data(data_file_path, time_interval, # time interval time_offset, # time offset plot_color, # plot style plot_title, # plot title variable_name, columns_to_plot, substract_first_value, self.converters, column_converter, log_level=logging.getLogger().getEffectiveLevel() ) if self.test.error_msg: QMessageBox.critical(self, programName, "Impossível traçar dados:\n{}".format(self.test.error_msg)) del self.test return ''' print(test.plotter.data) print(Path(self.tmp_dir).joinpath(file_content_md5(filename))) numpy.save(Path(self.tmp_dir).joinpath(file_content_md5(filename)), test.plotter.data) ''' self.test.setWindowFlags(Qt.WindowStaysOnTopHint) self.test.show() self.test.update_plot(0) self.pb_plot_data.setText("Enredo fechado") else: QMessageBox.warning(self, programName, "Selecione um arquivo de dados") else: # close plot self.test.close_plot() self.pb_plot_data.setText("Mostrar enredo")
def check_data_file(self): """ check if data can be plotted """ if self.pb_plot_data.text() == "Show plot": if self.tw_data_files.selectedIndexes() or self.tw_data_files.rowCount() == 1: if self.tw_data_files.rowCount() == 1: row_idx = 0 else: row_idx = self.tw_data_files.selectedIndexes()[0].row() filename = self.tw_data_files.item(row_idx, PLOT_DATA_FILEPATH_IDX).text() columns_to_plot = self.tw_data_files.item(row_idx, PLOT_DATA_COLUMNS_IDX).text() plot_title = self.tw_data_files.item(row_idx, PLOT_DATA_PLOTTITLE_IDX).text() # load converters in dictionary if self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text(): column_converter = eval(self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text()) ''' for idx_conv in self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text().split(","): idx, conv = idx_conv.split(":") column_converter[int(idx)] = conv ''' else: column_converter = {} variable_name = self.tw_data_files.item(row_idx, PLOT_DATA_VARIABLENAME_IDX).text() time_interval = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEINTERVAL_IDX).text()) time_offset = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEOFFSET_IDX).text()) substract_first_value = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_SUBSTRACT1STVALUE_IDX).currentText() plot_color = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_PLOTCOLOR_IDX).currentText() self.test = plot_data_module.Plot_data(filename, time_interval, # time interval time_offset, # time offset plot_color, # plot style plot_title, # plot title variable_name, columns_to_plot, substract_first_value, self.converters, column_converter, log_level=logging.getLogger().getEffectiveLevel() ) if self.test.error_msg: QMessageBox.critical(self, programName, "Impossibile to plot data:\n{}".format(self.test.error_msg)) del self.test return ''' print(test.plotter.data) print(Path(self.tmp_dir).joinpath(file_content_md5(filename))) numpy.save(Path(self.tmp_dir).joinpath(file_content_md5(filename)), test.plotter.data) ''' self.test.setWindowFlags(Qt.WindowStaysOnTopHint) self.test.show() self.test.update_plot(0) self.pb_plot_data.setText("Close plot") else: QMessageBox.warning(self, programName, "Select a data file") else: # close plot self.test.close_plot() self.pb_plot_data.setText("Show plot")
def plot_data_file(self): """ show plot check if data can be plotted """ if self.pb_plot_data.text() == "Show plot": if self.tw_data_files.selectedIndexes( ) or self.tw_data_files.rowCount() == 1: if self.tw_data_files.rowCount() == 1: row_idx = 0 else: row_idx = self.tw_data_files.selectedIndexes()[0].row() filename = self.tw_data_files.item( row_idx, PLOT_DATA_FILEPATH_IDX).text() columns_to_plot = self.tw_data_files.item( row_idx, PLOT_DATA_COLUMNS_IDX).text() plot_title = self.tw_data_files.item( row_idx, PLOT_DATA_PLOTTITLE_IDX).text() # load converters in dictionary if self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text(): column_converter = eval( self.tw_data_files.item( row_idx, PLOT_DATA_CONVERTERS_IDX).text()) else: column_converter = {} variable_name = self.tw_data_files.item( row_idx, PLOT_DATA_VARIABLENAME_IDX).text() time_interval = int( self.tw_data_files.item(row_idx, PLOT_DATA_TIMEINTERVAL_IDX).text()) time_offset = int( self.tw_data_files.item(row_idx, PLOT_DATA_TIMEOFFSET_IDX).text()) substract_first_value = self.tw_data_files.cellWidget( row_idx, PLOT_DATA_SUBSTRACT1STVALUE_IDX).currentText() plot_color = self.tw_data_files.cellWidget( row_idx, PLOT_DATA_PLOTCOLOR_IDX).currentText() data_file_path = project_functions.media_full_path( filename, self.project_path) if not data_file_path: QMessageBox.critical( self, programName, (f"Data file not found:\n{filename}\n" "If the file path is not stored the data file " "must be in the same directory than your project")) return self.test = plot_data_module.Plot_data( data_file_path, time_interval, # time interval time_offset, # time offset plot_color, # plot style plot_title, # plot title variable_name, columns_to_plot, substract_first_value, self.converters, column_converter, log_level=logging.getLogger().getEffectiveLevel()) if self.test.error_msg: QMessageBox.critical( self, programName, f"Impossible to plot data:\n{self.test.error_msg}") del self.test return self.test.setWindowFlags(Qt.WindowStaysOnTopHint) self.test.show() self.test.update_plot(0) self.pb_plot_data.setText("Close plot") else: QMessageBox.warning(self, programName, "Select a data file") else: # close plot self.test.close_plot() self.pb_plot_data.setText("Show plot")