Beispiel #1
0
    def load(self, fname):
        # Storing the name of the file for editting purposes
        self.fname = fname
        # Auxiliary dictionary to speed up the data convertion into pandas
        aux_dict = dict(raw_time=[], time=[], event=[], experiment=[], item=[],
                        count=[], comment=[])

        # Importing the file
        out_ouf_metadata = False
        with open(fname) as f:
            for line in f:

                if '\n' in line[0]:
                    pass
                # Filtering lines with comments
                elif '#' in line[0]:
                    if not out_ouf_metadata:
                        self.header.append(line)
                        self._read_metada(line)
                    else:
                        self.WTF.append(line)
                # Storing events
                elif is_elapsed_time(line.split()[0]):
                    aux_dict = self._read_events(line, aux_dict)
                # Useful data from the header
                else:
                    # We can say we are out of the metadate here because
                    # start_time and end_time are mandatory in the files
                    out_ouf_metadata = True
                    self._read_header_line(line.split())
        # Closing the file
        f.close()
        # Creating the pandas dataframe
        self.events = pd.DataFrame(aux_dict)
        # Sorting by the time
        self.events = self.events.sort(['time'])
        # Sorting the columns in the dataframe
        cols = ['raw_time', 'time', 'event', 'experiment', 'item', 'count',
                'comment']
        self.events = self.events[cols]
Beispiel #2
0
    def merge_includes(self):
        self.merged_events = self.events
        # Getting the path to load correctly the files
        path = os.path.dirname(os.path.abspath(self.fname))
        for f in self.include_files:
            print ("Reading " + f[0] + "...")
            fname = os.path.join(path, f[0].strip('"'))
            # There is an existing time
            if len(f) > 1 and is_elapsed_time(f[1]):
                ref_date = self._to_datetime(f[1])
                itl = ITL(fname, ref_date=ref_date)
            else:
                itl = ITL(fname)

            itl.check_consistency()
            # Recursing over the itl files
            itl.merge_includes()
            # Merging the dataframes
            self.merged_events = \
                pd.concat([self.merged_events, itl.merged_events],
                          ignore_index=True)
        self.merged_events = self.order_colums_in_dataframe(self.merged_events)
Beispiel #3
0
    def load(self, fname):
        # Storing the name of the file for editting purposes
        self.fname = fname

        # Auxiliary dictionary to speed up the data convertion into pandas
        aux_dict = dict(raw_time=[], time=[], experiment=[], mode=[],
                        action=[], parameters=[], comment=[])

        # Importing the file
        out_ouf_metadata = False
        with open(fname) as f:
            line = ""
            line_comments = list()
            for l in f:
                # Formatting just in case there is no space between parenthesis
                l = l.replace('(', ' ( ').replace(')', ' ) ')
                # Concatening lines if '\' found
                if '\\' in l and '#' not in l[0] and \
                   '\\' not in l[l.index('\\') + 1]:
                    line += l[:l.index('\\')]
                    line_comments.append(l[l.index('\\') + 1: - 1])
                    # Continues with the next iteration of the loop
                    continue
                # If there was no concatenation of lines
                if len(line) == 0:
                    line = l
                # If we were concatenating, we concatenate the last one
                else:
                    line += l[:l.index(')') + 1]
                    line_comments.append(l[l.index(')'):])

                if '\n' in line[0]:
                    pass
                elif 'Comment:' in line:
                    pass
                # Filtering lines with comments
                elif '#' in line[0]:
                    if not out_ouf_metadata:
                        self.header.append(line)
                        self._read_metada(line)
                    else:
                        self.WTF.append(line)
                # Storing events
                elif len(line.split()) > 0 and \
                        is_elapsed_time(line.split()[0]):
                    aux_dict = \
                        self._read_events(line, aux_dict, line_comments)
                # Useful data from the header
                else:
                    # We can say we are out of the metadate here because
                    # start_time and end_time are mandatory in the files
                    out_ouf_metadata = True
                    self._read_header_line(line.split())
                # Preparing values for next iteration
                line = ""
                line_comments = list()
        # Closing the file
        f.close()
        # Creating the pandas dataframe
        self.events = pd.DataFrame(aux_dict)
        self.events = self.order_colums_in_dataframe(self.events)