Browse Source

Add base class for models state #574 (#575)

pull/1/head
Alexandr Velikiy 6 years ago committed by rozetko
parent
commit
6a690c09f0
  1. 39
      analytics/analytics/models/model.py

39
analytics/analytics/models/model.py

@ -2,7 +2,7 @@ import utils
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from attrdict import AttrDict from attrdict import AttrDict
from typing import Optional from typing import Optional, List
import pandas as pd import pandas as pd
import math import math
import logging import logging
@ -42,6 +42,43 @@ class Segment(AttrDict):
nan_list = utils.find_nan_indexes(self.data) nan_list = utils.find_nan_indexes(self.data)
self.data = utils.nan_to_zero(self.data, nan_list) self.data = utils.nan_to_zero(self.data, nan_list)
class ModelState():
def __init__(
self,
pattern_center: List[int] = [],
pattern_model: List[float] = [],
convolve_max: float = 0,
convolve_min: float = 0,
window_size: int = 0,
conv_del_min: float = 0,
conv_del_max: float = 0
):
self.pattern_center = pattern_center
self.pattern_model = pattern_model
self.convolve_max = convolve_max
self.convolve_min = convolve_min
self.window_size = window_size
self.conv_del_min = conv_del_min
self.conv_del_max = conv_del_max
def to_json(self) -> dict:
return {
'pattern_center': self.pattern_center,
'pattern_model': self.pattern_model,
'convolve_max': self.convolve_max,
'convolve_min': self.convolve_min,
'window_size': self.window_size,
'conv_del_min': self.conv_del_min,
'conv_del_max': self.conv_del_max,
}
@staticmethod
def from_json(json: Optional[dict] = None):
if json is None:
json = {}
return ModelState(**json)
class Model(ABC): class Model(ABC):
HEIGHT_ERROR = 0.1 HEIGHT_ERROR = 0.1

Loading…
Cancel
Save