Example #1
0
 internal void AddNearEnd(double time, double[,] parameters)
 {
     if (Count == 0 || time > Times[LastIndex])
     {
         Times.Add(time);
         Parameters.Add(parameters);
     }
     else if (time < Times[0])
     {
         Times.Insert(0, time);
         Parameters.Insert(0, parameters);
     }
     else
     {
         var i = LastIndex;
         do
         {
             if (Times[i] == time)
             {
                 return;                    //if it already exists, just don't add it at all!
             }
             i--;
         } while (i > 0 && Times[i] >= time);
         Times.Insert(i + 1, time);
         Parameters.Insert(i + 1, parameters);
     }
     LastIndex++;
 }
Example #2
0
        //rkprad: possibly there is a better and simpler way to write the series of add /addnearend /addnearbegin functions

        internal void Add(double time, double[,] parameters)
        {
            if (Count == 0 || time > Times[LastIndex])
            //if count =0; then time is added to the first spot
            //if count =/0 then time is added to the next spot based on lastspot value
            {
                Times.Add(time);
                Parameters.Add(parameters);
            }
            else //inserting time at some intermediate value
            {
                int ub = LastIndex; //ub = upperbound say 5
                int lb = 0; //lb = lower bound
                int i;      //counter
                do
                {
                    i = (ub - lb) / 2;   //2.5 -> 3
                    if (Times[i] > time) //Times[3]>
                    {
                        ub = i;
                    }
                    else
                    {
                        lb = i;
                    }
                } while (ub - lb > 1);
                Times.Insert(i, time);
                Parameters.Insert(i, parameters);
            }
            LastIndex++;
        }
Example #3
0
 internal void AddNearBegin(double time, double[,] parameters)
 {
     if (Count == 0 || time > Times[LastIndex])
     {
         Times.Add(time);
         Parameters.Add(parameters);
     }
     else if (time < Times[0])
     {
         Times.Insert(0, time);
         Parameters.Insert(0, parameters);
     }
     else
     {
         int i = 0;
         do
         {
             if (Times[i] == time)
             {
                 return;                    //if it already exists, just don't add it at all!
             }
             i++;
         } while (Times[i] <= time);
         Times.Insert(i, time);
         Parameters.Insert(i, parameters);
     }
     LastIndex++;
 }
Example #4
0
        private void StartLap()
        {
            _lapCount++;
            Times.Insert(0,
                         new TimerItem
            {
                LapNumber   = _lapCount,
                LapTime     = _stopwatchLap.Elapsed,
                OverallTime = _stopwatchOverall.Elapsed
            });

            _stopwatchLap.Reset();
            _stopwatchLap.Start();
        }
Example #5
0
        protected void CalculateSleepTimes(TimeSpan endtime)
        {
            Times.Clear();

            var wakeUpTime = DateTime.Today.AddDays(1) + endtime;

            var sleepCycleTime = new TimeSpan(1, 30, 0);

            for (int i = 0; i < 6; i++)
            {
                var sleepTime = wakeUpTime.Add(-sleepCycleTime);

                Times.Insert(0, sleepTime.AddMinutes(-14).ToString("h:mm tt"));
                wakeUpTime = sleepTime;
            }
        }
Example #6
0
        /// <summary>
        ///     inserts a new point into the time series.
        ///     if the datetime already has a value, then it either replaces it
        ///     or throws an exception
        /// </summary>
        /// <param name="time">time at which value is to be inserted</param>
        /// <param name="value">value to be inserted</param>
        /// <param name="forceOverwrite">determines whether exception is thrown when point alread exists</param>
        public void InsertInMiddle(DateTime time, T value, bool forceOverwrite)
        {
            if (Count == 0)
            {
                Add(time, value, forceOverwrite);
                return;
            }

            var sidx = Times.BinarySearch(time);

            if (sidx >= 0) // got a match
            {
                if (forceOverwrite)
                {
                    Values[sidx] = value;
                    return;
                }

                throw new ApplicationException("Cannot insert over the top of an existing point.");
            }

            var i0 = ~sidx - 1; // the index of the time before the searched time

            if (i0 == -1)       // it goes at the front
            {
                Values.Insert(0, value);
                Times.Insert(0, time);
            }
            else if (i0 == Count - 1) // it goes at the end
            {
                Add(time, value, forceOverwrite);
            }
            else // it goes in the middle somewhere
            {
                Values.Insert(i0 + 1, value);
                Times.Insert(i0 + 1, time);
            }
        }
Example #7
0
 public void Insert(int index, KeyValuePair <double, double[, ]> item)
 {
     Times.Insert(index, item.Key);
     Parameters.Insert(index, item.Value);
 }