|
|
@ -36,16 +36,6 @@ def exponential_smoothing(series: pd.Series, alpha: float, last_smoothed_value: |
|
|
|
result.append(alpha * series[n] + (1 - alpha) * result[n - 1]) |
|
|
|
result.append(alpha * series[n] + (1 - alpha) * result[n - 1]) |
|
|
|
return pd.Series(result, index = series.index) |
|
|
|
return pd.Series(result, index = series.index) |
|
|
|
|
|
|
|
|
|
|
|
def segments_box(segments): |
|
|
|
|
|
|
|
max_time = 0 |
|
|
|
|
|
|
|
min_time = float("inf") |
|
|
|
|
|
|
|
for segment in segments: |
|
|
|
|
|
|
|
min_time = min(min_time, segment['from']) |
|
|
|
|
|
|
|
max_time = max(max_time, segment['to']) |
|
|
|
|
|
|
|
min_time = pd.to_datetime(min_time, unit='ms') |
|
|
|
|
|
|
|
max_time = pd.to_datetime(max_time, unit='ms') |
|
|
|
|
|
|
|
return min_time, max_time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_pattern(data: pd.Series, height: float, length: int, pattern_type: str) -> list: |
|
|
|
def find_pattern(data: pd.Series, height: float, length: int, pattern_type: str) -> list: |
|
|
|
pattern_list = [] |
|
|
|
pattern_list = [] |
|
|
|
right_bound = len(data) - length - 1 |
|
|
|
right_bound = len(data) - length - 1 |
|
|
@ -59,7 +49,7 @@ def find_pattern(data: pd.Series, height: float, length: int, pattern_type: str) |
|
|
|
pattern_list.append(i) |
|
|
|
pattern_list.append(i) |
|
|
|
return pattern_list |
|
|
|
return pattern_list |
|
|
|
|
|
|
|
|
|
|
|
def find_jump(data, height, lenght) -> List[int]: |
|
|
|
def find_jump(data, height: float, lenght: int) -> List[int]: |
|
|
|
''' |
|
|
|
''' |
|
|
|
Find jump indexes |
|
|
|
Find jump indexes |
|
|
|
''' |
|
|
|
''' |
|
|
@ -70,7 +60,7 @@ def find_jump(data, height, lenght) -> List[int]: |
|
|
|
j_list.append(i) |
|
|
|
j_list.append(i) |
|
|
|
return(j_list) |
|
|
|
return(j_list) |
|
|
|
|
|
|
|
|
|
|
|
def find_drop(data, height, length) -> List[int]: |
|
|
|
def find_drop(data, height: float, length: int) -> List[int]: |
|
|
|
''' |
|
|
|
''' |
|
|
|
Find drop indexes |
|
|
|
Find drop indexes |
|
|
|
''' |
|
|
|
''' |
|
|
@ -81,7 +71,7 @@ def find_drop(data, height, length) -> List[int]: |
|
|
|
d_list.append(i) |
|
|
|
d_list.append(i) |
|
|
|
return(d_list) |
|
|
|
return(d_list) |
|
|
|
|
|
|
|
|
|
|
|
def timestamp_to_index(dataframe, timestamp): |
|
|
|
def timestamp_to_index(dataframe: pd.DataFrame, timestamp: int): |
|
|
|
data = dataframe['timestamp'] |
|
|
|
data = dataframe['timestamp'] |
|
|
|
idx, = np.where(data >= timestamp) |
|
|
|
idx, = np.where(data >= timestamp) |
|
|
|
if len(idx) > 0: |
|
|
|
if len(idx) > 0: |
|
|
@ -100,16 +90,16 @@ def find_peaks(data: Generator[float, None, None], size: int) -> Generator[float |
|
|
|
window.append(v) |
|
|
|
window.append(v) |
|
|
|
window.popleft() |
|
|
|
window.popleft() |
|
|
|
|
|
|
|
|
|
|
|
def ar_mean(numbers): |
|
|
|
def ar_mean(numbers: List[float]): |
|
|
|
return float(sum(numbers)) / max(len(numbers), 1) |
|
|
|
return float(sum(numbers)) / max(len(numbers), 1) |
|
|
|
|
|
|
|
|
|
|
|
def get_av_model(patterns_list): |
|
|
|
def get_av_model(patterns_list: list): |
|
|
|
if not patterns_list: return [] |
|
|
|
if not patterns_list: return [] |
|
|
|
patterns_list = get_same_length(patterns_list) |
|
|
|
patterns_list = get_same_length(patterns_list) |
|
|
|
value_list = list(map(list, zip(*patterns_list))) |
|
|
|
value_list = list(map(list, zip(*patterns_list))) |
|
|
|
return list(map(ar_mean, value_list)) |
|
|
|
return list(map(ar_mean, value_list)) |
|
|
|
|
|
|
|
|
|
|
|
def get_same_length(patterns_list): |
|
|
|
def get_same_length(patterns_list: list): |
|
|
|
for index in range(len(patterns_list)): |
|
|
|
for index in range(len(patterns_list)): |
|
|
|
if type(patterns_list[index]) == pd.Series: |
|
|
|
if type(patterns_list[index]) == pd.Series: |
|
|
|
patterns_list[index] = patterns_list[index].tolist() |
|
|
|
patterns_list[index] = patterns_list[index].tolist() |
|
|
@ -223,7 +213,7 @@ def find_confidence(segment: pd.Series) -> (float, float): |
|
|
|
else: |
|
|
|
else: |
|
|
|
return (0, 0) |
|
|
|
return (0, 0) |
|
|
|
|
|
|
|
|
|
|
|
def find_width(pattern: pd.Series, selector) -> int: |
|
|
|
def find_width(pattern: pd.Series, selector: bool) -> int: |
|
|
|
pattern = pattern.values |
|
|
|
pattern = pattern.values |
|
|
|
center = utils.find_extremum_index(pattern, selector) |
|
|
|
center = utils.find_extremum_index(pattern, selector) |
|
|
|
pattern_left = pattern[:center] |
|
|
|
pattern_left = pattern[:center] |
|
|
@ -458,6 +448,6 @@ def cut_dataframe(data: pd.DataFrame) -> pd.DataFrame: |
|
|
|
data['value'] = data['value'] - data_min |
|
|
|
data['value'] = data['value'] - data_min |
|
|
|
return data |
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
def get_min_max(array, default): |
|
|
|
def get_min_max(array: list, default): |
|
|
|
return float(min(array, default=default)), float(max(array, default=default)) |
|
|
|
return float(min(array, default=default)), float(max(array, default=default)) |
|
|
|
|
|
|
|
|
|
|
|