Exemplo n.º 1
0
        public T?MeanExpWeighted()
        {
            if (!Rows.Any())
            {
                return(null);
            }
            var      rows  = Rows;
            DateTime start = DateTime.MinValue;
            DateTime stop  = rows.Last().TimeUtc;

            if (StartTime != null)
            {
                start = StartTime.Value;
            }

            if (NextRow != null && EndTime != null)
            {
                stop = EndTime.Value;
            }

            var diff             = stop - start;
            var timeSpanSubGroup = TimeSpan.FromTicks((diff.Ticks + (NumberOfExpFactors * 2)) / ExponentialFactors.Length);
            var newSerie         = new QuerySerie <T>(Rows, start, stop)
            {
                PreviousRow = PreviousRow, NextRow = NextRow
            };
            var subGroups =
                newSerie.Group(g => g.ByTime.Span(timeSpanSubGroup).Aggregate(f => f.MeanByTimeIncludePreviousAndNext()))
                .RemoveNulls();

            if (subGroups.Rows.Count != ExponentialFactors.Length)
            {
                Logger.Warn($"Subgroups count is {subGroups.Rows.Count}, instead of {ExponentialFactors.Length}");
                return(subGroups.MeanByTime()?.ToType <T>());
            }
            Debug.Assert(subGroups.Rows.Count == ExponentialFactors.Length);
            var subRows = subGroups.Rows;

            double sum = 0;

            for (int i = 0; i < subRows.Count; i++)
            {
                sum += subRows[i].Value.ToDouble() * ExponentialFactors[i];
            }

            double result = sum / ExpSum;

            return(result.ToType <T>());
        }
Exemplo n.º 2
0
        public IQuerySerie <T> CalcValue(Func <T, T> calculationFunc, string newSerieName = null)
        {
            var rows = new List <ISingleDataRow <T> >(Rows.Count);

            if (Rows.Any())
            {
                rows.AddRange(Rows.Select(row => new SingleDataRow <T>(row.TimeUtc, calculationFunc(row.Value))));
            }
            var newSerie = new QuerySerie <T>(rows, this);

            if (newSerieName != null)
            {
                newSerie.Name = newSerieName;
            }
            return(newSerie);
        }
Exemplo n.º 3
0
        public override IObjectQuerySerieBase GetOrCreateSerie(string name)
        {
            var serie = TryGetSerie(name);

            if (serie == null)
            {
                var firstSerie = Series.Values.FirstOrDefault();
                if (firstSerie != null)
                {
                    var newSerie = new QuerySerie <T>(new List <ISingleDataRow <T> >(firstSerie.Rows.Select(i => new SingleDataRow <T>(i.Key, default(T)))), firstSerie.StartTime, firstSerie.EndTime);
                    AddSerie(newSerie);
                    serie = newSerie;
                }
            }
            return(serie);
        }