Beispiel #1
0
        /// <summary>
        /// Returns a timestampseries at the required timestep
        /// Returns a new empty timestampseries if no data exists.
        /// </summary>
        /// <param name="TimeStep"></param>
        /// <returns></returns>
        public FixedTimeStepSeries GetTs(TimeStepUnit TimeStep)
        {
            FixedTimeStepSeries toreturn;

            if (!data.TryGetValue(TimeStep, out toreturn))
            {
                if (data.Count == 0)
                {
                    toreturn = new FixedTimeStepSeries()
                    {
                        TimeStepSize = TimeStep, Name = Name + "_" + TimeStep.ToString()
                    };
                }

                if (data.ContainsKey(TimeStepUnit.Day))
                {
                    toreturn = TSTools.ChangeZoomLevel(data[TimeStepUnit.Day], TimeStep, Accumulate);
                }
                else if (data.ContainsKey(TimeStepUnit.Month))
                {
                    toreturn = TSTools.ChangeZoomLevel(data[TimeStepUnit.Month], TimeStep, Accumulate);
                }
                data.Add(TimeStep, toreturn);
            }
            return(toreturn);
        }
Beispiel #2
0
 public TimeSpanSeries(IEnumerable <TimeSpanValue> Values)
     : base(Values)
 {
     if (Items.Count > 0)
     {
         TimeStepSize = TSTools.GetTimeStep(Items[0].StartTime, Items[0].EndTime);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Creates a fixed time step series with the lowest possible timestep
        /// </summary>
        /// <param name="ts"></param>
        public FixedTimeStepSeries(TimeSpanSeries ts, bool Accumulate) : this()
        {
            var maxtimestep = TimeSpan.FromSeconds(ts.Items.Average(tse => tse.Duration.TotalSeconds));

            this.TimeStepSize    = TSTools.GetLowestZoomLevel(maxtimestep);
            this.StartTime       = TSTools.GetTimeOfFirstTimeStep(ts.StartTime, TimeStepSize);
            this.OffSetStartTime = ts.StartTime;
            OffSetEndTime        = ts.EndTime;
            DateTime NextEnd = StartTime.AddTimeStepUnit(TimeStepSize);

            List <int> Nvalues = new List <int>();

            foreach (var v in ts.Items)
            {
                if (v.EndTime <= NextEnd)
                {
                    if (Items.Count == 0)
                    {
                        Items.Add(new ValueDouble(0));
                        Nvalues.Add(0);
                    }
                    if (v.Value != ts.DeleteValue)
                    {
                        Items[Items.Count - 1].Value += v.Value;
                        Nvalues[Items.Count - 1]++;
                    }
                }
                else
                {
                    Items.Add(new ValueDouble(DeleteValue));
                    Nvalues.Add(0);
                    while (v.EndTime > (NextEnd = NextEnd.AddTimeStepUnit(TimeStepSize)))
                    {
                        Items.Add(new ValueDouble(DeleteValue));
                        Nvalues.Add(0);
                    }
                    Items[Count - 1].Value = v.Value;
                    Nvalues[Items.Count - 1]++;
                }
            }

            if (!Accumulate)
            {
                for (int i = 0; i < Nvalues.Count; i++)
                {
                    if (Nvalues[i] > 0)
                    {
                        Items[i].Value /= Nvalues[i];
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Returns the R-squared value
        /// </summary>
        /// <param name="Other"></param>
        /// <returns></returns>
        public double?R2(FixedTimeStepSeries Other)
        {
            double[] val1;
            double[] val2;
            AlignRemoveDeletevalues(Other, out val1, out val2);
            int c = val1.Count();

            if (c > 0)
            {
                return(TSTools.R2(val1, val2));
            }
            return(null);
        }
Beispiel #5
0
 public TimeStampSeries(IEnumerable <TimeStampValue> Values)
     : base(Values)
 {
     if (Items.Count > 1)
     {
         TimeStepSize = TSTools.GetTimeStep(Items[0].Time, Items[1].Time);
     }
     else
     {
         TimeStepSize = TimeStepUnit.None;
     }
     Items.CollectionChanged += Items_CollectionChanged;
 }
Beispiel #6
0
        public TimeSpanSeries(TimeStampSeries ts, TimeSpan TimeStep)
            : this()
        {
            this.DeleteValue = ts.DeleteValue;
            TimeStepSize     = ts.TimeStepSize;
            List <TimeSpanValue> templist = new List <TimeSpanValue>();

            for (int i = 0; i < ts.Count; i++)
            {
                templist.Add(new TimeSpanValue(ts.Items[i].Time.Subtract(TimeStep), ts.Items[i].Time, ts.Items[i].Value));
            }
            AddRange(templist);
            if (ts.Count != 0)
            {
                TimeStepSize = TSTools.GetTimeStep(StartTime, StartTime.Add(TimeStep));
            }
        }
Beispiel #7
0
        public void GapFill(InterpolationMethods Method)
        {
            if (this.TimeStepSize == TimeStepUnit.None)
            {
                throw new Exception("Cannot GapFill when the timestep unit is not set");
            }

            List <int>    Xvalues = new List <int>();
            List <double> Yvalues = new List <double>();

            Xvalues.Add(0);
            Yvalues.Add(Items.First().Value);
            int counter = 0;

            for (int i = 1; i < Items.Count; i++)
            {
                DateTime next = Items[i - 1].Time;
                while ((next = TSTools.GetNextTime(next, this.TimeStepSize)) <= Items[i].Time)
                {
                    counter++;
                }
                Yvalues.Add(Items[i].Value);
                Xvalues.Add(counter);
            }

            if (Method == InterpolationMethods.DeleteValue)
            {
                for (int i = 1; i < Yvalues.Count; i++)
                {
                    for (int j = Xvalues[i - 1] + 1; j < Xvalues[i]; j++)
                    {
                        Items.Insert(j, new TimeStampValue(TSTools.GetNextTime(Items[j - 1].Time, this.TimeStepSize), DeleteValue));
                    }
                }
            }
            else
            {
                throw new Exception("Not implemented yet");
            }
        }
Beispiel #8
0
        public TimeSpanSeries(TimeStampSeries ts) : this()
        {
            if (ts != null)
            {
                this.DeleteValue = ts.DeleteValue;
                TimeStepSize     = ts.TimeStepSize;

                if (ts.Count > 1)
                {
                    List <TimeSpanValue> templist = new List <TimeSpanValue>();
                    templist.Add(new TimeSpanValue(ts.Items[0].Time.Subtract(ts.Items[1].Time.Subtract(ts.Items[0].Time)), ts.Items[0].Time, ts.Items[0].Value));

                    for (int i = 1; i < ts.Count; i++)
                    {
                        templist.Add(new TimeSpanValue(ts.Items[i - 1].Time, ts.Items[i].Time, ts.Items[i].Value));
                    }
                    AddRange(templist);
                }
                if (Items.Count > 0)
                {
                    TimeStepSize = TSTools.GetTimeStep(Items[0].StartTime, Items[0].EndTime);
                }
            }
        }