35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import numpy as np
|
|
|
|
|
|
def get_ranges(labels: np.ndarray) -> list[list[int, int, int]]:
|
|
"""Преобразование сырых лейблов временного ряда в отрезки для визуализации
|
|
|
|
Args:
|
|
labels (np.ndarray): лейблы
|
|
|
|
Returns:
|
|
list[list[int, int, int]]: список отрезков для визуализации, каждый отрезок определен как
|
|
тройка "начало", "конец", "тип действия"
|
|
"""
|
|
|
|
actions = []
|
|
__temp_action = [0]
|
|
__prev_action = labels[0]
|
|
idx = 1
|
|
|
|
while True:
|
|
if idx + 1 > len(labels):
|
|
__temp_action.extend([idx, __prev_action])
|
|
actions.append(__temp_action)
|
|
break
|
|
|
|
if labels[idx] != __prev_action:
|
|
__temp_action.extend([idx - 1, __prev_action])
|
|
actions.append(__temp_action)
|
|
__temp_action = [idx]
|
|
__prev_action = labels[idx]
|
|
|
|
idx += 1
|
|
|
|
return actions
|