Skip to content

Commit

Permalink
Add standard deviation / variance sampling to extended stats (#4891)
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam authored and github-actions[bot] committed Jul 31, 2020
1 parent 20e4875 commit d565147
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Nest/Aggregations/AggregateFormatter.cs
Expand Up @@ -72,7 +72,11 @@ internal class AggregateFormatter : IJsonFormatter<IAggregate>
{
{ "variance", 0 },
{ "std_deviation", 1 },
{ "std_deviation_bounds", 2 }
{ "std_deviation_bounds", 2 },
{ "variance_population", 3 },
{ "variance_sampling", 4 },
{ "std_deviation_population", 5 },
{ "std_deviation_sampling", 6 },
};

private static readonly byte[] ValueAsStringField = JsonWriter.GetEncodedPropertyNameWithoutQuotation(Parser.ValueAsString);
Expand Down Expand Up @@ -589,6 +593,18 @@ private IAggregate GetExtendedStatsAggregate(ref JsonReader reader, IJsonFormatt
extendedStatsMetric.StdDeviationBounds =
formatterResolver.GetFormatter<StandardDeviationBounds>().Deserialize(ref reader, formatterResolver);
break;
case 3:
extendedStatsMetric.VariancePopulation = reader.ReadNullableDouble();
break;
case 4:
extendedStatsMetric.VarianceSampling = reader.ReadNullableDouble();
break;
case 5:
extendedStatsMetric.StdDeviationPopulation = reader.ReadNullableDouble();
break;
case 6:
extendedStatsMetric.StdDeviationSampling = reader.ReadNullableDouble();
break;
}
}
else
Expand Down
Expand Up @@ -8,10 +8,53 @@ namespace Nest
{
public class ExtendedStatsAggregate : StatsAggregate
{
/// <summary>
/// The standard deviation of the collected values
/// </summary>
public double? StdDeviation { get; set; }

/// <summary>
/// The upper or lower bounds of standard deviation
/// </summary>
public StandardDeviationBounds StdDeviationBounds { get; set; }

/// <summary>
/// The sum of squares of the collected values
/// </summary>
public double? SumOfSquares { get; set; }

/// <summary>
/// The variance of the collected values
/// </summary>
public double? Variance { get; set; }

/// <summary>
/// The population variance of the collected values.
/// <para />
/// Valid in Elasticsearch 7.9.0+
/// </summary>
public double? VariancePopulation { get; set; }

/// <summary>
/// The sampling variance of the collected values.
/// <para />
/// Valid in Elasticsearch 7.9.0+
/// </summary>
public double? VarianceSampling { get; set; }

/// <summary>
/// The population standard deviation of the collected values.
/// <para />
/// Valid in Elasticsearch 7.9.0+
/// </summary>
public double? StdDeviationPopulation { get; set; }

/// <summary>
/// The sampling standard deviation of the collected values.
/// <para />
/// Valid in Elasticsearch 7.9.0+
/// </summary>
public double? StdDeviationSampling { get; set; }
}

[DataContract]
Expand All @@ -22,5 +65,17 @@ public class StandardDeviationBounds

[DataMember(Name = "upper")]
public double? Upper { get; set; }

[DataMember(Name = "lower_population")]
public double? LowerPopulation { get; set; }

[DataMember(Name = "upper_population")]
public double? UpperPopulation { get; set; }

[DataMember(Name = "lower_sampling")]
public double? LowerSampling { get; set; }

[DataMember(Name = "upper_sampling")]
public double? UpperSampling { get; set; }
}
}
Expand Up @@ -2,9 +2,10 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System;
using FluentAssertions;
using Nest;
using Tests.Core.Client;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Domain;
Expand Down Expand Up @@ -56,6 +57,19 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
commitStats.StdDeviationBounds.Should().NotBeNull();
commitStats.StdDeviationBounds.Upper.Should().BeGreaterThan(0);
commitStats.StdDeviationBounds.Lower.Should().NotBe(0);

// hide
if (TestClient.Configuration.InRange(">=7.9.0"))
{
commitStats.VariancePopulation.Should().BeGreaterThan(0);
commitStats.VarianceSampling.Should().BeGreaterThan(0);
commitStats.StdDeviationPopulation.Should().BeGreaterThan(0);
commitStats.StdDeviationSampling.Should().BeGreaterThan(0);
commitStats.StdDeviationBounds.UpperPopulation.Should().BeGreaterThan(0);
commitStats.StdDeviationBounds.UpperSampling.Should().NotBe(0);
commitStats.StdDeviationBounds.LowerPopulation.Should().NotBe(0);
commitStats.StdDeviationBounds.LowerSampling.Should().NotBe(0);
}
}
}

Expand Down

0 comments on commit d565147

Please sign in to comment.