Esempio n. 1
0
        public void CanUseDynamicGrouping_WithFuncAndLoadedTag()
        {
            using (var store = GetDocumentStore())
            {
                var baseline = TimeSeriesGroupByTag.PopulateCanGroupByLoadedTag(store);

                using (var session = store.OpenSession())
                {
                    var interval = GroupingInterval.Month;

                    var query = session.Query <TimeSeriesLinqQuery.Person>()
                                .Select(u => RavenQuery.TimeSeries(u, "Heartrate", baseline.EnsureUtc(), baseline.AddMonths(2).EnsureUtc())
                                        .GroupBy(g => Func(g, interval)
                                                 .ByTag <TimeSeriesLinqQuery.Watch>(w => w.Accuracy))
                                        .Select(g => new
                    {
                        Average = g.Average(),
                        Max     = g.Max()
                    })
                                        .ToList());

                    var result = query.First();

                    Assert.Equal(6, result.Count);

                    var agg = result.Results;

                    Assert.Equal(3, agg.Length);

                    var monthBaseline = new DateTime(baseline.Year, baseline.Month, 1);

                    var val1 = agg[0];
                    Assert.Equal(10.0m, val1.Key);
                    Assert.Equal(monthBaseline, val1.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(monthBaseline.AddMonths(1), val1.To, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(3, val1.Count[0]);

                    var val2 = agg[1];
                    Assert.Equal(10.0m, val2.Key);
                    Assert.Equal(monthBaseline.AddMonths(1), val2.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(monthBaseline.AddMonths(2), val2.To, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(2, val2.Count[0]);

                    var val3 = agg[2];
                    Assert.Equal(5.0m, val3.Key);
                    Assert.Equal(monthBaseline.AddMonths(1), val3.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(monthBaseline.AddMonths(2), val3.To, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(1, val3.Count[0]);
                }
            }
        }
Esempio n. 2
0
        public void CanUseDynamicGrouping_WithTagAndInterpolation()
        {
            using (var store = GetDocumentStore())
            {
                var baseline = TimeSeriesGroupByTag.PopulateCanGroupByTagWithInterpolation(store);

                using (var session = store.OpenSession())
                {
                    var grouping = GroupingInterval.Hour; // This could vary based on client input

                    var query = session.Query <TimeSeriesLinqQuery.Person>()
                                .Select(u => RavenQuery.TimeSeries(u, "Heartrate", baseline.EnsureUtc(), baseline.AddMonths(2).EnsureUtc())
                                        .GroupBy(g => Func2(g, grouping, InterpolationType.Linear, true))
                                        .Select(g => new
                    {
                        Max     = g.Max(),
                        Average = g.Average(),
                    })
                                        .ToList());

                    var result = query.First();

                    Assert.Equal(32 * 3, result.Count);

                    var agg = result.Results;

                    Assert.Equal(32 * 3, agg.Length);

                    var groups = agg.GroupBy(x => x.Key);

                    foreach (var group in groups)
                    {
                        var key   = group.Key;
                        var value = group.OrderBy(x => x.From).ToArray();
                        Assert.Equal(32, value.Length);
                        for (int i = 0; i < value.Length; i++)
                        {
                            var val = value[i];
                            switch (key)
                            {
                            case "watches/fitbit":
                                Assert.Equal(i * 10, val.Average[0]);
                                break;

                            case "watches/apple":
                                Assert.Equal(i * 100, val.Average[0]);
                                break;

                            case "watches/sony":
                                Assert.Equal(i * 1000, val.Average[0]);
                                break;

                            default:
                                throw new ArgumentException();
                            }
                            Assert.Equal(baseline.AddHours(i), val.From, RavenTestHelper.DateTimeComparer.Instance);
                            Assert.Equal(baseline.AddHours(i + 1), val.To, RavenTestHelper.DateTimeComparer.Instance);
                        }
                    }
                }
            }
        }