def getMeasureData(self, measure_ids, company_id, start_date, end_date): self.cursor.execute("use precompute") sql_version = "select max(big_table_version_id) from ks_fact where company_id = %s"%(company_id) self.cursor.execute(sql_version) rows = self.cursor.fetchall() row = rows[0] version = row[0] data = {} for measure_id in measure_ids: ks_fh = filehandler(self.db) measure_data = ks_fh.getMeasureDataByID(measure_id) if len(measure_data["formula"])>0: formula_data = {} formula_tree = parse(measure_data["formula"]) facts = tree_names(formula_tree) formula_data["op"] = formula_tree[0] formula_data["rhs"] = ks_fh.getMeasureID(list(facts)[0]) formula_data["lhs"] = ks_fh.getMeasureID(list(facts)[1]) formula_data["agg_type"] = measure_data["agg_type"] data[measure_id] = self.getRawDataFormula(formula_data,version, measure_id, start_date, end_date) else: data[measure_id] = self.getRawData(version, measure_id, start_date, end_date) return data
def test_tree_names_for_simple_arithmetic(self): tree = formula_parser.parse('(A+B)/(C-D)*X') self.assertEqual( 'ABCDX', ''.join(sorted(list(formula_parser.tree_names(tree)))))
def test_tree_names_for_method_call_with_tuple(self): tree = formula_parser.parse('A.some_method((X, Y, 7))/A') assert 'AXY' == ''.join(sorted(list(formula_parser.tree_names(tree))))
def test_tree_names_for_method_call_with_dict(self): tree = formula_parser.parse('A.some_method({"X":X, "Y":7})/A') assert 'AX' == ''.join(sorted(list(formula_parser.tree_names(tree))))
def test_tree_names_for_method_call_args_and_kwargs(self): tree = formula_parser.parse('A.some_method(X, Y, some_arg=Z)/A') assert 'AXYZ' == ''.join(sorted(list(formula_parser.tree_names(tree))))