Ejemplo n.º 1
0
    def execute(self, timeSeries):
        """Creates a new TimeSeries containing the SMA values for the predefined windowsize.

        :param TimeSeries timeSeries:    The TimeSeries used to calculate the simple moving average values.

        :return:    TimeSeries object containing the smooth moving average.
        :rtype:     TimeSeries

        :raise:   Raises a :py:exc:`ValueError` wif the defined windowsize is larger than the number of elements
            in timeSeries

        :note:    This implementation aims to support independent for loop execution.
        """
        windowsize    = self._parameters["windowsize"]

        if len (timeSeries) < windowsize:
            raise ValueError("windowsize is larger than the number of elements in timeSeries.")

        tsLength      = len(timeSeries)
        nbrOfLoopRuns = tsLength - windowsize + 1

        res = TimeSeries()
        for idx in xrange(nbrOfLoopRuns):
            end = idx + windowsize
            data = timeSeries[idx:end]

            timestamp = data[windowsize//2][0]
            value     = sum([i[1] for i in data])/windowsize

            res.add_entry(timestamp, value)

        res.sort_timeseries()
        return res
Ejemplo n.º 2
0
    def timeseries_sort_test(self):
        """Tests the sort_timeseries function."""
        data = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        ts   = TimeSeries.from_twodim_list(data)
        
        ts.sort_timeseries()
        ts.sort_timeseries(False)

        ts = TimeSeries(isSorted=True)
        ts.sort_timeseries()
Ejemplo n.º 3
0
    def timeseries_sort_test(self):
        """Tests the sort_timeseries function."""
        data = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        ts   = TimeSeries.from_twodim_list(data)

        ts.sort_timeseries()
        ts.sort_timeseries(False)

        ts = TimeSeries(isSorted=True)
        ts.sort_timeseries()