Beispiel #1
0
    def run_testing(self):
        if not self.file_names:
            self.selected_files.setText(
                "No files were selected. Go to menu and "
                "select files to test.")
            return
        # Create new queues every run
        self.queues = [
            multiprocessing.Queue(maxsize=self.PROCESS_NUMBER),
            multiprocessing.Queue(maxsize=self.PROCESS_NUMBER)
        ]
        self.STOP_THREADS = False
        progress = QProgressDialog("Starting Docker and VMs", "Abort start", 0,
                                   len(self.file_names) * 2, self)
        progress.canceled.connect(self.cancel)
        progress.setWindowModality(Qt.WindowModal)

        # Create Qthread to show progress
        self.thread = QThread()
        self.worker = Worker(self, self.file_names, self.queues)
        self.worker.moveToThread(self.thread)
        # Custom signals connected to own functions for progress dialog
        self.show_steps_thread = threading.Thread(target=self.show_steps,
                                                  args=(progress, ))
        self.show_steps_thread.start()
        # Thread start and stop signals connected with slots
        self.thread.started.connect(self.worker.run)
        self.thread.finished.connect(self.remove_processes)
        # Start thread and force to show progress dialog
        self.thread.start()
        progress.forceShow()
Beispiel #2
0
    def benchmarkClicked(self, wrapper):
        if wrapper._benchmark.get('isOther', False):
            path = QFileDialog.getOpenFileName(
                None,
                "Open benchmark",
                join(dirname(__file__), "benchmarks"),
                "Benchmark files (*.hgr)"
            )[0]
            if path:
                outputPath = QFileDialog.getExistingDirectory(
                    None,
                    "Select placement engine output directory",
                    dirname(__file__),
                )
            else:
                outputPath = None
        else:
            path = wrapper._benchmark['path']
            outputPath = dirname(path)

        if path and outputPath:
            app.setOverrideCursor(Qt.WaitCursor)
            results = load_data(path, outputPath)
            app.restoreOverrideCursor()

            if results[0] == -1:
                QMessageBox.critical(
                    None,
                    f"{basename(path)}",
                    f"Could not load benchmark.\n\nReason: {results[1]}",
                )

            else:
                placements = results[1]

                progress = QProgressDialog(
                    labelText="Generating visualizations...",
                    cancelButtonText=None,
                    minimum=0,
                    maximum=len(placements),
                    flags=Qt.WindowStaysOnTopHint,
                )
                progress.setWindowTitle(f"{basename(path)}")
                progress.setMinimumDuration(0)
                progress.setValue(0)
                progress.forceShow()
                app.processEvents()

                self.pws = []
                for placement in placements:
                    app.setOverrideCursor(Qt.WaitCursor)

                    pw = PlacementWindow(placement, app)
                    pw.show()
                    pw.plot()
                    self.pws.append(pw)

                    progress.setValue(progress.value() + 1)
                    app.processEvents()
                app.restoreOverrideCursor()
Beispiel #3
0
    def __init__(self, soundfile, parent):
        self.soundfile = soundfile
        self.isplaying = False
        self.time = 0  # current audio position in frames
        self.audio = QMediaPlayer()
        self.decoder = QAudioDecoder()
        self.is_loaded = False
        self.volume = 100
        self.isplaying = False
        self.decoded_audio = {}
        self.only_samples = []
        self.decoding_is_finished = False
        self.max_bits = 32768
        self.signed = False
        # File Loading is Asynchronous, so we need to be creative here, doesn't need to be duration but it works
        self.audio.durationChanged.connect(self.on_durationChanged)
        self.decoder.finished.connect(self.decode_finished_signal)
        self.audio.setMedia(QUrl.fromLocalFile(soundfile))
        self.decoder.setSourceFilename(
            soundfile)  # strangely inconsistent file-handling
        progress = QProgressDialog("Loading Audio", "Cancel", 0, 0)
        progress.setWindowTitle("Progress")
        progress.setModal(True)
        progress.forceShow()
        # It will hang here forever if we don't process the events.
        while not self.is_loaded:
            QCoreApplication.processEvents()
            time.sleep(0.1)

        self.decode_audio()

        self.np_data = np.array(self.only_samples)
        if not self.signed:  # don't ask me why this fixes 8 bit samples...
            self.np_data = self.np_data - self.max_bits / 2
        print(len(self.only_samples))
        print(self.max_bits)
        progress.close()
        self.isvalid = True
