def view_data_file_head(self): """ view first parts of data file """ if self.tw_data_files.selectedIndexes() or self.tw_data_files.rowCount( ) == 1: if self.tw_data_files.rowCount() == 1: data_file_path = project_functions.media_full_path( self.tw_data_files.item(0, 0).text(), self.project_path) else: data_file_path = project_functions.media_full_path( self.tw_data_files.item( self.tw_data_files.selectedIndexes()[0].row(), 0).text(), self.project_path) file_parameters = utilities.check_txt_file(data_file_path) if "error" in file_parameters: QMessageBox.critical( self, programName, f"Error on file {data_file_path}: {file_parameters['error']}" ) return header = utilities.return_file_header(data_file_path) if header: w = dialog.View_data_head() w.setWindowTitle(f"Data file: {Path(data_file_path).name}") w.setWindowFlags(Qt.WindowStaysOnTopHint) w.label.setVisible(False) w.le.setVisible(False) w.tw.setColumnCount(file_parameters["fields number"]) w.tw.setRowCount(len(header)) for row in range(len(header)): for col, v in enumerate(header[row].split( file_parameters["separator"])): w.tw.setItem(row, col, QTableWidgetItem(v)) w.exec_() else: QMessageBox.critical(self, programName, f"Error on file {data_file_path}") else: QMessageBox.warning(self, programName, "Select a data file")
def generate_spectrogram(self): """ generate spectrogram of all media files loaded in player #1 """ if self.cbVisualizeSpectrogram.isChecked(): if dialog.MessageDialog( programName, ("You choose to visualize the spectrogram for the media in player #1.<br>" "Choose YES to generate the spectrogram.\n\n" "Spectrogram generation can take some time for long media, be patient" ), [YES, NO]) == YES: if not self.ffmpeg_cache_dir: tmp_dir = tempfile.gettempdir() else: tmp_dir = self.ffmpeg_cache_dir w = dialog.Info_widget() w.resize(350, 100) w.setWindowFlags(Qt.WindowStaysOnTopHint) w.setWindowTitle("BORIS") w.label.setText("Generating spectrogram...") #for media in self.pj[OBSERVATIONS][self.observationId][FILE][PLAYER1]: for row in range(self.twVideo1.rowCount()): media_file_path = project_functions.media_full_path( self.twVideo1.item(row, 0).text(), self.project_path) if os.path.isfile(media_file_path): process = plot_spectrogram.create_spectrogram_multiprocessing( mediaFile=media_file_path, tmp_dir=tmp_dir, chunk_size=self.chunk_length, ffmpeg_bin=self.ffmpeg_bin, spectrogramHeight=self.spectrogramHeight, spectrogram_color_map=self.spectrogram_color_map) if process: w.show() while True: QApplication.processEvents() if not process.is_alive(): w.hide() break else: QMessageBox.warning( self, programName, "<b>{}</b> file not found".format(media_file_path)) else: self.cbVisualizeSpectrogram.setChecked(False)
def generate_spectrogram(self): """ generate spectrogram of all media files loaded in player #1 """ if self.cbVisualizeSpectrogram.isChecked(): if dialog.MessageDialog(programName, ("Você escolhe visualizar o espectrograma para a mídia no player #1.<br>" "Escolha SIM para gerar o espectrograma.\n\n" "Geração de espectrograma pode levar algum tempo para mídia longa, seja paciente"), [YES, NO]) == YES: if not self.ffmpeg_cache_dir: tmp_dir = tempfile.gettempdir() else: tmp_dir = self.ffmpeg_cache_dir w = dialog.Info_widget() w.resize(350, 100) w.setWindowFlags(Qt.WindowStaysOnTopHint) w.setWindowTitle("eMOC") w.label.setText("Gerando espectrograma...") #for media in self.pj[OBSERVATIONS][self.observationId][FILE][PLAYER1]: for row in range(self.twVideo1.rowCount()): media_file_path = project_functions.media_full_path(self.twVideo1.item(row, 0).text(), self.project_path) if os.path.isfile(media_file_path): process = plot_spectrogram.create_spectrogram_multiprocessing(mediaFile=media_file_path, tmp_dir=tmp_dir, chunk_size=self.chunk_length, ffmpeg_bin=self.ffmpeg_bin, spectrogramHeight=self.spectrogramHeight, spectrogram_color_map=self.spectrogram_color_map) if process: w.show() while True: QApplication.processEvents() if not process.is_alive(): w.hide() break else: QMessageBox.warning(self, programName , "<b>{}</b> Arquivo não encontrado".format(media_file_path)) else: self.cbVisualizeSpectrogram.setChecked(False)
def extract_wav(self): """ extract wav of all media files loaded in player #1 """ if self.cbVisualizeSpectrogram.isChecked() or self.cb_visualize_waveform.isChecked(): flag_wav_produced = False # check if player 1 is selected flag_player1 = False for row in range(self.twVideo1.rowCount()): if self.twVideo1.cellWidget(row, 0).currentText() == "1": flag_player1 = True if not flag_player1: QMessageBox.critical(self, programName , "The player #1 is not selected") self.cbVisualizeSpectrogram.setChecked(False) self.cb_visualize_waveform.setChecked(False) return if dialog.MessageDialog(programName, ("You choose to visualize the spectrogram or waveform for the media in player #1.<br>" "The WAV will be extracted from the media files, be patient"), [YES, NO]) == YES: w = dialog.Info_widget() w.resize(350, 100) w.setWindowFlags(Qt.WindowStaysOnTopHint) w.setWindowTitle("BORIS") w.label.setText("Extracting WAV from media files...") for row in range(self.twVideo1.rowCount()): # check if player 1 if self.twVideo1.cellWidget(row, 0).currentText() != "1": continue media_file_path = project_functions.media_full_path(self.twVideo1.item(row, MEDIA_FILE_PATH_IDX).text(), self.project_path) if self.twVideo1.item(row, HAS_AUDIO_IDX).text() == "False": QMessageBox.critical(self, programName , f"The media file {media_file_path} do not seem to have audio") flag_wav_produced = False break if os.path.isfile(media_file_path): w.show() QApplication.processEvents() if utilities.extract_wav(self.ffmpeg_bin, media_file_path, self.tmp_dir) == "": QMessageBox.critical(self, programName , f"Error during extracting WAV of the media file {media_file_path}") flag_wav_produced = False break w.hide() flag_wav_produced = True else: QMessageBox.warning(self, programName , f"<b>{media_file_path}</b> file not found") if not flag_wav_produced: self.cbVisualizeSpectrogram.setChecked(False) self.cb_visualize_waveform.setChecked(False) else: self.cbVisualizeSpectrogram.setChecked(False) self.cb_visualize_waveform.setChecked(False)
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, ("Data file not found:\n{}\n" "If the file path is not stored the data file " "must be in the same directory than your project").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, "Impossible 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 test_project_file_not_found(self): assert project_functions.media_full_path( "geese1.xxx", os.getcwd() + "/files/test.xxx.boris") == ""
def test_file_and_dir(self): assert project_functions.media_full_path( "geese1.mp4", os.getcwd() + "/files/test.boris") == os.getcwd() + "/files/geese1.mp4"
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")