public void GetValuesTest() { FixedTimeStepSeries target = new FixedTimeStepSeries(); // TODO: Initialize to an appropriate value target.TimeStepSize = TimeStepUnit.Month; target.AddRange(new DateTime(2010, 1, 1), new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }); DateTime StartTime = new DateTime(2010, 3, 1); DateTime EndTime = new DateTime(2010, 6, 1); double[] expected = new double[] { 3.0, 4.0, 5.0, 6.0 }; double[] actual; actual = target.GetValues(StartTime, EndTime); Assert.AreEqual(expected.Length, actual.Length); }
public void ChangeZoomLevelTest() { FixedTimeStepSeries Data = new FixedTimeStepSeries() { TimeStepSize = TimeStepUnit.Month }; Data.AddRange(new DateTime(2010, 1, 1), new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }); var actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, true); Assert.AreEqual(78, actual.GetValue(Data.StartTime)); actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, false); Assert.AreEqual(6.5, actual.GetValue(Data.StartTime), 1e-10); Assert.AreEqual(Data.DeleteValue, actual.GetValue(Data.StartTime.AddDays(400))); }
public void GetIndexTest() { FixedTimeStepSeries target = new FixedTimeStepSeries(); target.TimeStepSize = TimeStepUnit.Month; target.AddRange(new DateTime(2010, 1, 1), new double[] { 1, 2, 3, 4, 5 }); int expected = 0; int actual; actual = target.GetIndex(new DateTime(2010, 1, 1)); Assert.AreEqual(expected, actual); Assert.AreEqual(-1, target.GetIndex(new DateTime(2009, 12, 1))); Assert.AreEqual(-2, target.GetIndex(new DateTime(2009, 11, 1))); Assert.AreEqual(11, target.GetIndex(new DateTime(2010, 12, 1))); }
public void SubstractTest() { FixedTimeStepSeries ts1 = new FixedTimeStepSeries(); FixedTimeStepSeries ts2 = new FixedTimeStepSeries(); ts1.StartTime = new DateTime(2010, 1, 1); ts1.AddRange(new double[] { 2, 3, 4 }); ts1.TimeStepSize = TimeStepUnit.Month; ts2.StartTime = new DateTime(2010, 1, 1); ts2.AddRange(new double[] { 1, 1, 1 }); ts2.TimeStepSize = TimeStepUnit.Month; FixedTimeStepSeries actual; actual = TSTools.Substract(ts1, ts2); Assert.AreEqual(1, actual.GetValue(new DateTime(2010, 1, 1))); Assert.AreEqual(2, actual.GetValue(new DateTime(2010, 2, 1))); }
public void GetIndexTest() { FixedTimeStepSeries target = new FixedTimeStepSeries(); target.TimeStepSize = TimeStepUnit.Month; target.AddRange(new DateTime(2010, 1, 1), new double[] { 1, 2, 3, 4, 5 }); int expected = 0; int actual; actual = target.GetIndex(new DateTime(2010,1,1)); Assert.AreEqual(expected, actual); Assert.AreEqual(-1, target.GetIndex(new DateTime(2009,12,1))); Assert.AreEqual(-2, target.GetIndex(new DateTime(2009, 11, 1))); Assert.AreEqual(11, target.GetIndex(new DateTime(2010, 12, 1))); }
public void ChangeZoomLevelTest() { FixedTimeStepSeries Data = new FixedTimeStepSeries() { TimeStepSize = TimeStepUnit.Month }; Data.AddRange(new DateTime(2010, 1, 1), new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }); var actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, true); Assert.AreEqual(78, actual.GetValue(Data.StartTime, InterpolationMethods.DeleteValue)); actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, false); Assert.AreEqual(6.5, actual.GetValue(Data.StartTime, InterpolationMethods.DeleteValue), 1e-10); Assert.AreEqual(Data.DeleteValue, actual.GetValue(Data.StartTime.AddDays(400), InterpolationMethods.DeleteValue)); }
public void SubstractTest() { FixedTimeStepSeries ts1 = new FixedTimeStepSeries(); FixedTimeStepSeries ts2 = new FixedTimeStepSeries(); ts1.SetStartTime( new DateTime(2010, 1, 1)); ts1.AddRange(new double[] { 2, 3, 4 }); ts1.TimeStepSize = TimeStepUnit.Month; ts2.SetStartTime( new DateTime(2010, 1, 1)); ts2.AddRange(new double[] { 1, 1, 1 }); ts2.TimeStepSize = TimeStepUnit.Month; FixedTimeStepSeries actual; actual = TSTools.Substract(ts1, ts2); Assert.AreEqual(1, actual.GetValue(new DateTime(2010, 1, 1), InterpolationMethods.DeleteValue)); Assert.AreEqual(2, actual.GetValue(new DateTime(2010, 2, 1), InterpolationMethods.DeleteValue)); }
public void ChangeZoomLevelTest2() { FixedTimeStepSeries Data = new FixedTimeStepSeries() { TimeStepSize = TimeStepUnit.Month }; Data.AddRange(new DateTime(2010, 1, 1), new double[] { Data.DeleteValue, Data.DeleteValue, Data.DeleteValue }); var actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, true); Assert.AreEqual(Data.DeleteValue, actual.GetValue(Data.StartTime)); actual = TSTools.ChangeZoomLevel(Data, TimeStepUnit.Year, false); Assert.AreEqual(Data.DeleteValue, actual.GetValue(Data.StartTime), 1e-10); Assert.AreEqual(Data.DeleteValue, actual.GetValue(Data.StartTime.AddDays(400))); }
/// <summary> /// Gets a fixedtimestepseries at another zoom level. /// </summary> /// <param name="Data"></param> /// <param name="NewZoomLevel"></param> /// <param name="Accumulate"></param> /// <returns></returns> public static FixedTimeStepSeries ChangeZoomLevel(FixedTimeStepSeries Data, TimeStepUnit NewZoomLevel, bool Accumulate) { if (Data.TimeStepSize <= NewZoomLevel) return null; FixedTimeStepSeries ToReturn = new FixedTimeStepSeries(); ToReturn.DeleteValue = Data.DeleteValue; ToReturn.TimeStepSize = NewZoomLevel; ToReturn.StartTime= GetTimeOfFirstTimeStep(Data.StartTime, NewZoomLevel); ToReturn.OffSetStartTime = Data.OffSetStartTime; ToReturn.OffSetEndTime = Data.OffSetEndTime; List<double> newvalues = new List<double>(); int localcount = 0; int counter = 0; switch (NewZoomLevel) { case TimeStepUnit.Year: { int currentyear = -1; foreach (var v in Data.Items) { if (Data.GetTime(counter).Year == currentyear) { if (v.Value != Data.DeleteValue) newvalues[newvalues.Count - 1] += v.Value; } else { currentyear = Data.GetTime(counter).Year; if (!Accumulate & newvalues.Count>0) newvalues[newvalues.Count - 1] /= localcount; localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (localcount != 12) //only use complete years newvalues.RemoveAt(newvalues.Count - 1); else { if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; } } break; case TimeStepUnit.Month: int currentmonth = Data.StartTime.Month; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Month == currentmonth) { if (v.Value != Data.DeleteValue) newvalues[newvalues.Count - 1] += v.Value; } else { currentmonth = Data.GetTime(counter).Month; if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; break; case TimeStepUnit.Day: int currentday = Data.StartTime.Day; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Day == currentday) { if (v.Value != Data.DeleteValue) newvalues[newvalues.Count - 1] += v.Value; } else { currentday = Data.GetTime(counter).Day; if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; break; case TimeStepUnit.Hour: int currenthour = Data.StartTime.Hour; newvalues.Add(0); foreach (var v in Data.Items) { if (Data.GetTime(counter).Hour == currenthour) { if (v.Value != Data.DeleteValue) newvalues[newvalues.Count - 1] += v.Value; } else { currenthour = Data.GetTime(counter).Hour; if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; break; case TimeStepUnit.Minute: int currentminute = Data.StartTime.Minute; newvalues.Add(0); foreach (var v in Data.Items.Where(vv => vv.Value != Data.DeleteValue)) { if (Data.GetTime(counter).Minute == currentminute) { newvalues[newvalues.Count - 1] += v.Value; } else { currentminute = Data.GetTime(counter).Minute; if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; localcount = 0; newvalues.Add(v.Value); } localcount++; counter++; } if (!Accumulate) newvalues[newvalues.Count - 1] /= localcount; break; case TimeStepUnit.Second: break; case TimeStepUnit.None: break; default: break; } ToReturn.AddRange(newvalues.Select(n=>new ValueDouble(n))); return ToReturn; }