Beispiel #4
0
    def load_projectindex(self, project_idx_file):
        index_loaded = False
        stats_loaded = False
        if project_idx_file != "":
            if os.path.exists(project_idx_file):
                try:
                    self.parent().status.showMessage(
                        f"Loading {project_idx_file}")
                    progress = QProgressDialog("Loading index file...",
                                               "Cancel", 0, 3, self)
                    progress.setWindowTitle("Loading study index")
                    progress.setWindowModality(Qt.WindowModal)
                    progress.setMinimumWidth(300)
                    progress.setMinimumDuration(0)
                    progress.forceShow()
                    progress.setValue(0)
                    wb = load_workbook(project_idx_file, read_only=True)
                    progress.setValue(1)
                    ws = wb['Index']
                    ws.reset_dimensions()
                    data = ws.values
                    cols = next(data)
                    data = list(data)
                    progress.setValue(2)
                    self.data_index = pd.DataFrame(data,
                                                   columns=cols).fillna("")
                    progress.setValue(3)
                    progress.close()
                    # Parse index to the tree
                    num_ecgs = 0
                    if "EGREFID" in self.data_index.columns:
                        num_ecgs = self.data_index[[
                            "ZIPFILE", "AECGXML", "EGREFID", "WFTYPE"
                        ]].drop_duplicates().shape[0]
                        progress = QProgressDialog("Parsing index ...",
                                                   "Cancel", 0, num_ecgs, self)
                        progress.setWindowTitle("Loading study index")
                        progress.setLabelText("Parsing index...")
                        progress.setWindowModality(Qt.WindowModal)
                        progress.setMinimumWidth(300)
                        progress.setMinimumDuration(0)
                        progress.forceShow()
                        progress.setValue(0)
                        self.projectmodel = ProjectTreeModel(
                            self.data_index, progress_dialog=progress)
                        self.project_treeview.setModel(self.projectmodel)
                        self.project_treeview.selectionModel().\
                            selectionChanged.connect(self.load_data)
                        progress.close()
                    else:
                        QMessageBox.warning(
                            self, "EGREFID missing",
                            f"EGREFID column missing Index sheet of "
                            f"{project_idx_file}")
                    self.project_loaded = project_idx_file

                    # Reset aECG display
                    self.tabdisplays.aecg_display.aecg_data = None
                    self.tabdisplays.aecg_display.plot_aecg()

                    # Populate study information/validator tab
                    self.tabdisplays.load_study_info(project_idx_file)
                    self.data_index_info = self.tabdisplays.studyindex_info

                    index_loaded = True
                    try:
                        progress = QProgressDialog(
                            "Loading study index stats...", "Cancel", 0, 3,
                            self)
                        progress.setWindowTitle("Loading study index stats")
                        progress.setWindowModality(Qt.WindowModal)
                        progress.setMinimumWidth(300)
                        progress.setMinimumDuration(0)
                        progress.forceShow()
                        progress.setValue(0)
                        ws = wb['Stats']
                        ws.reset_dimensions()
                        data = ws.values
                        cols = next(data)
                        data = list(data)
                        progress.setValue(1)
                        progress.forceShow()
                        statsdf = pd.DataFrame(data, columns=cols).fillna("")
                        progress.setValue(2)
                        progress.forceShow()
                        self.data_index_stats = aecg.tools.indexer.StudyStats()
                        self.data_index_stats.__dict__.update(
                            statsdf.set_index("Property").transpose().
                            reset_index(drop=True).to_dict('index')[0])
                        progress.setValue(3)
                        progress.forceShow()
                        progress.close()
                        stats_loaded = True
                    except Exception as ex:
                        QMessageBox.warning(
                            self, f"Error loading study index stats",
                            f"Error loading study index stats from"
                            f"{project_idx_file}\n{str(ex)}")
                except Exception as ex:
                    QMessageBox.warning(
                        self, f"Error loading study index",
                        f"Error loading study index from {project_idx_file}"
                        f"\n{str(ex)}")
            else:
                QMessageBox.warning(self, f"Study index file not found",
                                    f"{project_idx_file} not found")

            if index_loaded:
                self.projectindex_loaded.emit()
                if stats_loaded:
                    self.projectindexstats_loaded.emit()
            self.parentWidget().status.clearMessage()
Beispiel #5
0
class Worker(QObject):
    loaded = Signal(int, str)
    finished = Signal()

    def __init__(self, csv_files, b):
        super().__init__()
        self._files = csv_files
        self._size = b

    def run(self):
        self._stop = False
        step = 0
        for i in range(len(self._files)):
            with open(self._files[i], 'r') as csv_file:
                size0 = 0
                for k in range(100):
                    line = csv_file.readline()
                    size0 += sys.getsizeof(line)
                lenght = size0 / 100
                lenght = int(self._size / lenght)
                self.showProgress('Загрузка файлов', lenght, self.stop)
                self.loaded.connect(self.updateProgress)
                csv_file.seek(0)
                reader = csv.reader(csv_file, delimiter='|')
                header = [
                    'number', 'name', 'fname', 'phone', 'uid', 'nik', 'wo'
                ]
                num = 0
                res = []
                for each in reader:
                    num += 1
                    if self._stop:
                        break
                    row = {}
                    trash = each.count('')
                    for i in range(trash):
                        each.remove('')
                    try:
                        for i in range(7):
                            row2 = {}
                            row2 = {header[i]: each[i]}
                            row.update(row2)
                    except IndexError:
                        pass
                    res.append(row)
                    if num % 100000 == 0:
                        new_collection.insert_many(res)
                        res = []
                    self.loaded.emit(step, f'{lenght} документов')
                    if step < lenght - 1:
                        step += 1
                if len(res) != 0:
                    new_collection.insert_many(res)
                step += 1
                self.loaded.emit(step, f'{lenght} документов')
                self.stop()
        self.finished.emit()

    def updateProgress(self, count, file):
        if not self.progress.wasCanceled():
            self.progress.setLabelText('Ожидается примерно %s' %
                                       os.path.basename(file))
            self.progress.setValue(count)

    def showProgress(self, text, length, handler):
        self.progress = QProgressDialog(text, "Отмена", 0, length)
        self.progress.setWindowModality(Qt.WindowModal)
        self.progress.canceled.connect(handler, type=Qt.DirectConnection)
        self.progress.forceShow()

    def stop(self):
        lenght = new_collection.find().count()
        w.set_data(lenght)
        self._stop = True
