Spaces:
Build error
Build error
File size: 963 Bytes
35cdf83 |
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 |
from abc import ABC, abstractmethod
import time
# Abstract interface for developers:
class Stimulator(ABC):
@abstractmethod
def stimulate(self, detection_signal):
"""
Stimulates accordingly to the output of the Detector.
Args:
detection_signal: Object: the output of the Detector.add_datapoints method.
"""
raise NotImplementedError
# Example implementation for sleep spindles:
class SleepSpindleRealTimeStimulator(Stimulator):
def __init__(self):
self.last_detected_ts = time.time()
self.wait_t = 0.4 # 400 ms
def stimulate(self, detection_signal):
for sig in detection_signal:
if sig:
ts = time.time()
if ts - self.last_detected_ts > self.wait_t:
print("stimulation")
else:
print("same spindle")
self.last_detected_ts = ts
|