Ejemplo n.º 1
0
        public void GroupByGroupTimesStartBeforeStartOfSerie()
        {
            var serie = PrepareForGroupTests();
            var startTime = new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc) - TimeSpan.FromMinutes(1);
            StartEndTime groupTime = new StartEndTime(startTime, new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc));
            ;

            var result = serie.Group(g => g.ByTimeRanges(new[] {groupTime}).Aggregate(i => i.MeanByTime()));
            result.Rows.Count.Should().Be(1);
            result.Rows[0].TimeUtc.Should().Be(startTime);
            result.Rows[0].Value.Should().BeLessThan(4.2f);
        }
Ejemplo n.º 2
0
        public void GroupByGroupTimesStartWithPrevAndNext()
        {
            var serie = PrepareForGroupTests();
            var startTime = new DateTime(1000, 1, 1, 0, 2, 0, DateTimeKind.Utc);
            StartEndTime groupTime = new StartEndTime(startTime, new DateTime(1000, 1, 1, 0, 9, 0, DateTimeKind.Utc));
            ;

            var result = serie.Group(g => g.ByTimeRanges(new[] {groupTime}).Aggregate(i => i.MeanByTime()));
            result.Rows.Count.Should().Be(1);
            result.Rows[0].TimeUtc.Should().Be(startTime);
            result.Rows[0].Value.Should().BeApproximately(4.285f, 3);
        }
Ejemplo n.º 3
0
        public void GroupByGroupTimes1()
        {
            var serie = PrepareForGroupTests();
            StartEndTime groupTime = new StartEndTime(new DateTime(1000, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(1000, 1, 1, 0, 10, 0, DateTimeKind.Utc));
            ;

            //var result = serie.GroupBy(new[] { groupTime }, i => i.MeanByTime());
            var result = serie.Group(g => g.ByTimeRanges(new[] {groupTime}).Aggregate(i => i.MeanByTime()));
            result.Rows.Count.Should().Be(1);
            result.Rows[0].TimeUtc.Should().Be(new DateTime(1000, 1, 1, 0, 0, 0));
            result.Rows[0].Value.Should().Be(4.2f);
        }
Ejemplo n.º 4
0
        public static IReadOnlyList<StartEndTime> CombineByTolerance(this IReadOnlyList<StartEndTime> groups,
            TimeSpan tolerance)
        {
            var newGroups = new List<StartEndTime>(groups.Count);
            var previous = groups.First();
            for (var i = 1; i < groups.Count; i++)
            {
                var current = groups[i];
                if ((current.Start - previous.End) <= tolerance)
                {
                    previous = new StartEndTime(previous.Start, current.End > previous.End ? current.End : previous.End);
                }
                else
                {
                    newGroups.Add(previous);
                    previous = current;
                }
            }
            newGroups.Add(previous);

            return newGroups;
        }