예제 #1
0
        public void CanStoreAndReadMultipleTimestampsUsingStoreOperations()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(1), Values = new[] { 59d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(2), Values = new[] { 61d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/apple-watch", Timestamp = baseline.AddSeconds(5), Values = new[] { 60d }
                });


                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var timeSeriesRangeResult = store.Operations.Send(
                    new GetTimeSeriesOperation(documentId, "Heartrate", DateTime.MinValue, DateTime.MaxValue));

                Assert.Equal(3, timeSeriesRangeResult.Entries.Length);

                var value = timeSeriesRangeResult.Entries[0];

                Assert.Equal(59d, value.Values[0]);
                Assert.Equal("watches/fitbit", value.Tag);
                Assert.Equal(baseline.AddSeconds(1), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                value = timeSeriesRangeResult.Entries[1];

                Assert.Equal(61d, value.Values[0]);
                Assert.Equal("watches/fitbit", value.Tag);
                Assert.Equal(baseline.AddSeconds(2), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                value = timeSeriesRangeResult.Entries[2];

                Assert.Equal(60d, value.Values[0]);
                Assert.Equal("watches/apple-watch", value.Tag);
                Assert.Equal(baseline.AddSeconds(5), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);
            }
        }
예제 #2
0
        public void CanGetAll_WithPaging()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 360; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddSeconds(i * 10),
                        Values    = new[] { 59d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var re = store.GetRequestExecutor();
                using (re.ContextPool.AllocateOperationContext(out var context))
                {
                    var tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, new List <TimeSeriesRange>
                    {
                        new TimeSeriesRange
                        {
                            Name = "Heartrate",
                            From = DateTime.MinValue,
                            To   = DateTime.MaxValue
                        }
                    }, start: 100, pageSize: 200);
                    re.Execute(tsCommand, context);
                    var res = tsCommand.Result;

                    Assert.Equal(1, res.Values.Count);
                    Assert.Equal(1, res.Values["Heartrate"].Count);
                    Assert.Equal(200, res.Values["Heartrate"][0].Entries.Length);

                    Assert.Equal(baseline.AddSeconds(100 * 10), res.Values["Heartrate"][0].Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddSeconds(299 * 10), res.Values["Heartrate"][0].Entries[199].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                }
            }
        }
예제 #3
0
        public void GetMultipleTimeSeriesShouldThrowOnMissingNameFromRange()
        {
            using (var store = GetDocumentStore())
            {
                var documentId = "users/ayende";

                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 72d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var ex = Assert.Throws <InvalidOperationException>(() => store.Operations.Send(
                                                                       new GetMultipleTimeSeriesOperation("users/ayende", new List <TimeSeriesRange>
                {
                    new TimeSeriesRange
                    {
                        From = baseline,
                        To   = DateTime.MaxValue
                    }
                })));

                Assert.Contains("'Name' cannot be null or empty", ex.Message);
            }
        }
예제 #4
0
        public void ShouldThrowOnNullOrEmptyRanges()
        {
            using (var store = GetDocumentStore())
            {
                var documentId = "users/ayende";
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = RavenTestHelper.UtcToday;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 72d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation("users/ayende", timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);
                var ex = Assert.Throws <ArgumentNullException>(() => store.Operations.Send(
                                                                   new GetMultipleTimeSeriesOperation("users/ayende", null)));

                Assert.Contains("Value cannot be null. (Parameter 'ranges')", ex.Message);

                var ex2 = Assert.Throws <InvalidOperationException>(() => store.Operations.Send(
                                                                        new GetMultipleTimeSeriesOperation("users/ayende", new List <TimeSeriesRange>())));

                Assert.Contains("'ranges' cannot be null or empty", ex2.Message);
            }
        }
예제 #5
0
        public void ShouldThrowOnAttemptToCreateTimeSeriesOnMissingDocument()
        {
            using (var store = GetDocumentStore())
            {
                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(1), Values = new[] { 59d }
                });

                var timeSeriesBatch = new TimeSeriesBatchOperation("users/ayende", timeSeriesOp);

                var ex = Assert.Throws <DocumentDoesNotExistException>(() => store.Operations.Send(timeSeriesBatch));

                Assert.Contains("Cannot operate on time series of a missing document", ex.Message);
            }
        }
