當前位置: 首頁>>代碼示例>>Python>>正文


Python calculation.Calculation類代碼示例

本文整理匯總了Python中bamboo.models.calculation.Calculation的典型用法代碼示例。如果您正苦於以下問題:Python Calculation類的具體用法?Python Calculation怎麽用?Python Calculation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Calculation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _test_calculator

    def _test_calculator(self):
        self.dframe = self.dataset.dframe()

        columns = self.dframe.columns.tolist()
        self.start_num_cols = len(columns)
        self.added_num_cols = 0

        column_labels_to_slugs = {
            column_attrs[Dataset.LABEL]: (column_name) for
            (column_name, column_attrs) in self.dataset.schema.items()
        }
        self.label_list, self.slugified_key_list = [
            list(ary) for ary in zip(*column_labels_to_slugs.items())
        ]

        for idx, formula in enumerate(self.calculations):
            name = 'test-%s' % idx

            self.parser.validate_formula(formula)

            calculator = Calculator(self.dataset)

            calculation = Calculation()
            calculation.save(self.dataset, formula, name, self.group)
            calculator.calculate_columns([calculation])

            self.column_labels_to_slugs = self.dataset.schema.labels_to_slugs

            self._test_calculation_results(name, formula)
開發者ID:sparkplug,項目名稱:bamboo,代碼行數:29,代碼來源:test_calculator.py

示例2: test_disallow_delete_dependent_calculation

 def test_disallow_delete_dependent_calculation(self):
     record = self._save_observations_and_calculation()
     self.name = 'test1'
     record = self._save_calculation('test')
     calculation = Calculation.find_one(self.dataset.dataset_id, 'test')
     self.assertEqual(calculation.dependent_calculations, ['test1'])
     calculation = Calculation.find_one(self.dataset.dataset_id, 'test')
     assert_raises(DependencyError, calculation.delete, self.dataset)
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:8,代碼來源:test_calculation.py

示例3: test_removes_dependent_calculations

 def test_removes_dependent_calculations(self):
     record = self._save_observations_and_calculation()
     self.name = 'test1'
     record = self._save_calculation('test')
     calculation = Calculation.find_one(self.dataset.dataset_id, 'test')
     self.assertEqual(calculation.dependent_calculations, ['test1'])
     calculation = Calculation.find_one(self.dataset.dataset_id, 'test1')
     calculation.delete(self.dataset)
     calculation = Calculation.find_one(self.dataset.dataset_id, 'test')
     self.assertEqual(calculation.dependent_calculations, [])
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:10,代碼來源:test_calculation.py

示例4: action

        def action(dataset):
            if json_file:
                calculations = safe_json_loads(json_file.file.read())
                Calculation.create_from_list_or_dict(dataset, calculations)
                success_message = "created calculations from JSON for dataset" ":%s" % dataset_id
            elif formula is None or name is None:
                raise ArgumentError("Must provide both formula and name argume" "nts, or json_file argument")
            else:
                Calculation.create(dataset, formula, name, group)
                success_message = "created calculation: %s for dataset: %s" % (name, dataset_id)

            return {self.SUCCESS: success_message}
開發者ID:j,項目名稱:bamboo,代碼行數:12,代碼來源:calculations.py

示例5: action

        def action(dataset):
            if json_file:
                calculations = safe_json_loads(json_file.file.read())
                Calculation.create_from_list_or_dict(dataset, calculations)
                success_message = 'created calculations from JSON'
            elif formula is None or name is None:
                raise ArgumentError('Must provide both formula and name argume'
                                    'nts, or json_file argument')
            else:
                Calculation.create(dataset, formula, name, group)

            return self._success('created calculation: %s' % name, dataset_id)
開發者ID:4sp1r3,項目名稱:bamboo,代碼行數:12,代碼來源:calculations.py

示例6: _action

        def _action(dataset):
            if json_file:
                calculations = json.loads(json_file.file.read())
                Calculation.create_from_list_or_dict(dataset, calculations)
                success_message = ('created calculations from JSON for dataset'
                                   ':%s' % dataset_id)
            elif formula is None or name is None:
                raise ArgumentError('Must provide both formula and name argume'
                                    'nts, or json_file argument')
            else:
                Calculation.create(dataset, formula, name, group)
                success_message = 'created calculation: %s for dataset: %s' % (
                    name, dataset_id)

            return {self.SUCCESS: success_message}
開發者ID:helioid,項目名稱:bamboo,代碼行數:15,代碼來源:calculations.py

示例7: action

 def action(dataset):
     calculation = Calculation.find_one(dataset.dataset_id, name, group)
     if calculation:
         calculation.delete(dataset)
         message = 'deleted calculation: \'%s\' for dataset: %s' % (
             name, dataset.dataset_id)
         return {self.SUCCESS: message}
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:7,代碼來源:calculations.py

