gui/gui_mainLayout.py
def data_processing(self):
        """
        This function separates data, from the file to display curves, and will put them in the good arrays.
        """
        the_file_name = str(self.result_file)
        the_file = open(the_file_name, 'r')

        lines = the_file.readlines()

        # We put all lines in an array and we put each cell of the line in a column.
        lines_array = []
        for line in lines:
            line = line.split(',')  # Each time there is a tabulation, there is a new cell
            lines_array.append(line)

        labels_line = lines_array[0]
        cell_labels_line = 0  # Iterator on each cell of the line labels_line.
        flag = True  # Become FALSE when we find the word which separate data from wavelength values.

        try:
            while flag:  # While it is TRUE, so if the word doesn't match, it's an infinite loop,
                if "wave length (nm)" in labels_line[cell_labels_line]:
                    index = labels_line.index(labels_line[cell_labels_line])  # Find the index of the string searched.
                    flag = False
                else:
                    cell_labels_line += 1
        except IndexError:  # In case of an infinite loop.
            raise sys.exit("Warning : There is no value named 'wavelength' in the file used to plot curves. "
                           "So, I can't separate data to plot curves and data about tests linking with these curves.")

        self.information = []  # This array will contain the data displayed under the curves.
        data_wavelength = []  # This array will contain the data to plot curves.
        self.num_line = 0  # Iterator on each line of lines_array,
        # The array containing data about information and wavelength.
        for line in lines_array:
            cell_line = 0  # Iterator on each cell of the line.
            self.information.append([])
            data_wavelength.append([])
            while cell_line < len(line):
                if cell_line < index:
                    self.information[self.num_line].append(line[cell_line])
                elif cell_line > index:
                    data_wavelength[self.num_line].append(line[cell_line])
                cell_line += 1
            self.num_line += 1

        # We transform wavelengths from strings to floats.
        line_wavelength = 0  # Iterator on each line of data_wavelength
        for row_data_wavelength in data_wavelength:
            row_data_wavelength = [float(item.strip('\n').strip('\"')) for item in row_data_wavelength]
            data_wavelength[line_wavelength] = row_data_wavelength
            line_wavelength += 1

        self.wavelength = data_wavelength[0]  # The first line contains wavelength
        self.data_wanted = data_wavelength[1:]  # The others contain data useful to plot curves.

        the_file.close()
def data_processing(self):
        the_file_name = str(self.result_file)
        the_file = open(the_file_name, 'r')

        lines = the_file.readlines()

        # We put all lines in an array and we put each cell of the line in a column.
        lines_array = []
        for line in lines:
            line = line.split(',')  # Each time there is a tabulation, there is a new cell
            lines_array.append(line)

        labels_line = lines_array[0]
        cell_labels_line = 0  # Iterator on each cell of the line labels_line.
        flag = True  # Become FALSE when we find the word which separate data from wavelength values.

        try:
            while flag:  # While it is TRUE, so if the word doesn't match, it's an infinite loop,
                if "wave length (nm)" in labels_line[cell_labels_line]:
                    index = labels_line.index(labels_line[cell_labels_line])  # Find the index of the string searched.
                    flag = False
                else:
                    cell_labels_line += 1
        except IndexError:  # In case of an infinite loop.
            raise sys.exit("Warning : There is no value named 'wavelength' in the file used to plot curves. "
                           "So, I can't separate data to plot curves and data about tests linking with these curves.")

        self.information = []  # This array will contain the data displayed under the curves.
        data_wavelength = []  # This array will contain the data to plot curves.
        self.num_line = 0  # Iterator on each line of lines_array,
        # The array containing data about information and wavelength.
        for line in lines_array:
            cell_line = 0  # Iterator on each cell of the line.
            self.information.append([])
            data_wavelength.append([])
            while cell_line < len(line):
                if cell_line < index:
                    self.information[self.num_line].append(line[cell_line])
                elif cell_line > index:
                    data_wavelength[self.num_line].append(line[cell_line])
                cell_line += 1
            self.num_line += 1

        # We transform wavelengths from strings to floats.
        line_wavelength = 0  # Iterator on each line of data_wavelength
        for row_data_wavelength in data_wavelength:
            row_data_wavelength = [float(item.strip('\n').strip('\"')) for item in row_data_wavelength]
            data_wavelength[line_wavelength] = row_data_wavelength
            line_wavelength += 1

        self.wavelength = data_wavelength[0]  # The first line contains wavelength
        self.data_wanted = data_wavelength[1:]  # The others contain data useful to plot curves.

        the_file.close()
def data_processing ( self ) : the_file_name = str ( self . result_file ) the_file = open ( the_file_name , 'r' ) lines = the_file . readlines ( ) # We put all lines in an array and we put each cell of the line in a column. lines_array = [ ] for line in lines : line = line . split ( ',' ) # Each time there is a tabulation, there is a new cell lines_array . append ( line ) labels_line = lines_array [ 0 ] cell_labels_line = 0 # Iterator on each cell of the line labels_line. flag = True # Become FALSE when we find the word which separate data from wavelength values. try : while flag : # While it is TRUE, so if the word doesn't match, it's an infinite loop, if "wave length (nm)" in labels_line [ cell_labels_line ] : index = labels_line . index ( labels_line [ cell_labels_line ] ) # Find the index of the string searched. flag = False else : cell_labels_line += 1 except IndexError : # In case of an infinite loop. raise sys . exit ( "Warning : There is no value named 'wavelength' in the file used to plot curves. " "So, I can't separate data to plot curves and data about tests linking with these curves." ) self . information = [ ] # This array will contain the data displayed under the curves. data_wavelength = [ ] # This array will contain the data to plot curves. self . num_line = 0 # Iterator on each line of lines_array, # The array containing data about information and wavelength. for line in lines_array : cell_line = 0 # Iterator on each cell of the line. self . information . append ( [ ] ) data_wavelength . append ( [ ] ) while cell_line < len ( line ) : if cell_line < index : self . information [ self . num_line ] . append ( line [ cell_line ] ) elif cell_line > index : data_wavelength [ self . num_line ] . append ( line [ cell_line ] ) cell_line += 1 self . num_line += 1 # We transform wavelengths from strings to floats. line_wavelength = 0 # Iterator on each line of data_wavelength for row_data_wavelength in data_wavelength : row_data_wavelength = [ float ( item . strip ( '\n' ) . strip ( '\"' ) ) for item in row_data_wavelength ] data_wavelength [ line_wavelength ] = row_data_wavelength line_wavelength += 1 self . wavelength = data_wavelength [ 0 ] # The first line contains wavelength self . data_wanted = data_wavelength [ 1 : ] # The others contain data useful to plot curves. the_file . close ( )
This function separates data, from the file to display curves, and will put them in the good arrays.
This function separates data from the file to display curves and will put them in the good arrays .