Beispiel #6
0
    def new_project_indexstats_loaded(self):
        tabs = self.centralWidget().tabdisplays
        progress = QProgressDialog("Parsing statistics from index file...",
                                   "Cancel", 0, 12, self)
        progress.setWindowTitle("Loading study index")
        progress.setWindowModality(Qt.WindowModal)
        progress.setMinimumWidth(300)
        progress.setMinimumDuration(0)
        progress.forceShow()
        progress.setValue(0)
        studyStats = self.centralWidget().data_index_stats

        # number of unique subjects in the index
        tabs.aecg_numsubjects.setText(str(studyStats.num_subjects))
        progress.setValue(1)
        # Num of unique aECG waveforms
        tabs.aecg_numaecg.setText(str(studyStats.num_aecgs))
        progress.setValue(2)
        # aECGs per subject
        tabs.aecg_aecgpersubject.setText(
            str(round(studyStats.avg_aecgs_subject, 2)))
        progress.setValue(3)

        # Other stats
        # Subjects with fewer ECGs
        if studyStats.num_subjects > 0:
            tabs.subjects_less_aecgs.setText(
                str(
                    round(
                        studyStats.subjects_less_aecgs /
                        float(studyStats.num_subjects) * 100, 2)) + " %")
        else:
            tabs.subjects_less_aecgs.setText(" %")
        progress.setValue(4)

        # Subjects with more ECGs
        if studyStats.num_subjects > 0:
            tabs.subjects_more_aecgs.setText(
                str(
                    round(
                        studyStats.subjects_more_aecgs /
                        float(studyStats.num_subjects) * 100, 2)) + " %")
        else:
            tabs.subjects_more_aecgs.setText(" %")
        progress.setValue(5)

        tabs.aecgs_no_annotations.setText(" %")
        tabs.aecgs_less_qt_in_primary_lead.setText(" %")
        tabs.aecgs_less_qt_in_primary_lead.setText(" %")
        tabs.aecgs_less_qts.setText(" %")
        tabs.aecgs_annotations_multiple_leads.setText(" %")
        tabs.aecgs_annotations_no_primary_lead.setText(" %")
        tabs.aecgs_potentially_digitized.setText(" %")
        if studyStats.num_aecgs > 0:
            tabs.aecgs_no_annotations.setText(
                str(
                    round(
                        studyStats.aecgs_no_annotations /
                        studyStats.num_aecgs * 100, 2)) + " %")
            progress.setValue(6)

            # aECGs without expected number of QTs in primary lead
            tabs.aecgs_less_qt_in_primary_lead.setText(
                str(
                    round(
                        studyStats.aecgs_less_qt_in_primary_lead /
                        studyStats.num_aecgs * 100, 2)) + " %")
            progress.setValue(7)

            # num aecgs with at least num_qts in primary lead
            tabs.aecgs_less_qts.setText(
                str(
                    round(
                        studyStats.aecgs_less_qts / studyStats.num_aecgs *
                        100, 2)) + " %")
            progress.setValue(8)

            # aECGs annotated in multiple leads
            tabs.aecgs_annotations_multiple_leads.setText(
                str(
                    round(
                        studyStats.aecgs_annotations_multiple_leads /
                        studyStats.num_aecgs * 100, 2)) + " %")
            progress.setValue(9)

            # aECGs with annotations not in primary lead
            tabs.aecgs_annotations_no_primary_lead.setText(
                str(
                    round(
                        studyStats.aecgs_annotations_no_primary_lead /
                        studyStats.num_aecgs * 100, 2)) + " %")
            progress.setValue(10)

            # aECGS with errors
            tabs.aecgs_with_errors.setText(str(studyStats.aecgs_with_errors))
            progress.setValue(11)

            # Potentially digitized aECGs
            tabs.aecgs_potentially_digitized.setText(
                str(studyStats.aecgs_potentially_digitized))
        progress.setValue(11)
        progress.close()