예제 #6
0
        public void GetTimeSeriesShouldThrowOnMissingName()
        {
            using (var store = GetDocumentStore())
            {
                var documentId = "users/ayende";

                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = RavenTestHelper.UtcToday;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 72d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var ex = Assert.Throws <ArgumentNullException>(() => store.Operations.Send(
                                                                   new GetTimeSeriesOperation("users/ayende", string.Empty, baseline, DateTime.MaxValue)));

                Assert.Contains("Value cannot be null", ex.Message);
            }
        }
예제 #7
0
        public void CanAvoidPassingTagInBatchOperation()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = RavenTestHelper.UtcToday;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Timestamp = baseline.AddSeconds(1), Values = new[] { 59d }
                });
                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var rangeResult = store.Operations.Send(
                    new GetTimeSeriesOperation("users/ayende", "Heartrate", DateTime.MinValue, DateTime.MaxValue));

                Assert.Equal(1, rangeResult.Entries.Length);

                var value = rangeResult.Entries[0];

                Assert.Equal(59d, value.Values[0]);
                Assert.Null(value.Tag);
                Assert.Equal(baseline.AddSeconds(1), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);
            }
        }
예제 #8
0
        public void CanGetNonExistedRange()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), "users/ayende");
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(1), Values = new[] { 59d }
                });

                var timeSeriesBatch = new TimeSeriesBatchOperation("users/ayende", timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var timeSeriesRangeResult = store.Operations.Send(
                    new GetTimeSeriesOperation("users/ayende", "Heartrate", baseline.AddMonths(-2), baseline.AddMonths(-1)));

                Assert.Empty(timeSeriesRangeResult.Entries);

                using (var session = store.OpenSession())
                {
                    var query = session.Query <User>().Select(u => RavenQuery.TimeSeries(u, "Heartrate", baseline.AddMonths(-2), baseline.AddMonths(-1)).ToList()).ToList();
                    Assert.Equal(0, query[0].Results.Length);
                }
            }
        }
예제 #9
0
        public void GetRangesShouldReturnNotModifiedCode_WithPaging()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 360; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddSeconds(i * 10),
                        Values    = new[] { 59d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var re = store.GetRequestExecutor();
                using (re.ContextPool.AllocateOperationContext(out var context))
                {
                    var ranges = new List <TimeSeriesRange>
                    {
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(5), To = baseline.AddMinutes(10)
                        },
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(15), To = baseline.AddMinutes(30)
                        },
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(40), To = baseline.AddMinutes(60)
                        }
                    };

                    GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand tsCommand;

                    for (int i = 0; i < 3; i++)
                    {
                        tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, ranges, 10, 150);
                        re.Execute(tsCommand, context);
                        var timesSeriesDetails = tsCommand.Result;

                        if (i == 0)
                        {
                            Assert.Equal(HttpStatusCode.OK, tsCommand.StatusCode);
                        }
                        else
                        {
                            Assert.Equal(HttpStatusCode.NotModified, tsCommand.StatusCode);
                        }

                        Assert.Equal(documentId, timesSeriesDetails.Id);
                        Assert.Equal(1, timesSeriesDetails.Values.Count);
                        Assert.Equal(3, timesSeriesDetails.Values["Heartrate"].Count);

                        var range = timesSeriesDetails.Values["Heartrate"][0];

                        Assert.Equal(baseline.AddMinutes(6).AddSeconds(40), range.From, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(10), range.To, RavenTestHelper.DateTimeComparer.Instance);

                        Assert.Equal(21, range.Entries.Length);
                        Assert.Equal(baseline.AddMinutes(6).AddSeconds(40), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(10), range.Entries[20].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                        range = timesSeriesDetails.Values["Heartrate"][1];

                        Assert.Equal(baseline.AddMinutes(15), range.From, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(30), range.To, RavenTestHelper.DateTimeComparer.Instance);

                        Assert.Equal(91, range.Entries.Length);
                        Assert.Equal(baseline.AddMinutes(15), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(30), range.Entries[90].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                        range = timesSeriesDetails.Values["Heartrate"][2];

                        Assert.Equal(baseline.AddMinutes(40), range.From, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(46).AddSeconds(10), range.To, RavenTestHelper.DateTimeComparer.Instance);

                        Assert.Equal(38, range.Entries.Length);
                        Assert.Equal(baseline.AddMinutes(40), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                        Assert.Equal(baseline.AddMinutes(46).AddSeconds(10), range.Entries[37].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                    }

                    using (var session = store.OpenSession())
                    {
                        // add a new entry to the series
                        session.TimeSeriesFor(documentId, "Heartrate").Append(baseline.AddMinutes(15).AddMilliseconds(50), new[] { 1000d }, "watches/apple");
                        session.SaveChanges();
                    }

                    // verify that we don't get cached results

                    tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, ranges, 10, 150);
                    re.Execute(tsCommand, context);

                    Assert.Equal(HttpStatusCode.OK, tsCommand.StatusCode);

                    var newEntry = tsCommand.Result.Values["Heartrate"][1].Entries
                                   .FirstOrDefault(e => e.Value == 1000d && e.Timestamp == baseline.AddMinutes(15).AddMilliseconds(50).ToUniversalTime());

                    Assert.NotNull(newEntry);

                    // request with a different 'start'
                    // verify that we don't get cached results

                    tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, new List <TimeSeriesRange>
                    {
                        new TimeSeriesRange()
                        {
                            Name = "Heartrate",
                            From = DateTime.MinValue,
                            To   = DateTime.MaxValue
                        }
                    }, start: 12, pageSize: 150);
                    re.Execute(tsCommand, context);

                    Assert.Equal(HttpStatusCode.OK, tsCommand.StatusCode);

                    Assert.Equal(baseline.AddSeconds(12 * 10), tsCommand.Result.Values["Heartrate"][0].Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                }
            }
        }
