public static AggregateAggregateValue Create(
                    AggregateOperator aggregateOperator,
                    string continuationToken)
                {
                    IAggregator aggregator;

                    switch (aggregateOperator)
                    {
                    case AggregateOperator.Average:
                        aggregator = AverageAggregator.Create(continuationToken);
                        break;

                    case AggregateOperator.Count:
                        aggregator = CountAggregator.Create(continuationToken);
                        break;

                    case AggregateOperator.Max:
                        aggregator = MinMaxAggregator.CreateMaxAggregator(continuationToken);
                        break;

                    case AggregateOperator.Min:
                        aggregator = MinMaxAggregator.CreateMinAggregator(continuationToken);
                        break;

                    case AggregateOperator.Sum:
                        aggregator = SumAggregator.Create(continuationToken);
                        break;

                    default:
                        throw new ArgumentException($"Unknown {nameof(AggregateOperator)}: {aggregateOperator}.");
                    }

                    return(new AggregateAggregateValue(aggregator));
                }
Ejemplo n.º 2
0
                public static TryCatch <AggregateValue> TryCreate(
                    AggregateOperator aggregateOperator,
                    string continuationToken)
                {
                    TryCatch <IAggregator> tryCreateAggregator;

                    switch (aggregateOperator)
                    {
                    case AggregateOperator.Average:
                        tryCreateAggregator = AverageAggregator.TryCreate(continuationToken);
                        break;

                    case AggregateOperator.Count:
                        tryCreateAggregator = CountAggregator.TryCreate(continuationToken);
                        break;

                    case AggregateOperator.Max:
                        tryCreateAggregator = MinMaxAggregator.TryCreateMaxAggregator(continuationToken);
                        break;

                    case AggregateOperator.Min:
                        tryCreateAggregator = MinMaxAggregator.TryCreateMinAggregator(continuationToken);
                        break;

                    case AggregateOperator.Sum:
                        tryCreateAggregator = SumAggregator.TryCreate(continuationToken);
                        break;

                    default:
                        throw new ArgumentException($"Unknown {nameof(AggregateOperator)}: {aggregateOperator}.");
                    }

                    return(tryCreateAggregator.Try <AggregateValue>((aggregator) => new AggregateAggregateValue(aggregator)));
                }
Ejemplo n.º 3
0
        protected override Expression TransformFunction(FunctionExpression functionExpression)
        {
            if (functionExpression.Function == Operators.Diff)
            {
                VariableListExtractor extractor = new VariableListExtractor();
                extractor.Visit(functionExpression[1]);
                IReadOnlyList <Variable> variables = extractor.Variables;
                if (variables.Count == 0)
                {
                    throw new InvalidOperationException("Cannot calculate derivative by constant");
                }

                throw new NotImplementedException();
            }
            if (functionExpression.Function == Operators.Plus)
            {
                return(Transform(functionExpression[0]));
            }
            if (functionExpression.Function is Operator)
            {
                SumAggregator aggregator = new SumAggregator();
                aggregator.VisitFunction(functionExpression);
                return(aggregator.ToExpression());
            }
            return(functionExpression.Function.Apply(functionExpression.Select(Transform)));
        }
Ejemplo n.º 4
0
        public void SumAggregator()
        {
            var sumAggr = new SumAggregator("test");
            Func <object, string, object> getVal = (r, f) => {
                Assert.Equal("test", f);
                return(r);
            };

            sumAggr.Push(5, getVal);
            Assert.Equal(5M, sumAggr.Value);
            sumAggr.Push(3, getVal);
            Assert.Equal(8M, sumAggr.Value);
        }
Ejemplo n.º 5
0
        public void SumAggregator_Merge()
        {
            var sumAggr1 = new SumAggregator("test");
            var sumAggr2 = new SumAggregator("test");
            Func <object, string, object> getVal = (r, f) => {
                return(r);
            };

            for (int i = 0; i < 10; i++)
            {
                sumAggr1.Push(i, getVal);
                sumAggr2.Push(i % 2, getVal);
            }

            sumAggr1.Merge(sumAggr2);
            Assert.Equal(50M, Convert.ToDecimal(sumAggr1.Value));
            Assert.Equal(20, (int)sumAggr1.Count);
        }
Ejemplo n.º 6
0
        public void AggregateField_Given_a_valid_field_Agregate_shound_be_equal_to_sum_of_the_field_value()
        {
            var aggregate = new Aggregate();
            var target    = new SumAggregator {
                Aggregate = aggregate, Description = "Record Count", Name = "Record Count"
            };

            var field1 = new Field {
                Index = 1, Raw = "100", ValidationResult = ValidationResultType.Valid, Value = 100
            };
            var field2 = new Field {
                Index = 2, Raw = "200", ValidationResult = ValidationResultType.Valid, Value = 200
            };

            target.AggregateField(field1);
            target.AggregateField(field2);

            Assert.AreEqual(300m, aggregate.Value);
        }
 public RemoteAvgAggregator(IAccessor <T> accessor)
     : base(accessor)
 {
     _countAggregator = new SumAggregator <T>(accessor);
     _valueAggregator = new SumAggregator <T>(accessor);
 }