コード例 #1
0
    def test_nb_points_cut_bigger_than_ts_length(self):
        """
        Check behavior when bad arguments provided

        case: DEGRADED
              number of points bigger than time series length
        """

        start_cut = int(1e12 + 3500)
        nb_points_cut = 10
        result_tsuids = []

        expected_result = np.array([
            [1e12 + 6000, 25.89],
            [1e12 + 8000, 3.0],
            [1e12 + 9000, 21.2],
            [1e12 + 40000, 18],
            [1e12 + 43000, 15.0],
            [1e12 + 43500, 12.0],
            [1e12 + 44000, 7.5],
            [1e12 + 52000, 35.0]])
        try:
            # Call algorithm
            result = dataset_cut(ds_name=self.ds_name, start=start_cut, nb_points=nb_points_cut, use_spark=True)
            result_tsuids = [x['tsuid'] for x in result]
            self.assertEqual(len(result_tsuids), 5)
            for tsuid_res in result_tsuids:
                self.array_equality(expected_data=expected_result, tsuid_result=tsuid_res)
        except Exception:
            self.fail("Unexpected error or assert failure in tests")
        finally:
            # Clean up
            if result_tsuids:
                for tsuid_res in result_tsuids:
                    IkatsApi.ts.delete(tsuid=tsuid_res, no_exception=True)
コード例 #2
0
    def test_degraded_bad_arguments_without_exception(self):
        """
        Check behavior when bad arguments provided

        case: DEGRADED
        """

        # CASE: dataset does not exist
        start_cut = int(1e12 + 44000)
        end_cut = int(1e12 + 45000)
        result = dataset_cut(ds_name="unknown", start=start_cut, end=end_cut, use_spark=True)
        self.assertEqual(len(result), 0)

        # CASE: empty dataset
        start_cut = int(1e12 + 44000)
        end_cut = int(1e12 + 45000)
        IkatsApi.ds.create("empty_ds", "", [])
        try:
            result = dataset_cut(ds_name="empty_ds", start=start_cut, end=end_cut, use_spark=True)
            self.assertEqual(len(result), 0)
        finally:
            IkatsApi.ds.delete(ds_name="empty_ds", deep=False)
コード例 #3
0
    def boundary_test_with_chunks_1(self):
        """
        Compute the cut on a single time series
        between start and end date with several chunks of data
        Check the time series is cut as expected

        case: BOUNDARY
            start date not aligned with point date (1ms less than a real point)
            end date not aligned with point date (1ms more than a real point)

        """

        start_cut = int(1e12 + 2999)
        end_cut = int(1e12 + 44001)
        nb_points_cut = None
        ds_name = "DS_Test_Cut_Dataset_3"
        result_tsuids = []

        expected_result = np.array([
            [1e12 + 3000, 8.0],
            [1e12 + 6000, 25.89],
            [1e12 + 8000, 3.0],
            [1e12 + 9000, 21.2],
            [1e12 + 40000, 18],
            [1e12 + 43000, 15.0],
            [1e12 + 43500, 12.0],
            [1e12 + 44000, 7.5]
        ])

        IkatsApi.ds.create(ds_name=ds_name, description="", tsuid_list=[self.tsuid1])

        try:
            # Call algorithm
            result = dataset_cut(ds_name=ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut,
                                 nb_points_by_chunk=2, use_spark=True)
            result_tsuids = [x['tsuid'] for x in result]
            self.assertEqual(len(result_tsuids), 1)
            for tsuid_res in result_tsuids:
                self.array_equality(expected_data=expected_result, tsuid_result=tsuid_res)
        except Exception:
            self.fail("Unexpected error or assert failure in tests")
        finally:
            # Clean up
            IkatsApi.ds.delete(ds_name=ds_name, deep=False)
            if result_tsuids:
                for tsuid_res in result_tsuids:
                    IkatsApi.ts.delete(tsuid=tsuid_res, no_exception=True)
コード例 #4
0
    def test_nominal_end_date(self):
        """
        Compute the cut on a single time series
        between start and end date
        Check the time series is cut as expected

        case: NOMINAL
        """

        start_cut = int(1e12 + 3000)
        end_cut = int(1e12 + 44000)
        nb_points_cut = None
        ds_name = "DS_Test_Cut_Dataset_2"
        result_tsuids = []

        expected_result = np.array([
            [1e12 + 3000, 8.0],
            [1e12 + 6000, 25.89],
            [1e12 + 8000, 3.0],
            [1e12 + 9000, 21.2],
            [1e12 + 40000, 18],
            [1e12 + 43000, 15.0],
            [1e12 + 43500, 12.0],
            [1e12 + 44000, 7.5]
        ])

        IkatsApi.ds.create(ds_name=ds_name, description="", tsuid_list=[self.tsuid1])

        try:
            # Call algorithm
            result = dataset_cut(ds_name=ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)
            result_tsuids = [x['tsuid'] for x in result]
            self.assertEqual(len(result_tsuids), 1)
            for tsuid_res in result_tsuids:
                self.array_equality(expected_data=expected_result, tsuid_result=tsuid_res)
        except Exception:
            self.fail("Unexpected error or assert failure in tests")
        finally:
            # Clean up
            IkatsApi.ds.delete(ds_name=ds_name, deep=False)
            if result_tsuids:
                for tsuid_res in result_tsuids:
                    IkatsApi.ts.delete(tsuid=tsuid_res, no_exception=True)
