diff --git a/pkg/algorithms/cmr/cmr.py b/pkg/algorithms/cmr/cmr.py index 7959af6..d72f35a 100644 --- a/pkg/algorithms/cmr/cmr.py +++ b/pkg/algorithms/cmr/cmr.py @@ -26,8 +26,8 @@ def _analyze(self): series: data series that contains attributes and full dataframe change_points_by_metric: list of ChangePoints """ - logger_instance = SingletonLogger.getLogger("Orion") - logger_instance.info("Starting analysis using CMR") + self.logger_instance = SingletonLogger.getLogger("Orion") + self.logger_instance.info("Starting analysis using CMR") self.dataframe["timestamp"] = pd.to_datetime(self.dataframe["timestamp"]) self.dataframe["timestamp"] = self.dataframe["timestamp"].astype(int) // 10**9 @@ -62,14 +62,8 @@ def run_cmr(self, tolerancy: int, dataframe_list: pd.DataFrame): change_points_by_metric={ k:[] for k in metric_columns } max_date_time = pd.Timestamp.max.to_pydatetime() max_time = max_date_time.timestamp() - # difference = ["difference", max_time] - # pass_fail_list = ["Pass/Fail", max_time] + for column in metric_columns: - pct_change_result = dataframe_list[column].pct_change() - single_pct_diff = round(pct_change_result.iloc[[-1]].values[0] * 100) - pass_fail = "Pass" - if single_pct_diff > tolerancy: - pass_fail = "Fail" change_point = ChangePoint(metric=column, index=1, @@ -82,13 +76,6 @@ def run_cmr(self, tolerancy: int, dataframe_list: pd.DataFrame): pvalue=1 )) change_points_by_metric[column].append(change_point) - # difference.append(single_pct_diff) - # pass_fail_list.append(pass_fail) - # difference.append("none") - # pass_fail_list.append("none") - # dataframe_list.loc[len(dataframe_list.index)] = difference - #dataframe_list.loc[len(dataframe_list.index)] = pass_fail_list - # logger_instance.info("final data frame " + str(dataframe_list)) # based on change point generate pass/fail return dataframe_list, change_points_by_metric diff --git a/pkg/runTest.py b/pkg/runTest.py index b24026c..3f09599 100644 --- a/pkg/runTest.py +++ b/pkg/runTest.py @@ -9,7 +9,16 @@ import pkg.constants as cnsts from pkg.utils import get_datasource, process_test, get_subtracted_timestamp - +def get_algorithm_type(kwargs): + if kwargs["hunter_analyze"]: + algorithm_name = cnsts.EDIVISIVE + elif kwargs["anomaly_detection"]: + algorithm_name = cnsts.ISOLATION_FOREST + elif kwargs['cmr']: + algorithm_name = cnsts.CMR + else: + algorithm_name = None + return algorithm_name def run(**kwargs: dict[str, Any]) -> dict[str, Any]: #pylint: disable = R0914 """run method to start the tests @@ -48,13 +57,8 @@ def run(**kwargs: dict[str, Any]) -> dict[str, Any]: #pylint: disable = R0914 if fingerprint_matched_df is None: sys.exit(3) # No data present - if kwargs["hunter_analyze"]: - algorithm_name = cnsts.EDIVISIVE - elif kwargs["anomaly_detection"]: - algorithm_name = cnsts.ISOLATION_FOREST - elif kwargs['cmr']: - algorithm_name = cnsts.CMR - else: + algorithm_name = get_algorithm_type(kwargs) + if algorithm_name is None: return None, None algorithmFactory = AlgorithmFactory()