-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocessing.py
More file actions
42 lines (38 loc) · 1.35 KB
/
processing.py
File metadata and controls
42 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
def tuple_to_sequence(lst, width, shift):
"""Convert [(strt, stp, val)] to sequence of val.
Args:
lst (list): start and stop times of each val.
width (numeric): window width in ms.
shift (numeric): window shift in ms.
Returns:
list: sequence of vals corresponding to the tuples in lst.
"""
lst = sorted(lst)
seq = []
last_frame = (lst[-1][1] - width) / shift
frame_id = 0
ind = 0
try:
start_time = time.time()
while (frame_id * shift) < (last_frame * shift) and ind < len(lst):
if lst[ind][1] >= (frame_id * shift) >= lst[ind][0]:
while (frame_id * shift) < lst[ind][1]:
seq.append(lst[ind][2])
frame_id += 1
ind += 1
else:
while (frame_id * shift) < lst[ind][0]:
seq.append(None)
frame_id += 1
if (frame_id * shift) >= (last_frame * shift):
return seq
elapsed_time = time.time() - start_time
if elapsed_time > 10:
raise TimeoutError("Generating the sequence took too long.")
except TimeoutError as e:
# print(f"Timeout Error: {e}")
seq = [None] * len(lst)
pass
#print("Sequence", seq)
return seq