def enable_saving(self, path: str = None, data_header: bool = True) -> None: if path is None: path = str(Settings.log_save_directory) + '/' + self.name if os.path.exists(path): logging.warning( "Folder {} exist, data from current participant will be saved in {}" .format(path, path + '.new')) path += '.new' self.enable_saving(path, data_header) return os.makedirs(path) csv_path = os.path.join(path, 'data.csv') file_handler = logging.FileHandler(csv_path, 'a', 'UTF-8', False) file_handler.setFormatter(logging.Formatter("%(message)s")) self.experiment_data_logger.addHandler(file_handler) if data_header: self.experiment_data_logger.info( "# matrix_number, video_number, response_time, correctness") with open(os.path.join( path, "meta.json", ), 'w') as f: retu = Settings.to_dict() retu['gender'] = self.gender retu['name'] = self.name f.write(json.dumps(retu, indent=2)) exp_logger.info(f"Saving records enabled. Csv file path {csv_path}")
def runExperiment(self, *args): try: self.getSettings() self.model.load_settings() import_text() except Exception as e: QMessageBox.warning(self.views['main'], "", e.args[0]) log.debug(*e.args) return participant_code = self.views['main'].participantCodeLineEdit.text() self.model.create_participant(participant_code, self.views['main'].participantGenderComboBox.currentText()) set_file_handler(participant_code) exp_logger.info("Experiment started") self.views['experiment'] = ExperimentView(model=self.model, size=QApplication.desktop().screenGeometry(QApplication.desktop().primaryScreen()).size()) self._tutorial()
def create_participant(self, name, gender): exp_logger.info(f"Creating participant with name {name}") self.participant = Participant(name, gender) self.video_played = 0 self.participant.enable_saving()
def tutorial_generator(self): self.view.text_panel.setContent(Resources.text.introduction) self.view.text_panel.on_click = lambda: next(self.tutorial_precedure) exp_logger.info("Tutorial: introduction") yield self.view.text_panel.setContent(Resources.text.description) exp_logger.info("Tutorial: description") yield self.timeout = Settings.Settings.tutorial_duration_of_matrices self.view.changePanelTo(self.view.matrices_widget) exp_logger.info("Tutorial: matrices") yield self.view.text_panel.setContent(Resources.text.example) self.view.changePanelTo(self.view.text_panel) exp_logger.info("Tutorial: Example task") yield self.timeout = Settings.Settings.duration_of_matrices for matrix in self.view.matrices_widget.matrices: matrix.on_click = self.matrixPush, {'matrix': matrix} self.view.video_widget.video_path = self.model._Model__tutorial_video self.view.changePanelTo(self.view.video_widget) exp_logger.info( f"Tutorial: playing video: {self.model._Model__tutorial_video}") yield self.view.changePanelTo(self.view.text_panel) # yield # self.view.text_panel.setContent(Resources.text.end_of_tutorial) yield self.on_finish() exp_logger.info("Tutorial: end ") yield
def mousePressEvent(self, ev: QtGui.QMouseEvent): exp_logger.info(f"Matrix clicked {self.name}") self.on_click()
def showEvent(self, event: QtGui.QShowEvent): super().showEvent(event) exp_logger.info(f"Playing video: {self.video_path}") self.mediaPlayer.play()