예제 #10
0
        public void CanGetRanges_WithPaging()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 360; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddSeconds(i * 10),
                        Values    = new[] { 59d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var re = store.GetRequestExecutor();
                using (re.ContextPool.AllocateOperationContext(out var context))
                {
                    var ranges = new List <TimeSeriesRange>
                    {
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(5), To = baseline.AddMinutes(10)
                        },
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(15), To = baseline.AddMinutes(30)
                        },
                        new TimeSeriesRange
                        {
                            Name = "Heartrate", From = baseline.AddMinutes(40), To = baseline.AddMinutes(60)
                        }
                    };

                    var tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, ranges, 10, 150);
                    re.Execute(tsCommand, context);
                    var timesSeriesDetails = tsCommand.Result;

                    Assert.Equal(documentId, timesSeriesDetails.Id);
                    Assert.Equal(1, timesSeriesDetails.Values.Count);
                    Assert.Equal(3, timesSeriesDetails.Values["Heartrate"].Count);

                    Assert.Null(timesSeriesDetails.Values["Heartrate"][0].TotalResults);

                    var range = timesSeriesDetails.Values["Heartrate"][0];

                    Assert.Equal(baseline.AddMinutes(6).AddSeconds(40), range.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(10), range.To, RavenTestHelper.DateTimeComparer.Instance);

                    Assert.Equal(21, range.Entries.Length);
                    Assert.Equal(baseline.AddMinutes(6).AddSeconds(40), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(10), range.Entries[20].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                    range = timesSeriesDetails.Values["Heartrate"][1];

                    Assert.Equal(baseline.AddMinutes(15), range.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(30), range.To, RavenTestHelper.DateTimeComparer.Instance);

                    Assert.Equal(91, range.Entries.Length);
                    Assert.Equal(baseline.AddMinutes(15), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(30), range.Entries[90].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                    range = timesSeriesDetails.Values["Heartrate"][2];

                    Assert.Equal(baseline.AddMinutes(40), range.From, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(46).AddSeconds(10), range.To, RavenTestHelper.DateTimeComparer.Instance);

                    Assert.Equal(38, range.Entries.Length);
                    Assert.Equal(baseline.AddMinutes(40), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                    Assert.Equal(baseline.AddMinutes(46).AddSeconds(10), range.Entries[37].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                }
            }
        }
예제 #11
0
        public void GetAllShouldReturnNotModifiedCode()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 360; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddSeconds(i * 10),
                        Values    = new[] { 59d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var re = store.GetRequestExecutor();
                using (re.ContextPool.AllocateOperationContext(out var context))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var tsCommand = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId, new List <TimeSeriesRange>
                        {
                            new TimeSeriesRange
                            {
                                Name = "Heartrate",
                                From = DateTime.MinValue,
                                To   = DateTime.MaxValue
                            }
                        }, start: 0, pageSize: int.MaxValue);

                        re.Execute(tsCommand, context);
                        var res = tsCommand.Result;

                        Assert.Equal(361, res.Values["Heartrate"][0].TotalResults);
                        Assert.Equal(1, res.Values.Count);
                        Assert.Equal(1, res.Values["Heartrate"].Count);
                        Assert.Equal(361, res.Values["Heartrate"][0].Entries.Length);

                        var statusCode = tsCommand.StatusCode;

                        if (i == 0)
                        {
                            Assert.Equal(HttpStatusCode.OK, statusCode);
                        }
                        else
                        {
                            Assert.Equal(HttpStatusCode.NotModified, statusCode);
                        }
                    }

                    using (var session = store.OpenSession())
                    {
                        // add a new entry to the series
                        session.TimeSeriesFor(documentId, "Heartrate").Append(baseline.AddSeconds(100).AddMilliseconds(50), new[] { 1000d }, "watches/apple");
                        session.SaveChanges();
                    }

                    // verify that we don't get cached results

                    var command = new GetMultipleTimeSeriesOperation.GetMultipleTimeSeriesCommand(documentId,
                                                                                                  new List <TimeSeriesRange>
                    {
                        new TimeSeriesRange
                        {
                            Name = "Heartrate",
                            From = DateTime.MinValue,
                            To   = DateTime.MaxValue
                        }
                    }, 0, int.MaxValue);
                    re.Execute(command, context);

                    Assert.Equal(HttpStatusCode.OK, command.StatusCode);

                    Assert.Equal(362, command.Result.Values["Heartrate"][0].TotalResults);
                    Assert.Equal(1, command.Result.Values.Count);
                    Assert.Equal(1, command.Result.Values["Heartrate"].Count);
                    Assert.Equal(362, command.Result.Values["Heartrate"][0].Entries.Length);

                    var newEntry = command.Result.Values["Heartrate"][0].Entries
                                   .FirstOrDefault(e => e.Value == 1000d && e.Timestamp == baseline.AddSeconds(100).AddMilliseconds(50).ToUniversalTime());

                    Assert.NotNull(newEntry);
                }
            }
        }
