- if len(tbl_dict[tst_name]["data"]) > 2:
- sample_lst = tbl_dict[tst_name]["data"]
- pd_data = pd.Series(sample_lst)
- win_size = pd_data.size \
- if pd_data.size < table["window"] else table["window"]
- # Test name:
- name = tbl_dict[tst_name]["name"]
-
- # Trend list:
- trend_lst = list(pd_data.rolling(window=win_size, min_periods=2).
- median())
- # Stdevs list:
- t_data, _ = find_outliers(pd_data)
- t_data_lst = list(t_data)
- stdev_lst = list(t_data.rolling(window=win_size, min_periods=2).
- std())
-
- rel_change_lst = [None, ]
- classification_lst = [None, ]
- for idx in range(1, len(trend_lst)):
- # Relative changes list:
- if not isnan(sample_lst[idx]) \
- and not isnan(trend_lst[idx])\
- and trend_lst[idx] != 0:
- rel_change_lst.append(
- int(relative_change(float(trend_lst[idx]),
- float(sample_lst[idx]))))
- else:
- rel_change_lst.append(None)
- # Classification list:
- if isnan(t_data_lst[idx]) or isnan(stdev_lst[idx]):
- classification_lst.append("outlier")
- elif sample_lst[idx] < (trend_lst[idx] - 3*stdev_lst[idx]):
- classification_lst.append("regression")
- elif sample_lst[idx] > (trend_lst[idx] + 3*stdev_lst[idx]):
- classification_lst.append("progression")
- else:
- classification_lst.append("normal")
-
- last_idx = len(sample_lst) - 1
- first_idx = last_idx - int(table["evaluated-window"])
- if first_idx < 0:
- first_idx = 0
-
- if "regression" in classification_lst[first_idx:]:
- classification = "regression"
- elif "outlier" in classification_lst[first_idx:]:
- classification = "outlier"
- elif "progression" in classification_lst[first_idx:]:
- classification = "progression"
- elif "normal" in classification_lst[first_idx:]:
- classification = "normal"
- else:
- classification = None
-
- idx = len(classification_lst) - 1
- while idx:
- if classification_lst[idx] == classification:
- break
- idx -= 1
-
- trend = round(float(trend_lst[-2]) / 1000000, 2) \
- if not isnan(trend_lst[-2]) else ''
- sample = round(float(sample_lst[idx]) / 1000000, 2) \
- if not isnan(sample_lst[idx]) else ''
- rel_change = rel_change_lst[idx] \
- if rel_change_lst[idx] is not None else ''
- tbl_lst.append([name,
- trend,
- sample,
- rel_change,
- classification])
-
- # Sort the table according to the classification
+ if len(tbl_dict[tst_name]["data"]) < 3:
+ continue
+
+ pd_data = pd.Series(tbl_dict[tst_name]["data"])
+ data_t, _ = split_outliers(pd_data, outlier_const=1.5,
+ window=table["window"])
+ last_key = data_t.keys()[-1]
+ win_size = min(data_t.size, table["window"])
+ win_first_idx = data_t.size - win_size
+ key_14 = data_t.keys()[win_first_idx]
+ long_win_size = min(data_t.size, table["long-trend-window"])
+ median_t = data_t.rolling(window=win_size, min_periods=2).median()
+ median_first_idx = median_t.size - long_win_size
+ try:
+ max_median = max(
+ [x for x in median_t.values[median_first_idx:-win_size]
+ if not isnan(x)])
+ except ValueError:
+ max_median = nan
+ try:
+ last_median_t = median_t[last_key]
+ except KeyError:
+ last_median_t = nan
+ try:
+ median_t_14 = median_t[key_14]
+ except KeyError:
+ median_t_14 = nan
+
+ if isnan(last_median_t) or isnan(median_t_14) or median_t_14 == 0.0:
+ rel_change_last = nan
+ else:
+ rel_change_last = round(
+ ((last_median_t - median_t_14) / median_t_14) * 100, 2)
+
+ if isnan(max_median) or isnan(last_median_t) or max_median == 0.0:
+ rel_change_long = nan
+ else:
+ rel_change_long = round(
+ ((last_median_t - max_median) / max_median) * 100, 2)
+
+ # Classification list:
+ classification_lst = classify_anomalies(data_t, window=14)
+
+ if classification_lst:
+ if isnan(rel_change_last) and isnan(rel_change_long):
+ continue
+ tbl_lst.append(
+ [tbl_dict[tst_name]["name"],
+ '-' if isnan(last_median_t) else
+ round(last_median_t / 1000000, 2),
+ '-' if isnan(rel_change_last) else rel_change_last,
+ '-' if isnan(rel_change_long) else rel_change_long,
+ classification_lst[win_first_idx:].count("regression"),
+ classification_lst[win_first_idx:].count("progression"),
+ classification_lst[win_first_idx:].count("outlier")])
+
+ tbl_lst.sort(key=lambda rel: rel[0])
+