Ejemplo n.º 1
0
        private void ProcessAggregate(ref JsonReader reader, ref JsonWriter writer)
        {
            var state = new AggregateProcessor(_query);

            var recordsProcessed = 0;
            var limit            = _query.Limit.Match(x => x.Limit, _ => int.MaxValue);

            while (true)
            {
                var readResult = ReadRecord(ref reader);
                if (readResult.IsNone)
                {
                    break;
                }

                var record = readResult.AsT0;
                if (TestPredicate(record))
                {
                    if (recordsProcessed++ >= limit)
                    {
                        break;
                    }

                    state.ProcessRecord(record);
                }
            }

            state.Write(ref writer);
            writer.WriteRaw((byte)'\n');
        }
Ejemplo n.º 2
0
        public void GenerateAggregateResultSetCalculatesAverageAndMaxOnSameVariable()
        {
            //setup
            var variableType = "X";
            var sut          = new AggregateProcessor();
            var avvalues     = new List <double>()
            {
                10, 20, 30, 40
            };
            var maxvalues = new List <double>()
            {
                40, 50, 60, 40
            };


            sut.AddResults(GetResultSet(new string[] { variableType }, true, true, false, avvalues.ToArray(), maxvalues.ToArray(), null));//

            //execute
            var results = sut.GenerateAggregateResultSet();


            //assert
            Assert.IsTrue(results.Any(r => r.VariableType == "X" && r.CalculationType == statisticCalculation.Average.ToString()));
            Assert.IsTrue(results.Any(r => r.VariableType == "X" && r.CalculationType == statisticCalculation.MaxValue.ToString()));
            Assert.AreEqual(25, results.First(r => r.VariableType == "X" && r.CalculationType == statisticCalculation.Average.ToString()).Value);
            Assert.AreEqual(60, results.First(r => r.VariableType == "X" && r.CalculationType == statisticCalculation.MaxValue.ToString()).Value);
        }
        public void Setup()
        {
            _cancellationToken = new CancellationToken();
            _aggregateId       = _fixture.Create <string>();
            _aggregate         = new BankAccount();

            _aggregateRepositoryMock = new Mock <IAggregateRepository <BankAccount> >();
            _aggregateRepositoryMock.Setup(x => x.GetAsync(_aggregateId, _cancellationToken)).ReturnsAsync(_aggregate);

            _sut = new AggregateProcessor <BankAccount>(_aggregateRepositoryMock.Object);
        }
Ejemplo n.º 4
0
        public void GenerateAggregateResultSetCalculatesAverage()
        {
            //setup
            var variableType = "X";
            var sut          = new AggregateProcessor();
            var values       = new List <double>()
            {
                10, 20, 30, 40
            };

            sut.AddResults(GetResultSet(new string[] { variableType }, true, false, false, values.ToArray(), null, null));//

            //execute
            var results = sut.GenerateAggregateResultSet();


            //assert
            Assert.AreEqual(25, results.First().Value);
            Assert.AreEqual(statisticCalculation.Average.ToString(), results.First().CalculationType);
            Assert.AreEqual(variableType, results.First().VariableType);
        }
Ejemplo n.º 5
0
 public MedicamentsController(AggregateProcessor aggregateProcessor)
 {
     _aggregateProcessor = aggregateProcessor;
 }