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.3); cell4.Setup(foo => foo.Content).Returns((double)0.1); List<Cell> cells = new List<Cell>(); cells.Add(cell1.Object); cells.Add(cell2.Object); cells.Add(cell3.Object); MinAggregation target = new MinAggregation(); double expected = 0.3; double actual; actual = (double)target.GetAggregatedValue(cells); Assert.AreEqual(expected, actual); cells.Add(cell4.Object); expected = 0.1; actual = (double)target.GetAggregatedValue(cells); Assert.AreEqual(expected, actual); }
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.3); cell4.Setup(foo => foo.Content).Returns((double)0.1); List <Cell> cells = new List <Cell>(); cells.Add(cell1.Object); cells.Add(cell2.Object); cells.Add(cell3.Object); MinAggregation target = new MinAggregation(); double expected = 0.3; double actual; actual = (double)target.GetAggregatedValue(cells); Assert.AreEqual(expected, actual); cells.Add(cell4.Object); expected = 0.1; actual = (double)target.GetAggregatedValue(cells); Assert.AreEqual(expected, actual); }
/// <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); }
public Tuple <string, List <BoardGame> > QueryData_MinPlayTime(string query) { _elasticClient.Flush("boardgames"); var queryContainer = new QueryContainer(); queryContainer &= new MatchAllQuery(); var aggregation = new MinAggregation("min_playing_time_aggregation", Infer.Field <BoardGame>(p => p.PlayingTime)); var searchRequest = new SearchRequest("boardgames", typeof(BoardGame)) { Query = queryContainer, Aggregations = aggregation }; var searchResponse = _elasticClient.Search <BoardGame>(searchRequest); var minPlayingTime = searchResponse.Aggregations.Min("min_playing_time_aggregation"); return(new Tuple <string, List <BoardGame> >( searchResponse.DebugInformation, searchResponse.Documents.ToList() )); }
/// <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); }