Exemple #1
0
        public void DimensionMembersTest()
        {
            KeyValuePair <int, int>[] pairs = new KeyValuePair <int, int>[] {
                new KeyValuePair <int, int>(1, 2),
                new KeyValuePair <int, int>(2, 1),
                new KeyValuePair <int, int>(3, 6)
            };
            KeyValuePair <int, int>[] pairs2 = new KeyValuePair <int, int>[] {
                new KeyValuePair <int, int>(2, 1),
                new KeyValuePair <int, int>(3, 6)
            };
            Cube <int> cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures();

            _watch.Reset();
            _watch.Start();

            cube.Initialize();
            cube.Process();

            Cell <int> xcell  = cube.Cells[pairs];
            Cell <int> xcell2 = cube.Cells[pairs2];

            _watch.Stop();
            Console.WriteLine();
            Console.WriteLine(_watch.ElapsedMilliseconds);
            Console.WriteLine();

            Assert.AreEqual("male", cube.Schema.Dimensions["sex"].Members["male"].Name);
            Assert.AreEqual("female", cube.Schema.Dimensions["sex"].Members["female"].Name);
            Assert.AreEqual("London", cube.Schema.Dimensions["place"].Members["London"].Name);
            Assert.AreEqual(5, xcell.Values[cube.Schema.Measures["quantity"].ID]);
            Assert.AreEqual(10.10, xcell.Values[cube.Schema.Measures["spent"].ID]);
            Assert.AreEqual(3, xcell2.Occurrences);
        }
        public void Basic_Multiple_Metric_Expressions_Execution_Test()
        {
            using (var cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2())
            {
                cube.Initialize();

                cube.BuildMetrics()
                .Add("testeAverage",
                     exb => exb.Expression(e => e.Set("quantity").Average()))
                .Add("testeMax",
                     exb => exb.Expression(e => e.Set("quantity").Max()))
                .Add("testeMin",
                     exb => exb.Expression(e => e.Set("quantity").Min()))
                .Create();

                Assert.IsNotNull(cube.Schema.Metrics["testeAverage"]);
                Assert.IsNotNull(cube.Schema.Metrics["testeMax"]);
                Assert.IsNotNull(cube.Schema.Metrics["testeMin"]);

                cube.Process();

                var cell = cube.Cells.Take(1).FirstOrDefault();


                var valueMeasure = (int)cell.Values[cube.Schema.Measures["quantity"].ID];
                var valueAverage = cell.Values[cube.Schema.Metrics["testeAverage"].ID];
                var valueMax     = cell.Values[cube.Schema.Metrics["testeMax"].ID];
                var valueMin     = cell.Values[cube.Schema.Metrics["testeMin"].ID];

                Assert.AreEqual(valueMeasure / 24, valueAverage);
                Assert.AreEqual(101, valueMax);
                Assert.AreEqual(1, valueMin);
            }
        }
        public void Basic_Multiple_Metric_Expressions_Execution_With_Query_On_Metric_Test()
        {
            using (var cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2())
            {
                cube.Initialize();

                cube.BuildMetrics()
                .Add("testeAverage",
                     exb => exb.Expression(e => e.Set("quantity").Average()))
                .Add("testeMax",
                     exb => exb.Expression(e => e.Set("quantity").Max()))
                .Add("testeMin",
                     exb => exb.Expression(e => e.Set("quantity").Min()))
                .Create();

                Assert.IsNotNull(cube.Schema.Metrics["testeAverage"]);
                Assert.IsNotNull(cube.Schema.Metrics["testeMax"]);
                Assert.IsNotNull(cube.Schema.Metrics["testeMin"]);

                cube.Process();

                var queryBuilder = cube.BuildQuery()
                                   .OnColumns("sex.All")
                                   .AddMeasuresOrMetrics("testeAverage");

                var query  = queryBuilder.Create();
                var result = query.StreamRows().ToList();

                Assert.IsTrue(result.Count == 2);
            }
        }
        public void Init()
        {
            cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2();
            cube.Initialize();
            cube.Process();

            _resolver = new NamespaceResolver <int>(cube);
        }
        public void Basic_Metric_Expression_Execution_Test()
        {
            using (var cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2())
            {
                cube.Initialize();

                cube.BuildMetrics()
                .Add("teste1", exb => exb.Expression(e => e.Set("quantity").Sum(10)))
                .Create();

                Assert.IsNotNull(cube.Schema.Metrics["teste1"]);

                cube.Process();

                var cell = cube.Cells.Take(1).FirstOrDefault();


                var valueMeasure = (int)cell.Values[cube.Schema.Measures["quantity"].ID];
                var value        = (int)cell.Values[cube.Schema.Metrics["teste1"].ID];

                Assert.AreEqual(valueMeasure + 10, value);
            }
        }
        public void Composite_Metric_Division_Expression_Execution_Test()
        {
            using (var cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2())
            {
                cube.Initialize();

                cube.BuildMetrics()
                .Add("testeDivide2", exb => exb.Expression(e => e.Set("spent").Divide(ex => ex.Set("quantity").Value())))
                .Create();

                Assert.IsNotNull(cube.Schema.Metrics["testeDivide2"]);

                cube.Process();

                var cell = cube.Cells.Take(1).FirstOrDefault();


                var valueMeasure  = (int)cell.Values[cube.Schema.Measures["quantity"].ID];
                var valueMeasure2 = (double)cell.Values[cube.Schema.Measures["spent"].ID];
                var value         = (double)cell.Values[cube.Schema.Metrics["testeDivide2"].ID];

                Assert.AreEqual(valueMeasure2 / valueMeasure, value);
            }
        }
