Exemplo n.º 1
0
    def testPerformAggregationCustom(self):

        cubeSetName = "test-" + str(uuid.uuid4())
        csvFilePath = cubeSetName + ".csv"
        try:
            shutil.copyfile("cubify/tests/testdata.csv", cubeSetName + ".csv")
        except Exception:
            shutil.copyfile("./testdata.csv", cubeSetName + ".csv")
        binningFileName = "cubify/tests/test_binnings.json"
        if os.path.isfile(binningFileName) == False:
            binningFileName = "./test_binnings.json"
        with open(binningFileName) as binnings_file:
            binnings = json.load(binnings_file)
        aggFileName = "cubify/tests/test_agg.json"
        if os.path.isfile(aggFileName) == False:
            aggFileName = "./test_agg.json"
        with open(aggFileName) as agg_file:
            aggs = json.load(agg_file)

        cs = CubeSetService("testdb")
        cubeSet = cs.createCubeSet("testOwner", cubeSetName, csvFilePath, binnings, None)
        cs.performAggregationCustom(cubeSet, aggs)

        agg = aggs[0]
        aggCubeRows = cs.getAggregatedCubeRows(cubeSet, agg["name"])
        self.assertTrue(aggCubeRows.count(False) == 4)
        for aggCubeRow in aggCubeRows:
            self.assertTrue(len(aggCubeRow["dimensions"]) == 2)
            print aggCubeRow

        print "---------"

        agg = aggs[1]
        aggCubeRows = cs.getAggregatedCubeRows(cubeSet, agg["name"])
        self.assertTrue(aggCubeRows.count(False) == 2)
        for aggCubeRow in aggCubeRows:
            self.assertTrue(len(aggCubeRow["dimensions"]) == 1)
            print aggCubeRow

        print "---------"

        agg = aggs[2]
        aggCubeRows = cs.getAggregatedCubeRows(cubeSet, agg["name"])
        self.assertTrue(aggCubeRows.count(False) == 2)
        for aggCubeRow in aggCubeRows:
            self.assertTrue(len(aggCubeRow["dimensions"]) == 1)
            print aggCubeRow

        print "---------"

        os.remove(cubeSetName + ".csv")