# Techniques for outlier detection of speeds. Each of these returns a speed threshold that 
# can be used with outlier detection techniques.

# Standard imports
import logging

logging.basicConfig(level=logging.DEBUG)

class BoxplotOutlier(object):
    MINOR = 1.5
    MAJOR = 3
    def __init__(self, multiplier = MAJOR):
        self.multiplier = multiplier

    def get_threshold(self, with_speeds_df):
        quartile_vals = with_speeds_df.quantile([0.25, 0.75]).speed
        logging.debug("quartile values are %s" % quartile_vals)
        iqr = quartile_vals.iloc[1] - quartile_vals.iloc[0]
        logging.debug("iqr %s" % iqr)
        return quartile_vals.iloc[1] + self.multiplier * iqr

class SimpleQuartileOutlier(object):
    def __init__(self, quantile = 0.99):
        self.quantile = quantile

    def get_threshold(self, with_speeds_df):
        return with_speeds_df.speed.quantile(self.quantile)


@@ -313,16 +313,38 @@
  = MAJOR
+, ignore_zeros = False
 ):%0A     
@@ -374,16 +374,57 @@
 ltiplier
+%0A        self.ignore_zeros = ignore_zeros
 %0A%0A    de
@@ -474,38 +474,181 @@
     
-quartile_vals = with_speeds_df
+if self.ignore_zeros:%0A            df_to_use = with_speeds_df%5Bwith_speeds_df.speed %3E 0%5D%0A        else:%0A            df_to_use = with_speeds_df%0A        quartile_vals = df_to_use
 .qua
@@ -972,16 +972,38 @@
 e = 0.99
+, ignore_zeros = False
 ):%0A     
@@ -1029,16 +1029,57 @@
 quantile
+%0A        self.ignore_zeros = ignore_zeros
 %0A%0A    de
@@ -1129,29 +1129,172 @@
     
-return with_speeds_df
+if self.ignore_zeros:%0A            df_to_use = with_speeds_df%5Bwith_speeds_df.speed %3E 0%5D%0A        else:%0A            df_to_use = with_speeds_df%0A        return df_to_use
 .spe

Support an option to ignore zeros while calculating thresholds