def ks_test(timeseries):
 hour_ago = (time() - 3600)
 ten_minutes_ago = (time() - 600)
 reference = scipy.array([x[1] for x in timeseries if ((x[0] >= hour_ago) and (x[0] < ten_minutes_ago))])
 probe = scipy.array([x[1] for x in timeseries if (x[0] >= ten_minutes_ago)])
 if ((reference.size < 20) or (probe.size < 20)):
  return False
 (ks_d, ks_p_value) = scipy.stats.ks_2samp(reference, probe)
 if ((ks_p_value < 0.05) and (ks_d > 0.5)):
  adf = sm.tsa.stattools.adfuller(reference, 10)
  if (adf[1] < 0.05):
   return True
 return False

def ks_test ( timeseries ) : hour_ago = ( time ( ) - 3600 ) ten_minutes_ago = ( time ( ) - 600 ) reference = scipy . array ( [ x [ 1 ] for x in timeseries if ( ( x [ 0 ] >= hour_ago ) and ( x [ 0 ] < ten_minutes_ago ) ) ] ) probe = scipy . array ( [ x [ 1 ] for x in timeseries if ( x [ 0 ] >= ten_minutes_ago ) ] ) if ( ( reference . size < 20 ) or ( probe . size < 20 ) ) : return False ( ks_d , ks_p_value ) = scipy . stats . ks_2samp ( reference , probe ) if ( ( ks_p_value < 0.05 ) and ( ks_d > 0.5 ) ) : adf = sm . tsa . stattools . adfuller ( reference , 10 ) if ( adf [ 1 ] < 0.05 ) : return True return False
a timeseries is anomalous if 2 sample kolmogorov-smirnov test indicates that data distribution for last 10 minutes is different from last hour .