Esempio n. 1
0
    def __init__(self,
                 unitclass,
                 points=None,
                 spacing=None,
                 ts0=None,
                 interpolation="piecewise_linear",
                 buffer_size=None,
                 use_point_ts=True,
                 stabilization_length=5,
                 stabilization_pc='1pc'):
        super(SignalWave, self).__init__(unitclass)

        self._stabilization_length = stabilization_length
        if isinstance(stabilization_pc, Percentage):
            self._stabilization_pc = stabilization_pc
        else:
            self._stabilization_pc = Percentage(stabilization_pc)
        self._buffer_size = buffer_size
        self._use_point_ts = use_point_ts

        if spacing is not None:
            if isinstance(spacing, TimeSpan):
                self._spacing = spacing.timedelta
            elif isinstance(spacing, TimeDelta):
                self._spacing = spacing
            else:
                raise TypeError("spacing must be an instance of TimeDelta or "
                                "TimeSpan. Got " + repr(spacing))

        if ts0 is not None:
            if not isinstance(ts0, TimeStamp):
                raise TypeError("ts0 must be an instance of TimeStamp")
            self._ts0 = ts0
        else:
            self._ts0 = timestamp_factory.now()

        if points and isinstance(points, deque):
            if isinstance(points[0], tuple):
                self._points = points
            else:
                if not self._use_point_ts:
                    span_spacing = self._spacing.timespan
                    self._points = deque(
                        [(ts0 + (span_spacing * idx).timedelta, point)
                         for idx, point in enumerate(points)],
                        maxlen=buffer_size)
                else:
                    self._points = deque([(point.timestamp, point)
                                          for point in points],
                                         maxlen=buffer_size)
        else:
            self._points = deque(maxlen=buffer_size)

        self._interpolation = interpolation
Esempio n. 2
0
    def __init__(self, unitclass, value, ts=None):
        super(SignalPoint, self).__init__(unitclass)

        if not isinstance(value, unitclass):
            self.value = unitclass(value)
        else:
            self.value = value

        if ts is None:
            self.timestamp = timestamp_factory.now()
        else:
            self.timestamp = ts

        self._error_bar = None
Esempio n. 3
0
    def __init__(self, unitclass, value, ts=None):
        super(SignalPoint, self).__init__(unitclass)

        if not isinstance(value, unitclass):
            self.value = unitclass(value)
        else:
            self.value = value

        if ts is None:
            self.timestamp = timestamp_factory.now()
        else:
            self.timestamp = ts

        self._error_bar = None
Esempio n. 4
0
    def __init__(self, unitclass, points=None, spacing=None, ts0=None,
                 interpolation="piecewise_linear", buffer_size=None,
                 use_point_ts=True, stabilization_length=5,
                 stabilization_pc='1pc'):
        super(SignalWave, self).__init__(unitclass)

        self._stabilization_length = stabilization_length
        if isinstance(stabilization_pc, Percentage):
            self._stabilization_pc = stabilization_pc
        else:
            self._stabilization_pc = Percentage(stabilization_pc)
        self._buffer_size = buffer_size
        self._use_point_ts = use_point_ts

        if spacing is not None:
            if isinstance(spacing, TimeSpan):
                self._spacing = spacing.timedelta
            elif isinstance(spacing, TimeDelta):
                self._spacing = spacing
            else:
                raise TypeError("spacing must be an instance of TimeDelta or "
                                "TimeSpan. Got " + repr(spacing))

        if ts0 is not None:
            if not isinstance(ts0, TimeStamp):
                raise TypeError("ts0 must be an instance of TimeStamp")
            self._ts0 = ts0
        else:
            self._ts0 = timestamp_factory.now()

        if points and isinstance(points, deque):
            if isinstance(points[0], tuple):
                self._points = points
            else:
                if not self._use_point_ts:
                    span_spacing = self._spacing.timespan
                    self._points = deque(
                        [(ts0 + (span_spacing * idx).timedelta, point)
                         for idx, point in enumerate(points)],
                        maxlen=buffer_size
                    )
                else:
                    self._points = deque([(point.timestamp, point)
                                          for point in points],
                                         maxlen=buffer_size)
        else:
            self._points = deque(maxlen=buffer_size)

        self._interpolation = interpolation
Esempio n. 5
0
 def add_point(self, point, ts=None):
     if point.unitclass != self.unitclass:
         raise TypeError
     if ts is None:
         if self._use_point_ts is False:
             if self.last_timestamp is None:
                 self._ts0 = timestamp_factory.now()
             ts = self.last_timestamp + self._spacing
         elif point.timestamp is not None:
             if self.last_timestamp is None:
                 self._ts0 = point.timestamp
             ts = point.timestamp
     if ts is None:
         raise ValueError
     self._points.append((ts, point))
Esempio n. 6
0
 def add_point(self, point, ts=None):
     if point.unitclass != self.unitclass:
         raise TypeError
     if ts is None:
         if self._use_point_ts is False:
             if self.last_timestamp is None:
                 self._ts0 = timestamp_factory.now()
             ts = self.last_timestamp + self._spacing
         elif point.timestamp is not None:
             if self.last_timestamp is None:
                 self._ts0 = point.timestamp
             ts = point.timestamp
     if ts is None:
         raise ValueError
     self._points.append((ts, point))
Esempio n. 7
0
    def reset_buffer(self, unitclass=DummyUnit):
        """
        Resets the point buffer to a new
        :class:`tendril.utils.types.signalbase.SignalWave` with the unitclass
        as specified by the parameter. Any data presently within it will be
        lost.

        :param unitclass: Class of Unit that the Wave points are composed of.

        """
        # logger.debug("Resetting buffer to type : " + repr(unitclass))
        self.point_buffer = SignalWave(unitclass,
                                       spacing=TimeDelta(microseconds=100000),
                                       ts0=timestamp_factory.now(),
                                       buffer_size=1000,
                                       use_point_ts=False)
Esempio n. 8
0
    def reset_buffer(self, unitclass=DummyUnit):
        """
        Resets the point buffer to a new
        :class:`tendril.utils.types.signalbase.SignalWave` with the unitclass
        as specified by the parameter. Any data presently within it will be
        lost.

        :param unitclass: Class of Unit that the Wave points are composed of.

        """
        # logger.debug("Resetting buffer to type : " + repr(unitclass))
        self.point_buffer = SignalWave(unitclass,
                                       spacing=TimeDelta(microseconds=100000),
                                       ts0=timestamp_factory.now(),
                                       buffer_size=1000,
                                       use_point_ts=False)