def prepareParameters(self):
        """
        method prepares poincare plot parameters
        """
        if self.stepper:
            self.stepper_size = extract_number(self.stepper, convert=int)
            self.stepper_unit = extract_alphabetic(self.stepper,
                                                   convert=str.lower)
        self.movie_dir = nvl(self.movie_dir, self.output_dir, '')

        if isinstance(self.excluded_annotations, str):
            self.excluded_annotations = get_as_list(self.excluded_annotations)

        if self.filters_names is not None:
            map(self.addFilter, get_as_list(self.filters_names))

        if self.output_dir:
            # remove leading and trailing whitespaces
            self.output_dir = self.output_dir.strip()

        if self.window_size:
            self.window_size_unit = extract_alphabetic(self.window_size,
                                                       convert=str.lower)
            self.window_size_value = extract_number(self.window_size,
                                                    convert=int)

        self.movie_multiprocessing_factor = nvl(
            self.movie_multiprocessing_factor,
            3 if multiprocessing.cpu_count() > 1 else 0)

        if not self.data_file == None:
            self.group_data_filename = None

        if isinstance(self.output_precision, str):
            self.output_precision = get_as_tuple(self.output_precision,
                                                 convert=int)
        elif self.output_precision == None:
            self.output_precision = DEFAULT_OUTPUT_PRECISION

        if self.add_headers == None:
            self.add_headers = True

        if len(self.statistics_classes) > 0:
            self.statistics_names = [
                s.__name__.replace("Statistic", "")
                for s in self.statistics_classes
            ]
    def prepareParameters(self):
        """
        method prepares poincare plot parameters
        """
        if self.stepper:
            self.stepper_size = extract_number(self.stepper, convert=int)
            self.stepper_unit = extract_alphabetic(self.stepper, convert=str.lower)
        self.movie_dir = nvl(self.movie_dir, self.output_dir, "")

        if isinstance(self.excluded_annotations, str):
            self.excluded_annotations = get_as_list(self.excluded_annotations)

        if self.filters_names is not None:
            map(self.addFilter, get_as_list(self.filters_names))

        if self.output_dir:
            # remove leading and trailing whitespaces
            self.output_dir = self.output_dir.strip()

        if self.window_size:
            self.window_size_unit = extract_alphabetic(self.window_size, convert=str.lower)
            self.window_size_value = extract_number(self.window_size, convert=int)

        self.movie_multiprocessing_factor = nvl(
            self.movie_multiprocessing_factor, 3 if multiprocessing.cpu_count() > 1 else 0
        )

        if not self.data_file == None:
            self.group_data_filename = None

        if isinstance(self.output_precision, str):
            self.output_precision = get_as_tuple(self.output_precision, convert=int)
        elif self.output_precision == None:
            self.output_precision = DEFAULT_OUTPUT_PRECISION

        if self.add_headers == None:
            self.add_headers = True

        if len(self.statistics_classes) > 0:
            self.statistics_names = [s.__name__.replace("Statistic", "") for s in self.statistics_classes]
Esempio n. 3
0
def merge_xls_by_index_file(output_xls, source_csv_files_mask, separator,
              index_file_xls, index_sheet_name):
    print('***************************************************')
    print('csv source files: ' + source_csv_files_mask)

    index_xls = load_workbook(index_file_xls)
    index_sheet = index_xls.get_sheet_by_name(index_sheet_name)
    index_cells = zip(index_sheet.columns[0], index_sheet.columns[1])

    xls = None
    merged_sheet = None
    for file_nr, _file in enumerate(glob.glob(source_csv_files_mask)):
        #if file_nr == 2:
        #    break
        print('===================================')
        print('Processing file: ' + str(_file))
        if xls == None:
            xls = load_workbook(output_xls)
            merged_sheet = xls.get_sheet_by_name('merged')
            headers_cells = merged_sheet.rows[0]
            code_cells = merged_sheet.columns[2]

        (headers_line, values_line) = get_first_lines(_file, count=2)
        filename = get_filename(_file)
        (group, file_ident) = filename.split('_')
        headers = [str(group + "_" + header.strip())
                        for header in headers_line.split(separator)]
        values = [value.strip() for value in values_line.split(separator)]

        file_number = extract_number(file_ident)
        ident_row = None
        for (file_index_cell, code_index_cell) in index_cells:
            if not ident_row == None:
                break
            if file_number == file_index_cell.value:
                for code_cell in code_cells:
                    if code_cell.value == code_index_cell.value:
                        ident_row = code_cell.row - 1
                        break

        #print("ident_row: " + str(ident_row))
        #add header
        save = False
        if ident_row:
            for header_idx, header in enumerate(headers):

                ident_column = None
                for cell in headers_cells:
                    if header == cell.value:
                        ident_column = cell.column
                        break
                if ident_column == None:
                    ident_column = merged_sheet.get_highest_column()
                    header_cell = merged_sheet.cell(row=0, column=ident_column)
                    header_cell.value = header
                    value_cell = merged_sheet.cell(row=ident_row,
                                               column=ident_column)
                    save = True
                else:
                    value_cell = merged_sheet.cell(
                                coordinate=ident_column + str(ident_row + 1))
                value_cell.value = values[header_idx]
        else:
            print('No item in xls file for ' + str(_file))
            return
        if save:
            print("Saving " + output_xls)
            xls.save(output_xls)
            print(".. done")
            xls = None

    if not xls == None:
        print("Saving " + output_xls)
        xls.save(output_xls)
        print(".. done")