Matrix Stats Aggregation Usage

edit

Fluent DSL example

edit
a => a
.MatrixStats("matrixstats", ms => ms
    .Meta(m => m
        .Add("foo", "bar")
    )
    .Fields(fs => fs
        .Field(p => p.NumberOfCommits)
        .Field(p => p.NumberOfContributors)
    )
    .Missing(m => m
        .Add(Field<Project>(p => p.NumberOfCommits), 0)
        .Add(Field<Project>(p => p.NumberOfContributors), 1)
    )
    .Mode(MatrixStatsMode.Median)
)

Object Initializer syntax example

edit
new MatrixStatsAggregation("matrixstats", Field<Project>(p => p.NumberOfCommits))
{
    Meta = new Dictionary<string, object>
    {
        { "foo", "bar" }
    },
    Missing = new Dictionary<Field, double>
    {
        { "numberOfCommits", 0.0 },
        { "numberOfContributors", 1.0 },
    },
    Mode = MatrixStatsMode.Median,
    Fields = Field<Project>(p => p.NumberOfCommits).And("numberOfContributors")
}

Example json output.

{
  "matrixstats": {
    "meta": {
      "foo": "bar"
    },
    "matrix_stats": {
      "fields": [
        "numberOfCommits",
        "numberOfContributors"
      ],
      "missing": {
        "numberOfCommits": 0.0,
        "numberOfContributors": 1.0
      },
      "mode": "median"
    }
  }
}

Handling Responses

edit
response.ShouldBeValid();
var matrix = response.Aggregations.MatrixStats("matrixstats");
matrix.Should().NotBeNull();
matrix.Fields.Should().NotBeNull().And.HaveCount(2);
matrix.DocCount.Should().BeGreaterThan(0);

AssertField(matrix, "numberOfCommits");
AssertField(matrix, "numberOfContributors");