예제 #1
0
 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);
 }
예제 #2
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
        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)
            };
        }
예제 #5
0
        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();
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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();
        }
예제 #9
0
 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);
 }
예제 #10
0
 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);
 }
예제 #11
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);
 }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
 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);
 }
예제 #15
0
 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);
 }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
        }
예제 #21
0
        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);
        }
예제 #22
0
        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);
        }
예제 #23
0
        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)
            };
        }
예제 #24
0
        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);
        }
예제 #25
0
        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);
        }
예제 #26
0
        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);
        }
예제 #27
0
        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();
        }
예제 #28
0
        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);
        }
예제 #29
0
        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);
        }
예제 #30
0
        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);
        }
예제 #31
0
        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)
            };
        }
예제 #32
0
 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;
 }
예제 #33
0
        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)
            };
        }
예제 #34
0
 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);
 }
예제 #35
0
 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);
 }
예제 #36
0
        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);
        }