@ -8,6 +8,7 @@ from typing import Optional
from detectors import Detector
from buckets import DataBucket
from models import ModelCache
logger = logging . getLogger ( ' PATTERN_DETECTOR ' )
@ -37,14 +38,14 @@ class PatternDetector(Detector):
self . window_size = 100
self . bucket = DataBucket ( )
def train ( self , dataframe : pd . DataFrame , segments : list , cache : Optional [ models . AnalyticUnit Cache] ) - > models . AnalyticUnit Cache:
def train ( self , dataframe : pd . DataFrame , segments : list , cache : Optional [ models . Model Cache] ) - > models . Model Cache:
# TODO: pass only part of dataframe that has segments
new_cache = self . model . fit ( dataframe , segments , cache )
return {
' cache ' : new_cache
}
def detect ( self , dataframe : pd . DataFrame , cache : Optional [ models . AnalyticUnit Cache] ) - > dict :
def detect ( self , dataframe : pd . DataFrame , cache : Optional [ models . Model Cache] ) - > dict :
# TODO: split and sleep (https://github.com/hastic/hastic-server/pull/124#discussion_r214085643)
detected = self . model . detect ( dataframe , cache )
@ -59,11 +60,13 @@ class PatternDetector(Detector):
' lastDetectionTime ' : last_detection_time
}
def recieve_data ( self , data : pd . DataFrame ) - > Optional [ dict ] :
self . bucket . receive_data ( data )
def recieve_data ( self , data : pd . DataFrame , cache : Optional [ AnalyticUnitCache ] ) - > Optional [ dict ] :
self . bucket . receive_data ( data . dropna ( ) )
if cache != None :
self . window_size = cache [ ' WINDOW_SIZE ' ]
if len ( self . bucket . data ) > = self . window_size :
res = self . detect ( self . bucket . data )
if len ( self . bucket . data ) > = self . window_size and cache != None :
res = self . detect ( self . bucket . data , cache )
excess_data = len ( self . bucket . data ) - self . window_size
self . bucket . drop_data ( excess_data )