diff --git a/pkg/algorithms/cmr/cmr.py b/pkg/algorithms/cmr/cmr.py index dd03a49..7959af6 100644 --- a/pkg/algorithms/cmr/cmr.py +++ b/pkg/algorithms/cmr/cmr.py @@ -1,4 +1,4 @@ -"""CMR Algorithm""" +"""CMR - Comparing Mean Responses Algorithm""" # pylint: disable = line-too-long from typing import List @@ -31,6 +31,10 @@ def _analyze(self): self.dataframe["timestamp"] = pd.to_datetime(self.dataframe["timestamp"]) self.dataframe["timestamp"] = self.dataframe["timestamp"].astype(int) // 10**9 + if len(self.dataframe.index) == 1: + series= self.setup_series() + series.data = self.dataframe + return series, {} # if larger than 2 rows, need to get the mean of 0 through -2 self.dataframe = self.combine_and_average_runs( self.dataframe) @@ -58,8 +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] + # 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) @@ -69,7 +73,7 @@ def run_cmr(self, tolerancy: int, dataframe_list: pd.DataFrame): change_point = ChangePoint(metric=column, index=1, - time=difference[1], + time=max_time, stats=ComparativeStats( mean_1=dataframe_list[column][0], mean_2=dataframe_list[column][1], @@ -78,8 +82,8 @@ 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(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 @@ -111,10 +115,11 @@ def combine_and_average_runs(self, dataFrame: pd.DataFrame): if isinstance(dF.loc[0, column], (numpy.float64, numpy.int64)): mean = dF[column].mean() + data2[column] = [mean] else: column_list = dF[column].tolist() - mean = ','.join(column_list) - data2[column] = [mean] + non_numeric_joined_list = ','.join(column_list) + data2[column] = [non_numeric_joined_list] i += 1 df2 = pd.DataFrame(data2)