Exemplo n.º 1
0
        public void GetAggregatedValueTest()
        {
            var cell1 = new Mock <Cell>();
            var cell2 = new Mock <Cell>();
            var cell3 = new Mock <Cell>();
            var cell4 = new Mock <Cell>();

            cell1.Setup(foo => foo.Content).Returns((double)0.6);
            cell2.Setup(foo => foo.Content).Returns((double)3);
            cell3.Setup(foo => foo.Content).Returns((double)0.6);
            cell4.Setup(foo => foo.Content).Returns((double)5);
            List <Cell> cells = new List <Cell>();

            cells.Add(cell1.Object);
            cells.Add(cell2.Object);
            cells.Add(cell3.Object);
            MaxAggregation target   = new MaxAggregation();
            double         expected = 3;
            double         actual;

            actual = (double)target.GetAggregatedValue(cells);
            Assert.AreEqual(expected, actual);

            cells.Add(cell4.Object);
            expected = 5;
            actual   = (double)target.GetAggregatedValue(cells);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Aggregate resuts
        /// </summary>
        /// <param name="key">Key identifier of results</param>
        /// <param name="field">Id field uppon the aggregation will be used</param>
        /// <param name="aggType">Type of Aggregation</param>
        public FindRequest <T> Aggregation(string key, Expression <Func <T, object> > field, EnAggregationType aggType)
        {
            AggregationContainer aggr = null;

            switch (aggType)
            {
            case EnAggregationType.Sum:
                aggr = new SumAggregation(key, field);
                break;

            case EnAggregationType.Average:
                aggr = new AverageAggregation(key, field);
                break;

            case EnAggregationType.Min:
                aggr = new MinAggregation(key, field);
                break;

            case EnAggregationType.Max:
                aggr = new MaxAggregation(key, field);
                break;
            }
            if (aggr != null)
            {
                searchInfo.Aggregations.Add(key, aggr);
            }
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Aggregate resuts over a clause
        /// </summary>
        /// <param name="groupField">Field that will be used as term to group aggregation results</param>
        /// <param name="field">Id field uppon the aggregation will be used</param>
        /// <param name="aggType">Type of Aggregation</param>
        public FindRequest <T> TermAggregation(Expression <Func <T, object> > groupField, Expression <Func <T, object> > field, EnAggregationType aggType)
        {
            //Get term
            var termName          = Utils.ExpressionAttributeName(groupField);
            TermsAggregation term = null;

            if (!searchInfo.termDictionary.ContainsKey(termName))
            {
                term = new TermsAggregation(termName)
                {
                    Field = groupField
                };
                searchInfo.termDictionary.Add(termName, term);
            }
            else
            {
                term = searchInfo.termDictionary[termName];
            }

            if (term != null)
            {
                //if(agg)
                AggregationContainer aggr = null;
                string pKey = "";
                switch (aggType)
                {
                case EnAggregationType.Sum:
                    pKey = string.Format("{0}_sum", termName);
                    aggr = new SumAggregation(pKey, field);
                    break;

                case EnAggregationType.Average:
                    pKey = string.Format("{0}_avg", termName);
                    aggr = new AverageAggregation(pKey, field);
                    break;

                case EnAggregationType.Min:
                    pKey = string.Format("{0}_min", termName);
                    aggr = new MinAggregation(pKey, field);
                    break;

                case EnAggregationType.Max:
                    pKey = string.Format("{0}_max", termName);
                    aggr = new MaxAggregation(pKey, field);
                    break;
                }
                if (aggr != null)
                {
                    if (term.Aggregations == null)
                    {
                        term.Aggregations = new AggregationDictionary();
                    }
                    term.Aggregations.Add(pKey, aggr);
                }
            }
            return(this);
        }