Beispiel #1
0
        public PivotLevel ComputePivot(OrQuery filter, IEnumerable <int> axis, IEnumerable <int> values)
        {
            var result = new PivotLevel();

            try
            {
                Parallel.ForEach(CacheClients, client =>
                {
                    var pivot = client.ComputePivot(filter, axis, values);
                    lock (result)
                    {
                        result.MergeWith(pivot);
                    }
                });
            }
            catch (AggregateException e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
            }

            return(result);
        }
        public void ComputePivotWithServerValues()
        {
            var description = TypedSchemaFactory.FromType(typeof(Order));

            var order1 = new Order
            {
                Amount   = 123.45, Date = DateTimeOffset.Now, Category = "geek", ClientId = 101, ProductId = 401,
                Id       = Guid.NewGuid(),
                Quantity = 2
            };

            var order2 = new Order
            {
                Amount   = 123.45, Date = DateTimeOffset.Now, Category = "sf", ClientId = 101, ProductId = 401,
                Id       = Guid.NewGuid(),
                Quantity = 2
            };

            var packed1 = PackedObject.Pack(order1, description);
            var packed2 = PackedObject.Pack(order2, description);

            var pivot = new PivotLevel();

            // Amount and Quantity to be aggregated (index 1 and 2) in the schema
            pivot.AggregateOneObject(packed1, new List <int>(), new List <int> {
                1, 2
            });
            pivot.AggregateOneObject(packed2, new List <int>(), new List <int> {
                1, 2
            });


            // Amount and Quantity should be aggregated
            Assert.AreEqual(2, pivot.AggregatedValues.Count);

            var agg = pivot.AggregatedValues.First(v => v.ColumnName == "Amount");

            Assert.AreEqual(2, agg.Count);
            Assert.AreEqual(order1.Amount + order2.Amount, agg.Sum);


            Console.WriteLine(pivot.ToString());
        }
        public void ComputePivotWithMultipleAxis()
        {
            var schema = TypedSchemaFactory.FromType(typeof(Order));

            var order1 = new Order
            {
                Amount   = 123.45, Date = DateTimeOffset.Now, Category = "geek", ClientId = 101, ProductId = 401,
                Id       = Guid.NewGuid(),
                Quantity = 2
            };

            var order2 = new Order
            {
                Amount   = 123.45, Date = DateTimeOffset.Now, Category = "sf", ClientId = 101, ProductId = 401,
                Id       = Guid.NewGuid(),
                Quantity = 2
            };

            var order3 = new Order
            {
                Amount   = 14.5, Date = DateTimeOffset.Now, Category = "geek", ClientId = 101, ProductId = 402,
                Id       = Guid.NewGuid(),
                Quantity = 2
            };

            var packed1 = PackedObject.Pack(order1, schema);
            var packed2 = PackedObject.Pack(order2, schema);
            var packed3 = PackedObject.Pack(order3, schema);


            // first test with one single axis (Category index = 3)
            var pivot = new PivotLevel();

            pivot.AggregateOneObject(packed1, new List <int> {
                3
            }, new List <int> {
                1, 2
            });
            pivot.AggregateOneObject(packed2, new List <int> {
                3
            }, new List <int> {
                1, 2
            });
            pivot.AggregateOneObject(packed3, new List <int> {
                3
            }, new List <int> {
                1, 2
            });


            // Amount and Quantity should be aggregated
            Assert.AreEqual(2, pivot.AggregatedValues.Count);

            var agg = pivot.AggregatedValues.First(v => v.ColumnName == "Amount");

            Assert.AreEqual(3, agg.Count);
            Assert.AreEqual(order1.Amount + order2.Amount + order3.Amount, agg.Sum);

            Assert.IsTrue(pivot.Children.Keys.All(k => k.KeyName == "Category"));
            Assert.IsTrue(pivot.Children.Values.All(v => v.AxisValue.KeyName == "Category"));

            var geek = pivot.Children.Values.First(p => p.AxisValue.StringValue == "geek");

            Assert.AreEqual(2, geek.AggregatedValues.Count);

            // then with two axis

            pivot = new PivotLevel();

            pivot.AggregateOneObject(packed1, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot.AggregateOneObject(packed2, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot.AggregateOneObject(packed3, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });

            Console.WriteLine(pivot.ToString());

            var geek1 = pivot.Children.Values.First(p => p.AxisValue.StringValue == "geek");

            Assert.AreEqual(2, geek1.AggregatedValues.Count);
            Assert.AreEqual(2, geek1.Children.Count);


            // check pivot merging

            // a new category
            var order4 = new Order
            {
                Amount   = 66.5, Date = DateTimeOffset.Now, Category = "student", ClientId = 101, ProductId = 405,
                Id       = Guid.NewGuid(),
                Quantity = 1
            };

            var packed4 = PackedObject.Pack(order4, schema);

            var pivot1 = new PivotLevel();

            pivot1.AggregateOneObject(packed1, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot1.AggregateOneObject(packed2, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot1.AggregateOneObject(packed3, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });

            var pivot2 = new PivotLevel();

            pivot2.AggregateOneObject(packed1, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot2.AggregateOneObject(packed3, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });
            pivot2.AggregateOneObject(packed4, new List <int> {
                3, 4
            }, new List <int> {
                1, 2
            });

            pivot1.MergeWith(pivot2);

            Console.WriteLine(pivot1);

            // check that an aggregate is equal to the sum of the children
            var sum1 = pivot1.AggregatedValues.First(v => v.ColumnName == "Amount").Sum;
            var sum2 = pivot1.Children.Sum(c => c.Value.AggregatedValues.First(v => v.ColumnName == "Amount").Sum);

            Assert.AreEqual(sum1, sum2);
        }
 /**
  * Constructor.
  * <p>
  * Calculates the (standard) reversal for the corresponding pivot level
  * @param pivotPointIndicator the {@link PivotPointIndicator} for this reversal
  * @param level the {@link PivotLevel} for this reversal
  */
 public StandardReversalIndicator(PivotPointIndicator pivotPointIndicator, PivotLevel level)
     : base(pivotPointIndicator)
 {
     _pivotPointIndicator = pivotPointIndicator;
     _level = level;
 }