コード例 #1
0
    def _test_calculator(self):
        self.dframe = self.dataset.dframe()
        row = self.dframe.irow(0)

        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, row)

            calculator = Calculator(self.dataset)

            groups = self.dataset.split_groups(self.group)
            calculator.calculate_column(formula, name, groups)

            self.column_labels_to_slugs = self.dataset.schema.labels_to_slugs

            self._test_calculation_results(name, formula)
コード例 #2
0
ファイル: calculation.py プロジェクト: astrorobotics/bamboo
def calculate_task(calculation, dataset):
    """Background task to run a calculation.

    Set calculation to failed and raise if an exception occurs.

    :param calculation: Calculation to run.
    :param dataset: Dataset to run calculation on.
    """
    # block until other calculations for this dataset are finished
    calculation.restart_if_has_pending(dataset)
    dataset.clear_summary_stats()

    calculator = Calculator(dataset)
    calculator.calculate_column(calculation.formula, calculation.name,
                                calculation.groups_as_list)
    calculation.add_dependencies(dataset, calculator.dependent_columns())

    if calculation.aggregation is not None:
        dataset.reload()
        aggregated_id = dataset.aggregated_datasets_dict[calculation.group]
        calculation.set_aggregation_id(aggregated_id)

    calculation.ready()