CSIT-1041: Trending dashboard
[csit.git] / resources / tools / presentation / utils.py
index 2fbf70c..a15742a 100644 (file)
@@ -81,15 +81,26 @@ def remove_outliers(input_list, outlier_const=1.5, window=14):
     :rtype: list of floats
     """
 
-    input_series = pd.Series()
-    for index, value in enumerate(input_list):
-        item_pd = pd.Series([value, ], index=[index, ])
-        input_series.append(item_pd)
-    output_series, _ = split_outliers(input_series, outlier_const=outlier_const,
-                                      window=window)
-    output_list = [y for x, y in output_series.items() if not np.isnan(y)]
-
-    return output_list
+    data = np.array(input_list)
+    upper_quartile = np.percentile(data, 75)
+    lower_quartile = np.percentile(data, 25)
+    iqr = (upper_quartile - lower_quartile) * outlier_const
+    quartile_set = (lower_quartile - iqr, upper_quartile + iqr)
+    result_lst = list()
+    for y in data.tolist():
+        if quartile_set[0] <= y <= quartile_set[1]:
+            result_lst.append(y)
+    return result_lst
+
+    # input_series = pd.Series()
+    # for index, value in enumerate(input_list):
+    #     item_pd = pd.Series([value, ], index=[index, ])
+    #     input_series.append(item_pd)
+    # output_series, _ = split_outliers(input_series, outlier_const=outlier_const,
+    #                                   window=window)
+    # output_list = [y for x, y in output_series.items() if not np.isnan(y)]
+    #
+    # return output_list
 
 
 def split_outliers(input_series, outlier_const=1.5, window=14):

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.