Exemplo n.º 1
0
 public DoubleTimeSeries GetDoubleTimeSeries(DateTime start, DateTime end)
 {
     if (start > end)
     {
         throw new ArgumentException("Starting date cannot be before ending date", "start");
     }
     else if (start < _calendar.MinValue)
     {
         throw CalendarException.Create(_calendar, start);
     }
     else if (end > _calendar.MaxValue)
     {
         throw CalendarException.Create(_calendar, end);
     }
     else
     {
         Calendar         subCalendar = _calendar.GetSubCalendar(start, end);
         DoubleTimeSeries res         = new DoubleTimeSeries();
         foreach (var date in subCalendar)
         {
             res[date] = _tSeries.ContainsKey(date) ? _tSeries[date] : null;
         }
         return(res);
     }
 }
Exemplo n.º 2
0
        public void AddOrUpdate(DateTime date, double?value)
        {
            if (_calendar.Contains(date))
            {
                if (_tSeries.Count > 0 && !_tSeries.ContainsKey(date) && !(_tSeries.Keys.Any(k => k < date) && _tSeries.Keys.Any(k => k > date)))
                {
                    DateTime minDate = _tSeries.Keys.Min();
                    DateTime maxDate = _tSeries.Keys.Max();
                    Calendar subCalendar;
                    if (date < minDate)
                    {
                        subCalendar = _calendar.GetSubCalendar(date, minDate);
                    }
                    else
                    {
                        subCalendar = _calendar.GetSubCalendar(maxDate, date);
                    }

                    foreach (var d in subCalendar)
                    {
                        if (d != minDate && d != maxDate)
                        {
                            _tSeries[d] = null;
                        }
                    }
                }
                _tSeries[date] = value;
            }
            else
            {
                throw CalendarException.Create(_calendar, date);
            }
        }
Exemplo n.º 3
0
 public void Remove(DateTime date)
 {
     if (_calendar.Contains(date))
     {
         if (!_tSeries.ContainsKey(date))
         {
             throw new ArgumentException(date.ToShortDateString() + " is not in the time series");
         }
         else
         {
             if (_tSeries.Count == 1)
             {
                 _tSeries.Remove(date);
             }
             else
             {
                 _tSeries[date] = null;
                 DateTime minDate = _tSeries.First(p => p.Value.HasValue).Key;
                 DateTime maxDate = _tSeries.Last(p => p.Value.HasValue).Key;
                 IEnumerable <DateTime> toRemove = _tSeries.Keys.Where(k => k <minDate || k> maxDate).ToList();
                 foreach (var d in toRemove)
                 {
                     _tSeries.Remove(d);
                 }
             }
         }
     }
     else
     {
         throw CalendarException.Create(_calendar, date);
     }
 }
Exemplo n.º 4
0
 public double?Get(DateTime date)
 {
     if (_calendar.Contains(date))
     {
         return(_tSeries[date]);
     }
     else
     {
         throw CalendarException.Create(_calendar, date);
     }
 }