Exemplo n.º 1
0
    def load_info(self):
        if not self.filepath:
            return

        with open(self.filepath) as filestream:
            csvreader = csv.reader(filestream)
            self.subjects = []

            count = 0
            for row in csvreader:
                msg = BpodMessageParser.fromlist(row)

                if msg:
                    if isinstance(msg, SessionInfo):
                        if msg.infoname == Session.INFO_SESSION_NAME:
                            self.task_name = msg.infovalue

                        elif msg.infoname == Session.INFO_CREATOR_NAME:
                            self.creator = msg.infovalue

                        elif msg.infoname == Session.INFO_SESSION_STARTED:
                            self.started = date_parser.parse(msg.infovalue)

                        elif msg.infoname == Session.INFO_SESSION_ENDED:
                            self.ended = date_parser.parse(msg.infovalue)

                        elif msg.infoname == Session.INFO_SERIAL_PORT:
                            self.board_serial_port = msg.infovalue

                        elif msg.infoname == Session.INFO_BOARD_NAME:
                            self.board_name = msg.infovalue

                        elif msg.infoname == Session.INFO_SETUP_NAME:
                            self.setup_name = msg.infovalue

                        elif msg.infoname == Session.INFO_SUBJECT_NAME:
                            self.subjects += [msg.infovalue]
                            name, uuid4 = eval(msg.infovalue)
                            subj = self.project.find_subject_by_id(uuid4)
                            if subj is not None:
                                subj += self
                    else:
                        count += 1

                if count > 50:
                    break

            return csvreader
Exemplo n.º 2
0
    def load_contents(self, init_func=None, update_func=None, end_func=None):
        """
        Parses session history file, line by line and populates the history message on memory.
        """
        if not self.filepath:
            return

        nrows = csv.reader.count_metadata_rows(self.filepath)

        with open(self.filepath) as filestream:
            self.data = pd.read_csv(filestream,
                                    delimiter=csv.CSV_DELIMITER,
                                    quotechar=csv.CSV_QUOTECHAR,
                                    quoting=csv.CSV_QUOTING,
                                    lineterminator=csv.CSV_LINETERMINATOR,
                                    skiprows=nrows,
                                    memory_map=True)

        res = self.data.query("MSG=='{0}'".format(Session.INFO_SESSION_ENDED))
        for index, row in res.iterrows():
            self.ended = date_parser.parse(row['+INFO'])

        res = self.data.query(
            "TYPE in ['VAL', 'TRIAL'] or MSG=='SESSION-ENDED'")
        variables = []
        for index, row in res.iterrows():
            if row['TYPE'] == 'TRIAL':
                variables.append(['New trial', None])
            elif row['MSG'] == 'SESSION-ENDED':
                variables.append(['Session ended', None])
            else:
                variables.append([row['MSG'], row['+INFO']])
Exemplo n.º 3
0
 def fromlist(cls, row):
     """
     Returns True if the typestr represents the class
     """
     obj = cls()
     obj.pc_timestamp = date_parser.parse(row[1])
     return obj
Exemplo n.º 4
0
    def fromlist(cls, row):
        """
        Returns True if the typestr represents the class
        """
        obj = cls(int(row[4]), row[5], float(row[2]) if row[2] else None)
        obj.pc_timestamp = date_parser.parse(row[1])

        return obj
Exemplo n.º 5
0
 def fromlist(cls, row):
     """
     Returns True if the typestr represents the class
     """
     obj = cls(row[4], float(row[2]) if row[2] else None)
     obj.pc_timestamp = date_parser.parse(row[1])
     obj._infovalue = row[5] if len(row) > 5 else None
     return obj
Exemplo n.º 6
0
    def end_run_task_handler(self):
        self.stop_thread()

        if not self._running_detached:
            # in case it is running detached
            errline = self.stderrstream.readline()
            if errline is not None:
                self.log2board(errline)

        # del self.proc

        session = self._running_session

        filepath = os.path.join(session.path, session.name + '.csv')
        session.filepath = filepath if os.path.exists(filepath) else None

        ## Execute the POST commands ##################################
        for cmd in self._running_task.commands:
            if cmd.when == 1:
                try:
                    cmd.execute(session=session)
                except Exception as err:
                    traceback.print_exc()
                    self.alert(
                        str(err),
                        "Unexpected error when executing the post-command")

        ###############################################################

        self.status = self.STATUS_READY

        if self._running_detached:
            session.load_contents()

        if session.data is not None:
            res = session.data.query("MSG=='{0}'".format(
                Session.INFO_SESSION_ENDED))
            for index, row in res.iterrows():
                session.ended = date_parser.parse(row['+INFO'])

            board_task = self._running_boardtask

            if board_task.update_variables:
                for var in board_task.variables:
                    res = session.data.query(
                        "TYPE=='VAL' and MSG=='{0}'".format(var.name))
                    for index, row in res.tail(1).iterrows():
                        value = row['+INFO']
                        if var.datatype == 'string':
                            var.value = value
                        else:
                            value.isdigit()
                            var.datatype == float(value)