Exemple #7
0
        public void CellsEnumeratorTest()
        {
            /*    CubeBuilder builder = new CubeBuilder();
             *
             *  builder.SetName("hello")
             *    .SetSource((sourcebuild) =>
             *    {
             *      sourcebuild.SetSource("sales")
             *        .AddMapping("category", "category")
             *        .AddMapping("sex", "sex")
             *        .AddMapping("place", "place");
             *    })
             *    .AddDataSource(dsbuild =>
             *    {
             *      dsbuild.SetName("sales")
             *        .SetSourceType(DataSourceType.CSV)
             *        .SetCSVConfig(csvbuild =>
             *        {
             *          csvbuild.SetFilePath("TestData//table.csv")
             *                           .SetHasHeader();
             *        })
             *        .AddField("category", 0, typeof(int))
             *        .AddField("sex", 1, typeof(int))
             *        .AddField("place", 2, typeof(int))
             *        .AddField("expenses", 3, typeof(double))
             *        .AddField("items", 4, typeof(int));
             *    })
             *    .AddDataSource(dsbuild =>
             *    {
             *      dsbuild.SetName("categories")
             *        .SetSourceType(DataSourceType.CSV)
             *        .AddField("id", 0, typeof(int))
             *        .AddField("description", 1, typeof(string))
             *        .SetCSVConfig(csvbuild =>
             *        {
             *          csvbuild.SetFilePath("TestData//dimension1.csv")
             *                           .SetHasHeader();
             *        });
             *    })
             *    .AddDataSource(dsbuild =>
             *    {
             *      dsbuild.SetName("sexes")
             *        .SetSourceType(DataSourceType.CSV)
             *        .AddField("id", 0, typeof(int))
             *        .AddField("description", 1, typeof(string))
             *        .SetCSVConfig(csvbuild =>
             *        {
             *          csvbuild.SetFilePath("TestData//dimension2.csv")
             *                           .SetHasHeader();
             *        });
             *    })
             *    .AddDataSource(dsbuild =>
             *    {
             *      dsbuild.SetName("places")
             *        .SetSourceType(DataSourceType.CSV)
             *        .AddField("id", 0, typeof(int))
             *        .AddField("description", 1, typeof(string))
             *        .SetCSVConfig(csvbuild =>
             *        {
             *          csvbuild.SetFilePath("TestData//dimension3.csv")
             *                           .SetHasHeader();
             *        });
             *    })
             *    .MetaData(mbuild =>
             *    {
             *      mbuild.AddDimension("category", (dimbuild) =>
             *      {
             *        dimbuild.Source("categories")
             *          .ValueField("id")
             *          .DescField("description");
             *      })
             *        .AddDimension("sex", (dimbuild) =>
             *        {
             *          dimbuild.Source("sexes")
             *                      .ValueField("id")
             *                      .DescField("description");
             *        })
             *        .AddDimension("place", (dimbuild) =>
             *        {
             *          dimbuild.Source("places")
             *                      .ValueField("id")
             *                      .DescField("description");
             *        })
             *        .AddMeasure("spent", mesbuild =>
             *        {
             *          mesbuild.ValueField("expenses")
             *                      .SetType(typeof(double));
             *        })
             *        .AddMeasure("quantity", mesbuild =>
             *        {
             *          mesbuild.ValueField("items")
             *                      .SetType(typeof(int));
             *        });
             *    });*/

            Cube <int> cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures();

            _watch.Reset();
            _watch.Start();

            cube.Initialize();
            cube.Process();
            // 12, 7
            Console.WriteLine();

            foreach (Cell <int> item in cube.Cells)
            {
                foreach (var pair in item.Coords)
                {
                    Console.Write(pair.Key);
                    Console.Write(",");
                    Console.Write(pair.Value);
                    Console.Write("|");
                }
                Console.WriteLine();
            }

            int count = cube.Cells.Count;

            _watch.Stop();
            Console.WriteLine();
            Console.WriteLine(_watch.ElapsedMilliseconds);
            Console.WriteLine();
        }
Exemple #8
0
 public void Init()
 {
     cube = CubeSourcesFixture.GetBasicCubeThreeSimpleDimensionsTwoMeasuresAndThreeDateDimensions();
     cube.Initialize();
     cube.Process();
 }
Exemple #9
0
 public void Init()
 {
     cube = CubeSourcesFixture.GetBasicCubeThreeDimensionsTwoMeasures2();
     cube.Initialize();
 }