コード例 #5
0
    def test_degraded_no_points_in_range(self):
        """
        Check behavior when bad arguments provided

        case: DEGRADED
        """

        # CASE: 1 of all TS has no points in range
        start_cut = int(1e12 + 3000)
        end_cut = int(1e12 + 9000)
        result_tsuids = []

        expected_result = np.array([
            [1e12 + 3000, 8.0],
            [1e12 + 6000, 25.89],
            [1e12 + 8000, 3.0],
            [1e12 + 9000, 21.2]
        ])
        tsuid, fid = _init_nominal(6, 10000)
        ds_name = "ds_test_cut_dataset"
        try:
            IkatsApi.ds.delete(ds_name=ds_name, deep=False)
        finally:
            IkatsApi.ds.create(ds_name, "", [tsuid, self.tsuid1, self.tsuid2])
        try:
            # Call algorithm
            result = dataset_cut(ds_name=ds_name, start=start_cut, end=end_cut, use_spark=True)
            result_tsuids = [x['tsuid'] for x in result]
            self.assertEqual(len(result_tsuids), 2)
            for tsuid_res in result_tsuids:
                self.array_equality(expected_data=expected_result, tsuid_result=tsuid_res)
        except Exception:
            self.fail("Unexpected error or assert failure in tests")
        finally:
            # Clean up
            IkatsApi.ts.delete(tsuid, no_exception=True)
            IkatsApi.ds.delete(ds_name=ds_name, deep=False)
            if result_tsuids:
                for tsuid_res in result_tsuids:
                    IkatsApi.ts.delete(tsuid=tsuid_res, no_exception=True)
コード例 #6
0
    def test_dataset_multi_ts(self):
        """
        Compute the cut on a multi time series dataset
        between start and end date with several chunks of data
        Check the time series are cut as expected

        case: NOMINAL
        """
        start_cut = int(1e12 + 3000)
        end_cut = int(1e12 + 44000)
        nb_points_cut = None
        result_tsuids = []

        expected_result = np.array([
            [1e12 + 3000, 8.0],
            [1e12 + 6000, 25.89],
            [1e12 + 8000, 3.0],
            [1e12 + 9000, 21.2],
            [1e12 + 40000, 18],
            [1e12 + 43000, 15.0],
            [1e12 + 43500, 12.0],
            [1e12 + 44000, 7.5]
        ])

        try:
            # Call algorithm
            result = dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut,
                                 nb_points_by_chunk=7, use_spark=True)
            result_tsuids = [x['tsuid'] for x in result]
            self.assertEqual(len(result_tsuids), 5)
            for tsuid_res in result_tsuids:
                self.array_equality(expected_data=expected_result, tsuid_result=tsuid_res)
        except Exception:
            self.fail("Unexpected error or assert failure in tests")
        finally:
            # Clean up
            if result_tsuids:
                for tsuid_res in result_tsuids:
                    IkatsApi.ts.delete(tsuid=tsuid_res, no_exception=True)
コード例 #7
0
    def test_degraded_bad_arguments_exception_raised(self):
        """
        Check behavior when bad arguments provided

        case: DEGRADED
        """

        with self.assertRaises(ValueError):
            # CASE: no dataset name provided
            start_cut = int(1e12 + 3000)
            end_cut = int(1e12 + 44000)
            nb_points_cut = None
            # noinspection PyTypeChecker
            dataset_cut(ds_name=None, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: no start date provided
            start_cut = None
            end_cut = int(1e12 + 44000)
            nb_points_cut = None
            # noinspection PyTypeChecker
            dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: no end date nor nb points provided
            start_cut = int(1e12 + 3000)
            end_cut = None
            nb_points_cut = None
            dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: end date and number of points provided together
            start_cut = int(1e12 + 3000)
            end_cut = int(1e12 + 44000)
            nb_points_cut = 18
            dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: end date and start date are equal
            start_cut = int(1e12 + 44000)
            end_cut = int(1e12 + 44000)
            nb_points_cut = None
            dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: end date lesser than start date
            start_cut = int(1e12 + 44000)
            end_cut = int(1e12 + 40000)
            nb_points_cut = None
            dataset_cut(ds_name=self.ds_name, start=start_cut, end=end_cut, nb_points=nb_points_cut, use_spark=True)

        with self.assertRaises(ValueError):
            # CASE: number of points <0
            start_cut = int(1e12 + 44000)
            nb_points = -5
            result = dataset_cut(ds_name="unknown", start=start_cut, nb_points=nb_points, use_spark=True)
            self.assertEqual(len(result), 0)