Ejemplo n.º 1
0
    def test_robustness_no_ts(self):
        """
        No time series is provided
        Check that the result is empty
        """

        # Prepare inputs
        ts_list = []

        # Prepare expected output
        expected_results = {}

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=2000,
                                     timestamp_position="BEG",
                                     aggregation_method="AVG",
                                     nb_points_by_chunk=4,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 2
0
    def test_empty_chunks(self):
        """
        Compute the downsampling on multiple time series having many points not evenly distributed
        Check the downsampling works with empty chunks
        """

        # Prepare inputs
        ts_list = [gen_ts(3)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12, 5.5], [1e12 + 2000, 7.0],
                                  [1e12 + 100000, 7.0], [1e12 + 102000, 7.5]]
        }

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=2000,
                                     timestamp_position="BEG",
                                     aggregation_method="AVG",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 3
0
    def test_single_point(self):
        """
        Compute the downsampling on time series having 1 point
        Check the new time series is the same as the original one
        """
        # Prepare inputs
        ts_list = [gen_ts(4)]

        # Prepare expected output
        expected_results = {ts_list[0]['tsuid']: [[1e12, 42.0]]}

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=2000,
                                     timestamp_position="BEG",
                                     aggregation_method="MAX",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 4
0
    def test_alignment_end(self):
        """
        Compute the downsampling on a single time series using END alignment
        Check the time series is processed and result matches the alignment method
        """

        # Prepare inputs
        ts_list = [gen_ts(1)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12 + 6000, 8.0], [1e12 + 12000, 42.0],
                                  [1e12 + 18000, 8.0]]
        }
        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=6000,
                                     timestamp_position="END",
                                     aggregation_method="MAX",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 5
0
    def test_aggregation_med(self):
        """
        Compute the downsampling on a single time series using MED aggregation (median)
        To compute the median, sort (ascending) the values in the desired period and take the middle point
        (or apply a linear interpolation in case of even values)
        Check the time series is processed and result matches the aggregation method
        """

        # Prepare inputs
        ts_list = [gen_ts(1)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12, 5.5], [1e12 + 10000, 8.0]]
        }

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=10000,
                                     timestamp_position="BEG",
                                     aggregation_method="MED",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)
        finally:

            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 6
0
    def test_aggregation_min(self):
        """
        Compute the downsampling on a single time series using MIN aggregation
        Check the time series is processed and result matches the aggregation method
        """

        # Prepare inputs
        ts_list = [gen_ts(1)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12, 5.0], [1e12 + 2000, 6.0],
                                  [1e12 + 4000, -15.0], [1e12 + 6000, 3.0],
                                  [1e12 + 8000, 2.0], [1e12 + 10000, 8.0],
                                  [1e12 + 12000, 8.0]]
        }

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=2000,
                                     timestamp_position="BEG",
                                     aggregation_method="MIN",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)
        finally:

            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 7
0
    def test_not_aligned(self):
        """
        Compute the downsampling on a single time series with a resampling period not a multiple of the original period
        Check the time series is processed
        """

        # Prepare inputs
        ts_list = [gen_ts(1)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12, 6.0], [1e12 + 1400, 6.0],
                                  [1e12 + 2800, 8.0], [1e12 + 4200, 2.0],
                                  [1e12 + 5600, 6.0], [1e12 + 7000, 3.0],
                                  [1e12 + 8400, 42.0], [1e12 + 9800, 8.0],
                                  [1e12 + 11200, 8.0], [1e12 + 12600, 8.0]]
        }

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=1400,
                                     timestamp_position="BEG",
                                     aggregation_method="MAX",
                                     nb_points_by_chunk=4,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)
Ejemplo n.º 8
0
    def test_multiple_ts(self):
        """
        Compute the downsampling on multiple time series without any constraint
        Check all time series are processed
        """

        # Prepare inputs
        ts_list = [gen_ts(1), gen_ts(2)]

        # Prepare expected output
        expected_results = {
            ts_list[0]['tsuid']: [[1e12, 5.5], [1e12 + 2000, 7.0],
                                  [1e12 + 4000, -6.5], [1e12 + 6000, 4.5],
                                  [1e12 + 8000, 22.0], [1e12 + 10000, 8.0],
                                  [1e12 + 12000, 8.0]],
            ts_list[1]['tsuid']: [[1e12, 5.5], [1e12 + 2000, 7.0],
                                  [1e12 + 4000, -6.5], [1e12 + 6000, 4.5],
                                  [1e12 + 8000, 3.5], [1e12 + 12000, 10.0]]
        }

        result = None
        try:
            # Call algorithm
            result = downsampling_ts(ts_list=ts_list,
                                     resampling_period=2000,
                                     timestamp_position="BEG",
                                     aggregation_method="AVG",
                                     nb_points_by_chunk=50000,
                                     generate_metadata=True)

            # Check the results
            self._check_results(ts_list, result, expected_results)

        finally:
            # Cleanup
            self._cleanup_ts(result)