示例8: calculations

    def calculations(self, include_aggs=True, only_aggs=False):
        """Return the calculations for this dataset.

        :param include_aggs: Include aggregations, default True.
        :param only_aggs: Exclude non-aggregations, default False.
        """
        return Calculation.find(self, include_aggs, only_aggs)
開發者ID:zbyufei,項目名稱:bamboo,代碼行數:7,代碼來源:dataset.py

示例9: test_save

 def test_save(self):
     record = self._save_observations_and_calculation()
     self.assertTrue(isinstance(record, dict))
     self.assertTrue(Calculation.FORMULA in record.keys())
     self.assertTrue(Calculation.STATE in record.keys())
     record = Calculation.find(self.dataset)[0].record
     self.assertEqual(record[Calculation.STATE], Calculation.STATE_READY)
     self.assertTrue(Calculation(record).is_ready)
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:8,代碼來源:test_calculation.py

示例10: __wait_for_calculation_ready

    def __wait_for_calculation_ready(self, dataset_id, name):
        while True:
            calculation = Calculation.find_one(dataset_id, name)

            if calculation.is_ready:
                break

            sleep(self.SLEEP_DELAY)
開發者ID:4sp1r3,項目名稱:bamboo,代碼行數:8,代碼來源:test_calculations.py

示例11: action

        def action(dataset):
            calculation = Calculation.find_one(dataset.dataset_id, name, group)

            if calculation:
                calculation.delete(dataset)

                return {self.SUCCESS: 'deleted calculation: \'%s\'' % name,
                        Dataset.ID: dataset.dataset_id}
開發者ID:sparkplug,項目名稱:bamboo,代碼行數:8,代碼來源:calculations.py

示例12: test_fail_then_create

    def test_fail_then_create(self):
        response = json.loads(self.__post_formula())
        self.__verify_create(response)

        # Overwrite as failed
        calc = Calculation.find_one(self.dataset_id, self.name)
        calc.update({calc.STATE: calc.STATE_FAILED})

        # Test we can still add a calculation
        self.name = 'test2'
        response = json.loads(self.__post_formula())
        self.__verify_create(response)
開發者ID:4sp1r3,項目名稱:bamboo,代碼行數:12,代碼來源:test_calculations.py

示例13: test_fail_in_background

    def test_fail_in_background(self):
        dataset_id = self._post_file('wp_data.csv')
        group = 'wp_id'
        self._wait_for_dataset_state(dataset_id)

        self.controller.create(dataset_id,
                               'newest(submit_date,functional)',
                               'wp_functional',
                               group=group)
        self.controller.create(dataset_id,
                               'max(submit_date)',
                               'latest_submit_date',
                               group=group)

        # Update the name to cause has pending to be true and infinite retries.
        # It will fail after 10 retries.
        calc = Calculation.find_one(dataset_id, 'latest_submit_date', group)
        calc.update({calc.NAME: 'another_name'})

        update = {
            'wp_id': 'D',
            'functional': 'yes',
        }
        self.__post_update(dataset_id, update)
        update = {
            'submit_date': '2013-01-08',
            'wp_id': 'A',
            'functional': 'no',
        }
        self.__post_update(dataset_id, update)

        while True:
            dataset = Dataset.find_one(dataset_id)
            calcs_not_pending = [
                c.state != c.STATE_PENDING for c in dataset.calculations()]

            if not len(dataset.pending_updates) and all(calcs_not_pending):
                break

            sleep(self.SLEEP_DELAY)

        for c in dataset.calculations():
            self.assertEqual(c.STATE_FAILED, c.state)
            self.assertTrue('Traceback' in c.error_message)
開發者ID:4sp1r3,項目名稱:bamboo,代碼行數:44,代碼來源:test_calculations.py

示例14: test_save_set_aggregation_id

 def test_save_set_aggregation_id(self):
     record = self._save_observations_and_calculation('max(amount)')
     agg_id = self.dataset.aggregated_datasets_dict['']
     calculation = Calculation.find(self.dataset)[0]
     self.assertEqual(agg_id, calculation.aggregation_id)
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:5,代碼來源:test_calculation.py

示例15: test_save_set_aggregation

 def test_save_set_aggregation(self):
     record = self._save_observations_and_calculation('max(amount)')
     calculation = Calculation.find(self.dataset)[0]
     self.assertEqual('max', calculation.aggregation)
開發者ID:astrorobotics,項目名稱:bamboo,代碼行數:4,代碼來源:test_calculation.py


注:本文中的bamboo.models.calculation.Calculation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。