public void WithoutPrevAndNext() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.MeanByTime(); result.Should().Be(3.75f); }
public void Setup() { var unitUnderTest50 = new List <ISingleDataRow <float> >(); var unitUnderTest50Int = new List <ISingleDataRow <int> >(); var unitUnderTest50Even = new List <ISingleDataRow <float> >(); int items = 1000; int items50 = 50; var startDate = new DateTime(2010, 1, 1, 13, 27, 14, DateTimeKind.Utc); var startDateEven = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc); var current40S = startDate; var current40SEven = startDateEven; for (int i = 0; i < items; i++) { //unitUnderTest1000.Add(new SingleDataRow<float>(current40s, 0.5f * i )); if (i < items50) { unitUnderTest50.Add(new SingleDataRow <float>(current40S, 0.5f * i)); unitUnderTest50Int.Add(new SingleDataRow <int>(current40S, i)); unitUnderTest50Even.Add(new SingleDataRow <float>(current40SEven, 0.5f * i)); } current40S += TimeSpan.FromSeconds(40); current40SEven += TimeSpan.FromSeconds(60); } //_unitUnderTest1000 = new QuerySerie<float>(unitUnderTest1000, startDate, null); _unitUnderTest50 = new QuerySerie <float>(unitUnderTest50, startDate, null); _unitUnderTest50Int = new QuerySerie <int>(unitUnderTest50Int, startDate, null); _unitUnderTest50Even = new QuerySerie <float>(unitUnderTest50Even, startDateEven, null); }
public void DynamicSerieTests() { DummyLambda(a => a); Dummy(3); const int max = 100000; var start = new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc); var rowsA = new List<ISingleDataRow<int>>(); var rowsB = new List<ISingleDataRow<int>>(); for (var i = 0; i < max; i++) { rowsA.Add(new SingleDataRow<int>(start + TimeSpan.FromMinutes(i), i)); rowsB.Add(new SingleDataRow<int>(start + TimeSpan.FromMinutes(i), i*2)); } var serieA = new QuerySerie<int>(rowsA, start, start + TimeSpan.FromMinutes(max)) {Name = "A", Key = "A"}; var serieB = new QuerySerie<int>(rowsB, start, start + TimeSpan.FromMinutes(max)) {Name = "B", Key = "B"}; var table = new QueryTable<int>(); table.AddSerie(serieA); table.AddSerie(serieB); //var sw = Stopwatch.StartNew(); //var result = table.Do(i => i.GroupByHours(1, t => t.Mean())).ZipToNew<int>("SumTable", t => t.A + t.B); //sw.Stop(); var sw2 = Stopwatch.StartNew(); var result2 = table.Transform(i => i.GroupByMinutes(1, t => t.First())) .ZipToNew("DiffTable", t => t.A - t.B); sw2.Stop(); }
public void Setup() { _rows.Clear(); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 1, 0, DateTimeKind.Utc), 2)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 2, 0, DateTimeKind.Utc), 4)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 8, 0, DateTimeKind.Utc), 6)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 14, 0, DateTimeKind.Utc), 5)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 17, 0, DateTimeKind.Utc), 4)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 18, 0, DateTimeKind.Utc), 6)); _rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc), 8)); _serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 22, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; _serie2 = new QuerySerie <float>(_rows.Take(6).ToList(), new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; _serie3 = new QuerySerie <float>(_rows.Take(7).ToList(), new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; }
public void IncludeLastRowTest() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.IncludeLastRow(); result.IncludeLastRow().Should().NotBeNull(); }
public void WithoutPrevAndNext() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.MeanByTime(); result.Should().Be(3.75f); }
public void WhereValueTest() { IQuerySerie <float> serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var newSerie2 = serie.WhereValue(i => i >= 4); serie.Rows.Count.Should().Be(3); newSerie2.Rows.Count.Should().Be(2); }
public void IncludeLastRowTest() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.IncludeLastRow(); result.IncludeLastRow().Should().NotBeNull(); }
public void WithoutPrev() { var serie = new QuerySerie<float>(_rows, new DateTime(999, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.MeanByTime(); result.Should().Be(4.2f); }
public void ConditionNotFound() { var serie = new QuerySerie<float>(_rows, new DateTime(999, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 7f)?.TotalMinutes; result.Should().Be(0); }
public void WithoutPrev() { var serie = new QuerySerie<float>(_rows, new DateTime(999, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 6f).Value.TotalMinutes; result.Should().Be(2f); }
public void WithoutPrev() { var serie = new QuerySerie <float>(_rows, new DateTime(999, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.MeanByTime(); result.Should().Be(4.2f); }
public override INullableQuerySerie <T> ExecuteGrouping() { var rows = Serie.Rows; if (!rows.Any() || !GroupTimes.Any()) { return(new NullableQuerySerie <T>(new List <ISingleDataRow <T?> >(), Serie)); } int index = 0; var max = rows.Count; var result = new List <ISingleDataRow <T?> >(); int?nextTimeRangeIndex = null; for (int groupIndex = 0; groupIndex < GroupTimes.Count; groupIndex++) { StartEndTime groupTime = GroupTimes[groupIndex]; StartEndTime nextGroupTime = (groupIndex + 1 < GroupTimes.Count) ? GroupTimes[groupIndex + 1] : null; var group = new List <ISingleDataRow <T> >(); while (index < max && rows[index].TimeUtc < groupTime.Start) { index++; } var startIndex = index; while (index < max && rows[index].TimeUtc < groupTime.End) { group.Add(rows[index]); if (nextTimeRangeIndex == null && nextGroupTime != null && rows[index].TimeUtc > nextGroupTime.Start) { nextTimeRangeIndex = Math.Max(index - 1, 0); } index++; } var aggregationData = new QuerySerie <T>(@group, groupTime.Start, groupTime.End) { PreviousRow = startIndex > 0 ? rows[startIndex - 1] : Serie.PreviousRow, NextRow = index < max ? rows[index] : Serie.NextRow }; result.Add(new SingleDataRow <T?>(groupTime.GetTimeStampByType(TimeStampType), AggregationFunc(aggregationData))); if (nextTimeRangeIndex != null) { index = nextTimeRangeIndex.Value; nextTimeRangeIndex = null; } } var resultData = new NullableQuerySerie <T>(result, Serie); return(resultData); }
public void FirstItemOnStartTime_PrevRowHasNoImpact() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 10), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 10f).Value.TotalMinutes; result.Should().Be(0f); }
public void FirstItemOnStartTime_PrevRowHasNoImpact() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 10), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.MeanByTime(); result.Should().Be(4.2f); }
private QuerySerie <float> PrepareForGroupTests() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1), new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), -3), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 16, 0, DateTimeKind.Utc), 11) }; return(serie); }
public void ConditionNotFound() { var serie = new QuerySerie <float>(_rows, new DateTime(999, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 7f)?.TotalMinutes; result.Should().Be(0); }
public void WithoutPrev() { var serie = new QuerySerie <float>(_rows, new DateTime(999, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 6f).Value.TotalMinutes; result.Should().Be(2f); }
public void FirstItemOnStartTime_PrevRowHasNoImpact() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 10), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.MeanByTime(); result.Should().Be(4.2f); }
public void FirstItemOnStartTime_PrevRowHasNoImpact() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 10), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 10f).Value.TotalMinutes; result.Should().Be(0f); }
public void WithoutPrevAndNext() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.TimeWhere(v => v == 4f).Value.TotalMinutes; result.Should().Be(7f); result = serie.TimeWhere(v => v == 6f).Value.TotalMinutes; result.Should().Be(0f); }
public void WithPrevAndNext() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc) - TimeSpan.FromMinutes(5), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(999, 1, 1, 0, 11, 0, DateTimeKind.Utc), 9.6f), NextRow = new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.TimeWhere(v => v == 9.6f)?.TotalMinutes; result.Should().Be(5f); }
public void Setup() { var unitUnderTest40s = new List <ISingleDataRow <float> >(); var unitUnderTest9m = new List <ISingleDataRow <float> >(); var unitUnderTest5h = new List <ISingleDataRow <float> >(); var unitUnderTest9mNotTrimmed = new List <ISingleDataRow <float> >(); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 0, 0, 0), -1f)); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 0, 0, 1), -0.5f)); int items = 100; var startDate = new DateTime(2010, 1, 1, 13, 27, 14, DateTimeKind.Utc); var startDate5h = new DateTime(2010, 5, 19, 13, 27, 14, DateTimeKind.Utc); var current40s = startDate; var current9m = startDate; var current5h = startDate5h; for (int i = 0; i < items; i++) { unitUnderTest40s.Add(new SingleDataRow <float>(current40s, 0.5f * i)); unitUnderTest9m.Add(new SingleDataRow <float>(current9m, 0.5f * i)); if (i < 10) { unitUnderTest9mNotTrimmed.Add(new SingleDataRow <float>(current9m, 0.5f * i)); } current40s += TimeSpan.FromSeconds(40); current9m += TimeSpan.FromMinutes(9); } for (int i = 0; i < 10000; i++) { unitUnderTest5h.Add(new SingleDataRow <float>(current5h, 0.5f * i)); current5h += TimeSpan.FromHours(5); } //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 15, 0, 1), -99f)); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 15, 0, 2), -99.5f)); _trimEndDate = new DateTime(2010, 1, 1, 15, 1, 0, DateTimeKind.Utc); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(_trimEndDate, -99.5f)); _unitUnderTest40s = new QuerySerie <float>(unitUnderTest40s, startDate, null); _unitUnderTest9m = new QuerySerie <float>(unitUnderTest9m, startDate, null); _unitUnderTest5h = new QuerySerie <float>(unitUnderTest5h, startDate5h, null); _unitUnderTest9mNotTrimmed = new QuerySerie <float>(unitUnderTest9mNotTrimmed, new DateTime(2010, 1, 1, 13, 0, 0, DateTimeKind.Utc), new DateTime(2010, 1, 1, 15, 0, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow <float>(new DateTime(2010, 1, 1, 0, 0, 1, DateTimeKind.Utc), -0.5f), NextRow = new SingleDataRow <float>(new DateTime(2010, 1, 1, 15, 0, 1, DateTimeKind.Utc), -99f) }; }
public void ZipSeriesTest() { var serie = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)).GroupByMinutes(5, i => i.First()); var serie2 = new QuerySerie <float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)).GroupByMinutes(5, i => i.Last()); ; var result = serie.Zip(serie2, "res", (s1, s2) => s1 + s2); result.Name.Should().Be("res"); result.Rows[0].Value.Should().Be(6); result.Rows[1].Value.Should().Be(12); }
public void SawToothWithResetValueOne() { var rows = new List<ISingleDataRow<float>>(); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), 2)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 1, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 8, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 12, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 13, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 14, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc), 6)); var serie = new QuerySerie<float>(rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc)); var normalizedSerie = serie.NormalizeOverflows(1); normalizedSerie.Rows[8].Value.Should().Be(15); }
public void SawToothWithResetValueOne() { var rows = new List <ISingleDataRow <float> >(); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), 2)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 1, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 8, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 12, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 13, 0, DateTimeKind.Utc), 6)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 14, 0, DateTimeKind.Utc), 4)); rows.Add(new SingleDataRow <float>(new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc), 6)); var serie = new QuerySerie <float>(rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc)); var normalizedSerie = serie.NormalizeOverflows(1); normalizedSerie.Rows[8].Value.Should().Be(15); }
public void DynamicSerieTests() { DummyLambda(a => a); Dummy(3); const int max = 100000; var start = new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc); var rowsA = new List <ISingleDataRow <int> >(); var rowsB = new List <ISingleDataRow <int> >(); for (var i = 0; i < max; i++) { rowsA.Add(new SingleDataRow <int>(start + TimeSpan.FromMinutes(i), i)); rowsB.Add(new SingleDataRow <int>(start + TimeSpan.FromMinutes(i), i * 2)); } var serieA = new QuerySerie <int>(rowsA, start, start + TimeSpan.FromMinutes(max)) { Name = "A", Key = "A" }; var serieB = new QuerySerie <int>(rowsB, start, start + TimeSpan.FromMinutes(max)) { Name = "B", Key = "B" }; var table = new QueryTable <int>(); table.AddSerie(serieA); table.AddSerie(serieB); //var sw = Stopwatch.StartNew(); //var result = table.Do(i => i.GroupByHours(1, t => t.Mean())).ZipToNew<int>("SumTable", t => t.A + t.B); //sw.Stop(); var sw2 = Stopwatch.StartNew(); var result2 = table.Transform(i => i.GroupByMinutes(1, t => t.First())) .ZipToNew("DiffTable", t => t.A - t.B); sw2.Stop(); }
private IQuerySerie <T> ReadRows <T>(FileStream fs, BinaryReader binaryReader, DateTime start, DateTime stop, DateTime? @from = null, DateTime?to = null) where T : struct { //TODO: optimize duplicated code with ReadRows ISingleDataRow <T> firstRow = null; var rows = new List <ISingleDataRow <T> >(); var data = new QuerySerie <T>(rows, from, to) { IsDbSerie = true }; while (fs.Position < fs.Length) { var readRow = _rowReaderWriter.ReadRow <T>(binaryReader); if (readRow.TimeUtc >= start) { if (readRow.TimeUtc <= stop) { rows.Add(readRow); } } else { firstRow = readRow; } if (readRow.TimeUtc >= stop) { data.NextRow = readRow; break; } } data.Name = Metadata.Name; data.PreviousRow = firstRow; return(data); }
public void WithoutPrevAndNext() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var result = serie.TimeWhere(v => v == 4f).Value.TotalMinutes; result.Should().Be(7f); result = serie.TimeWhere(v => v == 6f).Value.TotalMinutes; result.Should().Be(0f); }
public void Setup() { var unitUnderTest50 = new List<ISingleDataRow<float>>(); var unitUnderTest50Int = new List<ISingleDataRow<int>>(); var unitUnderTest50Even = new List<ISingleDataRow<float>>(); int items = 1000; int items50 = 50; var startDate = new DateTime(2010, 1, 1, 13, 27, 14, DateTimeKind.Utc); var startDateEven = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc); var current40S = startDate; var current40SEven = startDateEven; for (int i = 0; i < items; i++) { //unitUnderTest1000.Add(new SingleDataRow<float>(current40s, 0.5f * i )); if (i < items50) { unitUnderTest50.Add(new SingleDataRow<float>(current40S, 0.5f*i)); unitUnderTest50Int.Add(new SingleDataRow<int>(current40S, i)); unitUnderTest50Even.Add(new SingleDataRow<float>(current40SEven, 0.5f*i)); } current40S += TimeSpan.FromSeconds(40); current40SEven += TimeSpan.FromSeconds(60); } //_unitUnderTest1000 = new QuerySerie<float>(unitUnderTest1000, startDate, null); _unitUnderTest50 = new QuerySerie<float>(unitUnderTest50, startDate, null); _unitUnderTest50Int = new QuerySerie<int>(unitUnderTest50Int, startDate, null); _unitUnderTest50Even = new QuerySerie<float>(unitUnderTest50Even, startDateEven, null); }
public void Setup() { _rows.Clear(); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 1, 0, DateTimeKind.Utc), 2)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 2, 0, DateTimeKind.Utc), 4)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 8, 0, DateTimeKind.Utc), 6)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 14, 0, DateTimeKind.Utc), 5)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 17, 0, DateTimeKind.Utc), 4)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 18, 0, DateTimeKind.Utc), 6)); _rows.Add(new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc), 8)); _serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 22, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; _serie2 = new QuerySerie<float>(_rows.Take(6).ToList(), new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; _serie3 = new QuerySerie<float>(_rows.Take(7).ToList(), new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 20, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), 8), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 26, 0, DateTimeKind.Utc), 11) }; }
private QuerySerie<float> PrepareForGroupTests() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1), new DateTime(1000, 1, 1, 0, 15, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(99, 1, 1, 0, 11, 0, DateTimeKind.Utc), -3), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 16, 0, DateTimeKind.Utc), 11) }; return serie; }
public void Setup() { var unitUnderTest40s = new List<ISingleDataRow<float>>(); var unitUnderTest9m = new List<ISingleDataRow<float>>(); var unitUnderTest5h = new List<ISingleDataRow<float>>(); var unitUnderTest9mNotTrimmed = new List<ISingleDataRow<float>>(); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 0, 0, 0), -1f)); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 0, 0, 1), -0.5f)); int items = 100; var startDate = new DateTime(2010, 1, 1, 13, 27, 14, DateTimeKind.Utc); var startDate5h = new DateTime(2010, 5, 19, 13, 27, 14, DateTimeKind.Utc); var current40s = startDate; var current9m = startDate; var current5h = startDate5h; for (int i = 0; i < items; i++) { unitUnderTest40s.Add(new SingleDataRow<float>(current40s, 0.5f*i)); unitUnderTest9m.Add(new SingleDataRow<float>(current9m, 0.5f*i)); if (i < 10) { unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(current9m, 0.5f*i)); } current40s += TimeSpan.FromSeconds(40); current9m += TimeSpan.FromMinutes(9); } for (int i = 0; i < 10000; i++) { unitUnderTest5h.Add(new SingleDataRow<float>(current5h, 0.5f*i)); current5h += TimeSpan.FromHours(5); } //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 15, 0, 1), -99f)); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(new DateTime(2010, 1, 1, 15, 0, 2), -99.5f)); _trimEndDate = new DateTime(2010, 1, 1, 15, 1, 0, DateTimeKind.Utc); //unitUnderTest9mNotTrimmed.Add(new SingleDataRow<float>(_trimEndDate, -99.5f)); _unitUnderTest40s = new QuerySerie<float>(unitUnderTest40s, startDate, null); _unitUnderTest9m = new QuerySerie<float>(unitUnderTest9m, startDate, null); _unitUnderTest5h = new QuerySerie<float>(unitUnderTest5h, startDate5h, null); _unitUnderTest9mNotTrimmed = new QuerySerie<float>(unitUnderTest9mNotTrimmed, new DateTime(2010, 1, 1, 13, 0, 0, DateTimeKind.Utc), new DateTime(2010, 1, 1, 15, 0, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(2010, 1, 1, 0, 0, 1, DateTimeKind.Utc), -0.5f), NextRow = new SingleDataRow<float>(new DateTime(2010, 1, 1, 15, 0, 1, DateTimeKind.Utc), -99f) }; }
public void WithPrevAndNext() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc) - TimeSpan.FromMinutes(5), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)) { PreviousRow = new SingleDataRow<float>(new DateTime(999, 1, 1, 0, 11, 0, DateTimeKind.Utc), 9.6f), NextRow = new SingleDataRow<float>(new DateTime(1000, 1, 1, 0, 11, 0, DateTimeKind.Utc), 11) }; var result = serie.MeanByTime(); result.Should().Be(6f); }
public void WhereValueTest() { IQuerySerie<float> serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)); var newSerie2 = serie.WhereValue(i => i >= 4); serie.Rows.Count.Should().Be(3); newSerie2.Rows.Count.Should().Be(2); }
public void ZipSeriesTest() { var serie = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)).GroupByMinutes(5, i => i.First()); var serie2 = new QuerySerie<float>(_rows, new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc)).GroupByMinutes(5, i => i.Last()); ; var result = serie.Zip(serie2, "res", (s1, s2) => s1 + s2); result.Name.Should().Be("res"); result.Rows[0].Value.Should().Be(6); result.Rows[1].Value.Should().Be(12); }