예제 #12
0
        public void CanGetMultipleTimeSeriesInSingleRequest()
        {
            using (var store = GetDocumentStore())
            {
                var documentId = "users/ayende";
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                // append

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 72d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "BloodPressure",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 80d }
                    });
                }

                timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Temperature",
                };

                for (int i = 0; i <= 10; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Timestamp = baseline.AddMinutes(i * 10),
                        Values    = new[] { 37d + i * 0.15 }
                    });
                }

                timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                // get ranges from multiple time series in a single request

                var timesSeriesDetails = store.Operations.Send(
                    new GetMultipleTimeSeriesOperation(documentId, new List <TimeSeriesRange>
                {
                    new TimeSeriesRange
                    {
                        Name = "Heartrate",
                        From = baseline,
                        To   = baseline.AddMinutes(15)
                    },
                    new TimeSeriesRange
                    {
                        Name = "Heartrate",
                        From = baseline.AddMinutes(30),
                        To   = baseline.AddMinutes(45)
                    },
                    new TimeSeriesRange
                    {
                        Name = "BloodPressure",
                        From = baseline,
                        To   = baseline.AddMinutes(30)
                    },
                    new TimeSeriesRange
                    {
                        Name = "BloodPressure",
                        From = baseline.AddMinutes(60),
                        To   = baseline.AddMinutes(90)
                    },
                    new TimeSeriesRange
                    {
                        Name = "Temperature",
                        From = baseline,
                        To   = baseline.AddDays(1)
                    }
                }));

                Assert.Equal("users/ayende", timesSeriesDetails.Id);
                Assert.Equal(3, timesSeriesDetails.Values.Count);

                Assert.Equal(2, timesSeriesDetails.Values["Heartrate"].Count);

                var range = timesSeriesDetails.Values["Heartrate"][0];

                Assert.Equal(baseline, range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(15), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(2, range.Entries.Length);
                Assert.Equal(baseline, range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(10), range.Entries[1].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Null(range.TotalResults);

                range = timesSeriesDetails.Values["Heartrate"][1];

                Assert.Equal(baseline.AddMinutes(30), range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(45), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(2, range.Entries.Length);
                Assert.Equal(baseline.AddMinutes(30), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(40), range.Entries[1].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Null(range.TotalResults);

                Assert.Equal(2, timesSeriesDetails.Values["BloodPressure"].Count);

                range = timesSeriesDetails.Values["BloodPressure"][0];

                Assert.Equal(baseline, range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(30), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(4, range.Entries.Length);
                Assert.Equal(baseline, range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(30), range.Entries[3].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Null(range.TotalResults);

                range = timesSeriesDetails.Values["BloodPressure"][1];

                Assert.Equal(baseline.AddMinutes(60), range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(90), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(4, range.Entries.Length);
                Assert.Equal(baseline.AddMinutes(60), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(90), range.Entries[3].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Null(range.TotalResults);

                Assert.Equal(1, timesSeriesDetails.Values["Temperature"].Count);

                range = timesSeriesDetails.Values["Temperature"][0];

                Assert.Equal(baseline, range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddDays(1), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(11, range.Entries.Length);
                Assert.Equal(baseline, range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(100), range.Entries[10].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(11, range.TotalResults); // full range
            }
        }
예제 #13
0
        public void CanGetMultipleRangesInSingleRequest()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                for (int i = 0; i <= 360; i++)
                {
                    timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation
                    {
                        Tag       = "watches/fitbit",
                        Timestamp = baseline.AddSeconds(i * 10),
                        Values    = new[] { 59d }
                    });
                }

                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var timesSeriesDetails = store.Operations.Send(
                    new GetMultipleTimeSeriesOperation(documentId, new List <TimeSeriesRange>
                {
                    new TimeSeriesRange
                    {
                        Name = "Heartrate",
                        From = baseline.AddMinutes(5),
                        To   = baseline.AddMinutes(10)
                    },

                    new TimeSeriesRange
                    {
                        Name = "Heartrate",
                        From = baseline.AddMinutes(15),
                        To   = baseline.AddMinutes(30)
                    },

                    new TimeSeriesRange
                    {
                        Name = "Heartrate",
                        From = baseline.AddMinutes(40),
                        To   = baseline.AddMinutes(60)
                    }
                }));

                Assert.Equal(documentId, timesSeriesDetails.Id);
                Assert.Equal(1, timesSeriesDetails.Values.Count);
                Assert.Equal(3, timesSeriesDetails.Values["Heartrate"].Count);

                var range = timesSeriesDetails.Values["Heartrate"][0];

                Assert.Equal(baseline.AddMinutes(5), range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(10), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(31, range.Entries.Length);
                Assert.Equal(baseline.AddMinutes(5), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(10), range.Entries[30].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                range = timesSeriesDetails.Values["Heartrate"][1];

                Assert.Equal(baseline.AddMinutes(15), range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(30), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(91, range.Entries.Length);
                Assert.Equal(baseline.AddMinutes(15), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(30), range.Entries[90].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                range = timesSeriesDetails.Values["Heartrate"][2];

                Assert.Equal(baseline.AddMinutes(40), range.From, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(60), range.To, RavenTestHelper.DateTimeComparer.Instance);

                Assert.Equal(121, range.Entries.Length);
                Assert.Equal(baseline.AddMinutes(40), range.Entries[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                Assert.Equal(baseline.AddMinutes(60), range.Entries[120].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
            }
        }
예제 #14
0
        public void CanAppendAndRemoveTimestampsInSingleBatch()
        {
            const string documentId = "users/ayende";

            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new User(), documentId);
                    session.SaveChanges();
                }

                var baseline = DateTime.Today;

                var timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(1), Values = new[] { 59d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(2), Values = new[] { 61d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(3), Values = new[] { 61.5d }
                });


                var timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                var timeSeriesRangeResult = store.Operations.Send(
                    new GetTimeSeriesOperation(documentId, "Heartrate", DateTime.MinValue, DateTime.MaxValue));

                Assert.Equal(3, timeSeriesRangeResult.Entries.Length);

                timeSeriesOp = new TimeSeriesOperation
                {
                    Name = "Heartrate",
                };

                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(4), Values = new[] { 60d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(5), Values = new[] { 62.5d }
                });
                timeSeriesOp.Append(new TimeSeriesOperation.AppendOperation {
                    Tag = "watches/fitbit", Timestamp = baseline.AddSeconds(6), Values = new[] { 62d }
                });
                timeSeriesOp.Delete(new TimeSeriesOperation.DeleteOperation {
                    From = baseline.AddSeconds(2), To = baseline.AddSeconds(3)
                });

                timeSeriesBatch = new TimeSeriesBatchOperation(documentId, timeSeriesOp);

                store.Operations.Send(timeSeriesBatch);

                timeSeriesRangeResult = store.Operations.Send(
                    new GetTimeSeriesOperation(documentId, "Heartrate", DateTime.MinValue, DateTime.MaxValue));

                Assert.Equal(4, timeSeriesRangeResult.Entries.Length);

                var value = timeSeriesRangeResult.Entries[0];
                Assert.Equal(59d, value.Values[0]);
                Assert.Equal(baseline.AddSeconds(1), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                value = timeSeriesRangeResult.Entries[1];
                Assert.Equal(60d, value.Values[0]);
                Assert.Equal(baseline.AddSeconds(4), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                value = timeSeriesRangeResult.Entries[2];
                Assert.Equal(62.5d, value.Values[0]);
                Assert.Equal(baseline.AddSeconds(5), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                value = timeSeriesRangeResult.Entries[3];
                Assert.Equal(62d, value.Values[0]);
                Assert.Equal(baseline.AddSeconds(6), value.Timestamp, RavenTestHelper.DateTimeComparer.Instance);
            }

            using (var store = GetDocumentStore())
            {
                var baseline = DateTime.Today;

                using (var session = store.OpenSession())
                {
                    session.Store(new { Name = "Oren" }, documentId);
                    session.TimeSeriesFor(documentId, "Heartrate")
                    .Append(baseline.AddMinutes(1), new[] { 59d }, "watches/fitbit");
                    session.TimeSeriesFor(documentId, "Heartrate")
                    .Append(baseline.AddMinutes(2), new[] { 69d }, "watches/fitbit");
                    session.TimeSeriesFor(documentId, "Heartrate")
                    .Append(baseline.AddMinutes(3), new[] { 79d }, "watches/fitbit");

                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    session.Store(new { Name = "Oren" }, documentId);
                    session.TimeSeriesFor(documentId, "Heartrate")
                    .Delete(baseline.AddMinutes(2));

                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var vals = session.TimeSeriesFor(documentId, "Heartrate")
                               .Get(DateTime.MinValue, DateTime.MaxValue)
                               .ToList();
                    Assert.Equal(2, vals.Count);
                    Assert.Equal(new[] { 59d }, vals[0].Values);
                    Assert.Equal("watches/fitbit", vals[0].Tag);
                    Assert.Equal(baseline.AddMinutes(1), vals[0].Timestamp, RavenTestHelper.DateTimeComparer.Instance);

                    Assert.Equal(new[] { 79d }, vals[1].Values);
                    Assert.Equal("watches/fitbit", vals[1].Tag);
                    Assert.Equal(baseline.AddMinutes(3), vals[1].Timestamp, RavenTestHelper.DateTimeComparer.Instance);
                }
            }
        }