def load_df()

in docker/services/metrics_service.py [0:0]


    def load_df(self, path, algorithm: Algorithm,
                applied_recommendations: List[RecommendationHistory] = None,
                instance_meta: dict = None):
        all_attrs = set(list(algorithm.required_data_attributes))
        metric_attrs = set(list(algorithm.metric_attributes))
        non_metric = all_attrs - metric_attrs
        non_metric.remove(algorithm.timestamp_attribute)
        try:
            df = self.read_metrics(metric_file_path=path, algorithm=algorithm)
            df = self.trim_from_appliance_date(
                df=df, applied_recommendations=applied_recommendations)
            recommendation_settings = algorithm.recommendation_settings
            timezone_name = recommendation_settings.target_timezone_name
            if timezone_name:
                _LOG.debug(f'Converting to timezone \'{timezone_name}\'')
                try:
                    df = df.tz_convert(timezone_name)
                except UnknownTimeZoneError:
                    _LOG.error(f'Unknown timezone \'{timezone_name}\'')
            df = self.fill_missing_timestamps(df=df)
            df.sort_index(ascending=True, inplace=True)
            for attr in non_metric:
                df.drop(attr, inplace=True, axis=1)
            df = self.discard_start(
                df=df,
                algorithm=algorithm,
                instance_meta=instance_meta
            )
            df_duration_days = (df.index.max() - df.index.min()).days
            if np.isnan(df_duration_days) or \
                    df_duration_days < \
                    algorithm.recommendation_settings.min_allowed_days:
                _LOG.error(
                    f'Insufficient data. Analysed period must be larger '
                    f'than a full day with 5-min frequency of records.')
                raise ExecutorException(
                    step_name=JOB_STEP_INITIALIZE_ALGORITHM,
                    reason=f'Insufficient data. Analysed period must be larger '
                           f'than a full day with 5-min frequency of records.'
                )
            df = self.get_last_period(df,
                                      days=recommendation_settings.max_days)
            df = self.group_by_time(
                df=df,
                step_minutes=recommendation_settings.record_step_minutes)
            return df
        except ExecutorException as e:
            raise e
        except Exception as e:
            _LOG.error(f'Error occurred while reading metrics file: {str(e)}')
            raise ExecutorException(
                step_name=JOB_STEP_PROCESS_METRICS,
                reason=f'Unable to read metrics file'
            )