def measure(self): calc_object = CalculationFactory().create_calc_object( cal_type=self.calculation_type if self.calculation_type else CalcType.SUM_CALCULATION.value, ts=self.data) cal_result = calc_object.calculate(metric=self.measure_type) return {self.type_name: cal_result}
def test_count_calculation(): print( "================== Testing test_mean_calculation() =================") cf = CalculationFactory() data = pd.DataFrame(data={"Sales": [1, 2, 3]}, index=["Jan 2019", "Feb 2019", "Mar 2019"]) mean_calc = cf.create_calc_object("count_calculation") mean_calc.assign(data) assert mean_calc.calculate(metric="Sales") == 3
def test_complex_count_calculation(): print( "================== Testing test_complex_count_calculation() =================" ) cf = CalculationFactory() data = pd.DataFrame(data={ "Sales": [1, 2, 3], "Prod": ["A", "B", "B"] }, index=["Jan 2019", "Feb 2019", "Mar 2019"]) mean_calc = cf.create_calc_object("complex_count_calculation") mean_calc.assign(data) df = mean_calc.calculate(metric="Sales", other_key="Prod") assert df is not None assert df.loc["A"]["Sales"] == 1 assert df.loc["B"]["Sales"] == 2
def test_calculationfactory(): print( "================== Testing test_calculationfactory() =================" ) cf = CalculationFactory() try: cf.create_calc_object(None, None) assert False except Exception: assert True try: cf.create_calc_object(None) assert False except Exception: assert True try: sum_calculation = cf.create_calc_object("sum_calculation") assert False except Exception: assert True