Browse Source

Analytic bucket size #446 (#451)

pull/1/head
Evgeny Smyshlyaev 6 years ago committed by rozetko
parent
commit
86c4433b65
  1. 1
      analytics/analytics/buckets/data_bucket.py
  2. 12
      analytics/analytics/detectors/pattern_detector.py

1
analytics/analytics/buckets/data_bucket.py

@ -11,4 +11,5 @@ class DataBucket(object):
self.data = self.data.append(data, ignore_index=True) self.data = self.data.append(data, ignore_index=True)
def drop_data(self, count: int): def drop_data(self, count: int):
if count > 0:
self.data = self.data.iloc[count:] self.data = self.data.iloc[count:]

12
analytics/analytics/detectors/pattern_detector.py

@ -37,8 +37,7 @@ class PatternDetector(Detector):
self.analytic_unit_id = analytic_unit_id self.analytic_unit_id = analytic_unit_id
self.pattern_type = pattern_type self.pattern_type = pattern_type
self.model = resolve_model_by_pattern(self.pattern_type) self.model = resolve_model_by_pattern(self.pattern_type)
self.max_window_size = 150 self.min_bucket_size = 150
self.window_size = 0
self.bucket = DataBucket() self.bucket = DataBucket()
def train(self, dataframe: pd.DataFrame, segments: list, cache: Optional[models.ModelCache]) -> models.ModelCache: def train(self, dataframe: pd.DataFrame, segments: list, cache: Optional[models.ModelCache]) -> models.ModelCache:
@ -71,12 +70,13 @@ class PatternDetector(Detector):
return None return None
self.bucket.receive_data(data_without_nan) self.bucket.receive_data(data_without_nan)
if cache and self.window_size == 0: if not cache: cache = {}
self.window_size = cache['WINDOW_SIZE'] bucket_size = max(cache.get('WINDOW_SIZE', 0) * 3, self.min_bucket_size)
res = self.detect(self.bucket.data, cache) res = self.detect(self.bucket.data, cache)
if len(self.bucket.data) >= self.window_size and cache != None:
excess_data = len(self.bucket.data) - self.max_window_size if len(self.bucket.data) > bucket_size:
excess_data = len(self.bucket.data) - bucket_size
self.bucket.drop_data(excess_data) self.bucket.drop_data(excess_data)
if res: if res:

Loading…
Cancel
Save