示例#1
0
    def __init__(self, schema_name, report_path, compression, provider_uuid):
        """Initialize the report processor.

        Args:
            schema_name (str): The name of the customer schema to process into
            report_path (str): Where the report file lives in the file system
            compression (CONST): How the report file is compressed.
                Accepted values: UNCOMPRESSED, GZIP_COMPRESSED

        """
        self._processor = None
        _, self.report_type = utils.detect_type(report_path)
        if self.report_type == utils.OCPReportTypes.CPU_MEM_USAGE:
            self._processor = OCPCpuMemReportProcessor(schema_name,
                                                       report_path,
                                                       compression,
                                                       provider_uuid)
        elif self.report_type == utils.OCPReportTypes.STORAGE:
            self._processor = OCPStorageProcessor(schema_name, report_path,
                                                  compression, provider_uuid)
        elif self.report_type == utils.OCPReportTypes.NODE_LABELS:
            self._processor = OCPNodeLabelProcessor(schema_name, report_path,
                                                    compression, provider_uuid)
        elif self.report_type == utils.OCPReportTypes.NAMESPACE_LABELS:
            self._processor = OCPNamespaceLabelProcessor(
                schema_name, report_path, compression, provider_uuid)
        elif self.report_type == utils.OCPReportTypes.UNKNOWN:
            raise OCPReportProcessorError("Unknown OCP report type.")
def divide_csv_daily(file_path, filename):
    """
    Split local file into daily content.
    """
    daily_files = []
    directory = os.path.dirname(file_path)

    data_frame = pd.read_csv(file_path)
    report_type, _ = utils.detect_type(file_path)
    unique_times = data_frame.interval_start.unique()
    days = list({cur_dt[:10] for cur_dt in unique_times})
    daily_data_frames = [{
        "data_frame":
        data_frame[data_frame.interval_start.str.contains(cur_day)],
        "date":
        cur_day
    } for cur_day in days]

    for daily_data in daily_data_frames:
        day = daily_data.get("date")
        df = daily_data.get("data_frame")
        day_file = f"{report_type}.{day}.csv"
        day_filepath = f"{directory}/{day_file}"
        df.to_csv(day_filepath, index=False, header=True)
        daily_files.append({"filename": day_file, "filepath": day_filepath})
    return daily_files
 def report_type(self):
     """Report type for OpenShift, else None."""
     if self.provider_type == Provider.PROVIDER_OCP:
         for file_name in self.file_list:
             report_type, _ = detect_type(file_name)
             if report_type:
                 return report_type
     return None