/// <summary> /// This method computes a Checksum for the timeseries. The input to the hash includes /// the list of parameters of the time series, and the list of checksums for each of the traces in /// the time series ensemble. The list of the traces' checksums are passed to this method within /// a list of ITimeSeriesTrace objects. This method does not modify the object given in the traceList /// parameter or assign any property values to any of its items. /// </summary> /// <param name="timeStepUnit">TSDateCalculator.TimeStepUnitCode value for Minute,Hour,Day,Week,Month, Year, or Irregular</param> /// <param name="timeStepQuantity">The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6.</param> /// <param name="blobStartDate">Date of the first time step in the BLOB</param> /// <param name="traceList">a list of trace object whose checksums have already been computed.</param> /// <returns>the Checksum as a byte[16] array</returns> public byte[] ComputeChecksum( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate, List<ITimeSeriesTrace> traceList) { return TSBlobCoder.ComputeChecksum(timeStepUnit, timeStepQuantity, blobStartDate, traceList); }
/// <summary> /// TimeSeriesLibrary is responsible for ensuring that a certain set of meta-parameters (which /// are saved as database fields) are coordinated with the BLOB of timeseries data. This method /// records all of the meta-parameters of a regular timeseries into the fields of this TSParameters /// object, using the input parameters given to the method. /// </summary> public void SetParametersRegular( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int timeStepCount, DateTime blobStartDate, int compressionCode) { // Most of the parameters are straightforward TimeStepUnit = timeStepUnit; TimeStepQuantity = timeStepQuantity; BlobStartDate = blobStartDate; CompressionCode = compressionCode; }
/// <summary> /// This method is to be used as a common utility function for testing the speed of the /// FillDateArray method. /// </summary> public void FillDataArray_SpeedCore(int nCycles, int n, TSDateCalculator.TimeStepUnitCode unit) { var array = new DateTime[n + 2]; DateTime start = new DateTime(1920, 1, 1); for (int i = 0; i < nCycles; i++) { TSDateCalculator.FillDateArray(unit, 1, n, array, start); } }
public void CountSteps_4Week() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Week; short q = 4; DateTime d1 = new DateTime(1960, 1, 1); DateTime d2 = d1.AddDays(56); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(2, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
public void CountSteps_1Year() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Year; short q = 1; DateTime d1 = new DateTime(1960, 1, 2); DateTime d2 = new DateTime(1980, 12, 15); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(20, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
/// <summary> /// This method is to be used as a common utility function for testing the speed of the /// FillDateArray method. /// </summary> public void FillDataArray_Core(TSDateCalculator.TimeStepUnitCode unit, short quantity, Func <DateTime, DateTime> func) { int n = 20; var array = new DateTime[n + 2]; DateTime start = new DateTime(1920, 1, 1); TSDateCalculator.FillDateArray(unit, quantity, n, array, start); for (int i = 1; i < n; i++) { Assert.AreEqual(func(array[i - 1]), array[i]); } }
public void ReadDatesValuesRegular() { DateTime startDate = DateTime.Parse("1/10/1996"); DateTime endDate = DateTime.Parse("2/10/2002"); int timeStepCount = 70; TSDateCalculator.TimeStepUnitCode timeStepUnit = TSDateCalculator.TimeStepUnitCode.Hour; short timeStepQuantity = 6; int id, traceNumber = 13; String extraParamNames = "TimeSeriesType, Unit_Id, RunGUID, VariableType, VariableName, RunElementGUID"; String extraParamValues = "0, 1, 'A0101010-AAAA-BBBB-2222-3E3E3E3E3E3E', 0, 'eraseme', '00000000-0000-0000-0000-000000000000'"; id = _lib.WriteParametersRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), (short)timeStepUnit, timeStepQuantity, timeStepCount, startDate, GetSbyte(extraParamNames), GetSbyte(extraParamValues)); double[] valArray = new double[timeStepCount]; TSDateValueStruct[] dateValArray = new TSDateValueStruct[timeStepCount], testDateValArray = new TSDateValueStruct[timeStepCount]; double x = 5.25; DateTime curDate = startDate; for (int i = 0; i < timeStepCount; i++) { valArray[i] = x; dateValArray[i].Value = x; dateValArray[i].Date = curDate; x += 1.75; curDate = TSDateCalculator.IncrementDate(curDate, timeStepUnit, timeStepQuantity, 1); } _lib.WriteTraceRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), id, traceNumber, valArray); _lib.CommitTraceWrites(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName)); // The method being tested _lib.ReadDatesValues(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), id, traceNumber, timeStepCount, ref testDateValArray, startDate, endDate); // for (int i = 0; i < timeStepCount; i++) { Assert.AreEqual(dateValArray[i], testDateValArray[i]); } }
public void CountSteps_5Min() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Minute; short q = 5; DateTime d1 = new DateTime(1960, 1, 15); DateTime d2 = new DateTime(1960, 1, 17); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(576, n); d1 = d1.AddSeconds(98); n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(576, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
public void CountSteps_2Month() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Month; short q = 2; DateTime d1 = new DateTime(1960, 1, 2); DateTime d2 = new DateTime(1960, 12, 15); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(6, n); d1 = new DateTime(1960, 1, 1); d2 = new DateTime(1960, 12, 1); n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(6, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
public void CountSteps_2Day() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Day; short q = 2; DateTime d1 = new DateTime(1960, 1, 1); DateTime d2 = new DateTime(1960, 12, 31); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(183, n); d1 = d1.AddHours(23).AddMinutes(59); d2 = new DateTime(1961, 12, 31); n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(365, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
public void CountSteps_2Hour() { TSDateCalculator.TimeStepUnitCode u = TSDateCalculator.TimeStepUnitCode.Hour; short q = 2; DateTime d1 = new DateTime(1960, 2, 20); DateTime d2 = new DateTime(1960, 3, 3); int n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(144, n); d2 = d1.AddHours(6); d1 = d1.AddMinutes(30); n = TSDateCalculator.CountSteps(d1, d2, u, q); Assert.AreEqual(3, n); n = TSDateCalculator.CountSteps(d1, d1, u, q); Assert.AreEqual(0, n); }
/// <summary> /// This method creates a List of TimeSeriesValue objects from the given BLOB (byte array) /// of time series values. The method converts the entire BLOB into the list. The sibling /// method ConvertBlobToListLimited can convert a selected portion of the BLOB into the list. /// </summary> /// <param name="timeStepUnit">TSDateCalculator.TimeStepUnitCode value for Minute,Hour,Day,Week,Month, Year, or Irregular</param> /// <param name="timeStepQuantity">The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6. If timeStepUnit is /// Irregular, then this value is ignored.</param> /// <param name="timeStepCount">the number of time steps that are stored in the blob</param> /// <param name="blobStartDate">The DateTime value of the first time step in the BLOB. If /// timeStepUnit is Irregular, then this value is ignored.</param> /// <param name="blobData">The BLOB (byte array) that this method will convert</param> /// <param name="dateValueList">The List of TimeSeriesValues that this method will create from the BLOB.</param> /// <param name="compressionCode">a generation number that indicates what compression technique to use</param> /// <returns>The number of time steps added to dateValueList</returns> public int ConvertBlobToListAll( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int timeStepCount, DateTime blobStartDate, Byte[] blobData, ref List<TimeSeriesValue> dateValueList, int compressionCode) { // The private method ConvertBlobToList() will do all the real work here. // This private method takes parameters for limiting a portion of the List to be // written to the BLOB. The values below are dummies that will be passed to // the private method, which it will ignore. int nReqValues = 0; DateTime reqStartDate = blobStartDate; DateTime reqEndDate = blobStartDate; // Let the private core method do all the real work. // We pass it the 'applyLimits' value of false, to tell it to ignore the 'req' limit values. return ConvertBlobToList(timeStepUnit, timeStepQuantity, timeStepCount, blobStartDate, false, nReqValues, reqStartDate, reqEndDate, blobData, ref dateValueList, compressionCode); }
public void ReadValuesRegular() { DateTime startDate = DateTime.Parse("2/10/2000"); int timeStepCount = 40; short timeStepUnit = (short)TSDateCalculator.TimeStepUnitCode.Day; short timeStepQuantity = 2; int id, traceNumber = 27; String extraParamNames = "TimeSeriesType, Unit_Id, RunGUID, VariableType, VariableName, RunElementGUID"; String extraParamValues = "0, 1, 'A0101010-AAAA-BBBB-2222-3E3E3E3E3E3E', 0, 'eraseme', '00000000-0000-0000-0000-000000000000'"; id = _lib.WriteParametersRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), timeStepUnit, timeStepQuantity, timeStepCount, startDate, GetSbyte(extraParamNames), GetSbyte(extraParamValues)); double[] valArray = new double[timeStepCount], testValArray = new double[timeStepCount]; double x = 10.0; for (int i = 0; i < timeStepCount; i++) { valArray[i] = x; x *= 1.2; } DateTime endDate = TSDateCalculator.IncrementDate(startDate, (TSDateCalculator.TimeStepUnitCode)timeStepUnit, timeStepQuantity, timeStepCount - 1); _lib.WriteTraceRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), id, traceNumber, valArray); _lib.CommitTraceWrites(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName)); // The method being tested _lib.ReadValuesRegular(_connxNumber, GetSbyte(_paramTableName), GetSbyte(_traceTableName), id, traceNumber, timeStepCount, testValArray, startDate, endDate); // for (int i = 0; i < timeStepCount; i++) { Assert.AreEqual(valArray[i], testValArray[i]); } }
// The series of tests below is for ConvertBlobToListAll and ConvertListToBlob. // The tests take advantage of the fact that the methods are designed so that // the series that is put into the BLOB must be identical to the series that // comes out of the BLOB. // This method is re-used by the actual test methods that follow. public void ConvertBlobAll(List<TimeSeriesValue> inList, TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate) { TSLibrary tsLib = new TSLibrary(); List<TimeSeriesValue> outList = new List<TimeSeriesValue>(); int compressionCode; byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity, inList.Count, inList.First().Date, inList.Last().Date, inList, new TSTrace { TraceNumber=1 }, out compressionCode); int ret = tsLib.ConvertBlobToListAll(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, blobData, ref outList, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, inList.Count); // the count in both lists must match Assert.AreEqual(outList.Count, inList.Count); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outList[i].ValueEquals(inList[i]) == false) AreEqual = false; } Assert.IsTrue(AreEqual); }
// This method is reused by the actual test methods that follow public Boolean ComputeTestChecksums( TSDateCalculator.TimeStepUnitCode u1, short q1, DateTime sDate1, List<ITimeSeriesTrace> traceList1, TSDateCalculator.TimeStepUnitCode u2, short q2, DateTime sDate2, List<ITimeSeriesTrace> traceList2) { TSLibrary tsLib = new TSLibrary(); byte[] b1 = tsLib.ComputeChecksum(u1, q1, sDate1, traceList1); byte[] b2 = tsLib.ComputeChecksum(u2, q2, sDate2, traceList2); Assert.IsTrue(b1.Length == 16); Assert.IsTrue(b2.Length == 16); for (int i = 0; i < b2.Length; i++) if (b1[i] != b2[i]) return false; return true; }
// The series of tests below is for ConvertListToBlobWithChecksum() // // This method is reused by the actual test methods that follow public Boolean ComputeTestChecksums( TSDateCalculator.TimeStepUnitCode u1, short q1, List<TimeSeriesValue> list1, ITimeSeriesTrace trace1, TSDateCalculator.TimeStepUnitCode u2, short q2, List<TimeSeriesValue> list2, ITimeSeriesTrace trace2) { TSLibrary tsLib = new TSLibrary(); int compressionCode; tsLib.ConvertListToBlobWithChecksum( u1, q1, list1.Count, list1[0].Date, list1[list1.Count - 1].Date, list1, trace1, out compressionCode); tsLib.ConvertListToBlobWithChecksum( u2, q2, list2.Count, list2[0].Date, list2[list2.Count - 1].Date, list2, trace2, out compressionCode); Assert.IsTrue(trace1.Checksum.Length == 16); Assert.IsTrue(trace2.Checksum.Length == 16); for (int i = 0; i < trace2.Checksum.Length; i++) if (trace1.Checksum[i] != trace2.Checksum[i]) return false; return true; }
/// <summary> /// This method converts a List of TimeSeriesValue objects into a BLOB (byte array) of /// time series values and computes a checksum from the BLOB. This method assigns the new values /// of the ValueBlob, Checksum, EndDate, and TimeStepCount to the object given in the traceObject /// parameter. The TraceNumber property of the traceObject parameter must be set before calling /// this method. /// /// The entire List is converted into the BLOB--i.e., the method does not take any /// parameters for limiting the size of the List that is created. This method will /// throw exceptions if the meta-parameters that are passed in are not consistent /// with the List of TimeSeriesValue objects. /// </summary> /// <param name="timeStepUnit">TSDateCalculator.TimeStepUnitCode value for /// Minute, Hour, Day, Week, Month, Year, or Irregular</param> /// <param name="timeStepQuantity">The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6.</param> /// <param name="timeStepCount">The number of time steps stored in the BLOB</param> /// <param name="blobStartDate">Date of the first time step in the BLOB</param> /// <param name="blobEndDate">Date of the last time step in the BLOB</param> /// <param name="dateValueList">A List of TimeSeriesValue objects that will be converted to a BLOB</param> /// <param name="traceObject">an object which contains the a TraceNumber property that is used to /// compute the checksum. The computed BLOB and checksum are both saved to the appropriate properties /// of this object.</param> /// <param name="compressionCode">a generation number that indicates what compression technique to use</param> /// <returns>The BLOB (byte array) of time series values that was created from dateValueList</returns> public byte[] ConvertListToBlobWithChecksum( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int timeStepCount, DateTime blobStartDate, DateTime blobEndDate, List<TimeSeriesValue> dateValueList, ITimeSeriesTrace traceObject, out int compressionCode) { // Error checks if (dateValueList.Count != timeStepCount) throw new TSLibraryException(ErrCode.Enum.Checksum_Improper_Count); if (dateValueList[0].Date != blobStartDate) throw new TSLibraryException(ErrCode.Enum.Checksum_Improper_StartDate); if (dateValueList.Last().Date != blobEndDate) throw new TSLibraryException(ErrCode.Enum.Checksum_Improper_EndDate); // When compressing, we always use the latest compression method compressionCode = TSBlobCoder.currentCompressionCode; // Assign properties to the Trace object if (traceObject.EndDate != blobEndDate) traceObject.EndDate = blobEndDate; if (traceObject.TimeStepCount != timeStepCount) traceObject.TimeStepCount = timeStepCount; // Convert the List dateValueList into a BLOB. if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular) { // IRREGULAR TIME SERIES // The method in TSBlobCoder can only process an array of TSDateValueStruct. Therefore // we convert the List of objects to an Array of struct instances. TSDateValueStruct[] dateValueArray = dateValueList.Select(tsv => (TSDateValueStruct)tsv).ToArray(); // Let the method in TSBlobCoder class do all the work TSBlobCoder.ConvertArrayToBlobIrregular(dateValueArray, compressionCode, traceObject); } else { // REGULAR TIME SERIES // The method in TSBlobCoder can only process an array of double values. Therefore // we convert the List of date/value objects to an Array values. double[] valueArray = dateValueList.Select(dv => dv.Value).ToArray(); // Let the method in TSBlobCoder class do all the work TSBlobCoder.ConvertArrayToBlobRegular(valueArray, compressionCode, traceObject); } return traceObject.ValueBlob; }
public void FillDateArray( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int nReqValues, DateTime[] dateArray, DateTime reqStartDate) { TSDateCalculator.FillDateArray(timeStepUnit, timeStepQuantity, nReqValues, dateArray, reqStartDate); }
/// <summary> /// This method creates a List of TimeSeriesValue objects from the given BLOB (byte array) /// of time series values. The method takes parameters for a maximum number of values, /// an earliest date, and a latest date, so that only a portion of the BLOB might be /// converted to the List. The sibling method ConvertBlobToListAll can convert the entire /// BLOB without any limits. /// </summary> /// <param name="timeStepUnit">TSDateCalculator.TimeStepUnitCode value for Minute,Hour,Day,Week,Month, Year, or Irregular</param> /// <param name="timeStepQuantity">The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6. If timeStepUnit is /// Irregular, then this value is ignored.</param> /// <param name="timeStepCount">the number of time steps that are stored in the blob</param> /// <param name="blobStartDate">The DateTime value of the first time step in the BLOB. If /// timeStepUnit is Irregular, then this value is ignored.</param> /// <param name="nReqValues">The maximum number of time steps that should be added to dateValueList</param> /// <param name="reqStartDate">The earliest date that will be added to dateValueList</param> /// <param name="reqEndDate">The latest date that will be added to dateValueList</param> /// <param name="blobData">The BLOB (byte array) that this method will convert into a List</param> /// <param name="dateValueList">The List of TimeSeriesValues that this method will create from the BLOB.</param> /// <param name="compressionCode">a generation number that indicates what compression technique to use</param> /// <returns>The number of time steps added to dateValueList</returns> public int ConvertBlobToListLimited( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int timeStepCount, DateTime blobStartDate, int nReqValues, DateTime reqStartDate, DateTime reqEndDate, Byte[] blobData, ref List<TimeSeriesValue> dateValueList, int compressionCode) { // Let the private core method do all the real work. // We pass it the 'applyLimits' value of true. return ConvertBlobToList(timeStepUnit, timeStepQuantity, timeStepCount, blobStartDate, true, nReqValues, reqStartDate, reqEndDate, blobData, ref dateValueList, compressionCode); }
/// <summary> /// This method is to be used as a common utility function for testing the speed of the /// FillDateArray method. /// </summary> public void FillDataArray_SpeedCore(int nCycles, int n, TSDateCalculator.TimeStepUnitCode unit) { var array = new DateTime[n + 2]; DateTime start = new DateTime(1920, 1, 1); for (int i = 0; i < nCycles; i++) TSDateCalculator.FillDateArray(unit, 1, n, array, start); }
// the maximum number of time steps to put into the series // The series of tests below is for ConvertBlobToListLimited and ConvertListToBlob. // The tests take advantage of the fact that the methods are designed so that // the series that is put into the BLOB must be identical to the series that // comes out of the BLOB. // This method is re-used by the actual test methods that follow. public void ConvertBlobLimited(List<TimeSeriesValue> inList, TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, DateTime blobStartDate, int nCutStart, // the number of time steps that the test will truncate from the start of the series int nCutEnd, // the number of time steps that the test will truncate from the end of the series int nMax) { TSLibrary tsLib = new TSLibrary(); List<TimeSeriesValue> outList = new List<TimeSeriesValue>(); int compressionCode; byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity, inList.Count, inList.First().Date, inList.Last().Date, inList, new TSTrace { TraceNumber = 1 }, out compressionCode); int ret = tsLib.ConvertBlobToListLimited(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, nMax, inList[nCutStart].Date, inList[inList.Count - nCutEnd - 1].Date, blobData, ref outList, compressionCode); // The return value of the function must match the number of items in the original list Assert.AreEqual(ret, Math.Min(nMax, inList.Count - nCutStart - nCutEnd)); // the count in both lists must match Assert.AreEqual(outList.Count, Math.Min(nMax, inList.Count - nCutStart - nCutEnd)); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outList[i].ValueEquals(inList[i + nCutStart]) == false) AreEqual = false; } Assert.IsTrue(AreEqual); }
/// <summary> /// This private method creates a List of TimeSeriesValue objects from the given BLOB (byte array) /// of time series values. The method takes parameters for a maximum number of values, /// an earliest date, and a latest date, so that only a portion of the BLOB might be /// converted to the List. This method is designed to do the operations that are common between /// the public methods ConvertBlobToListLimited() and ConvertBlobToListAll(). /// </summary> /// <param name="timeStepUnit">TSDateCalculator.TimeStepUnitCode value for Minute,Hour,Day,Week,Month, Year, or Irregular</param> /// <param name="timeStepQuantity">The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6. If timeStepUnit is /// Irregular, then this value is ignored.</param> /// <param name="timeStepCount">the number of time steps that are stored in the blob</param> /// <param name="blobStartDate">The DateTime value of the first time step in the BLOB. If /// timeStepUnit is Irregular, then this value is ignored.</param> /// <param name="applyLimits">If value is true, then nReqValues, reqStartDate, and reqEndDate will be /// used to limit the portion of the BLOB that is converted to dateValueList. If the value is false, then /// nReqValues, reqStartDate, and reqEndDate will be ignored.</param> /// <param name="nReqValues">The maximum number of time steps that should be added to dateValueList. /// If applyLimits==false, then this value is ignored.</param> /// <param name="reqStartDate">The earliest date that will be added to dateValueList. /// If applyLimits==false, then this value is ignored.</param> /// <param name="reqEndDate">The latest date that will be added to dateValueList. /// If applyLimits==false, then this value is ignored.</param> /// <param name="blobData">The BLOB (byte array) that this method will convert into a List</param> /// <param name="dateValueList">The List of TimeSeriesValues that this method will create from the BLOB.</param> /// <param name="compressionCode">a generation number that indicates what compression technique to use</param> /// <returns>The number of time steps added to dateValueList</returns> private unsafe int ConvertBlobToList( TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity, int timeStepCount, DateTime blobStartDate, Boolean applyLimits, int nReqValues, DateTime reqStartDate, DateTime reqEndDate, Byte[] blobData, ref List<TimeSeriesValue> dateValueList, int compressionCode) { int nValuesRead = 0; if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular) { // IRREGULAR TIME SERIES // If we're not limiting the output list (i.e., we're returning every time step from // the BLOB), then set the size of the intermediate array to match the size of the BLOB. if (applyLimits == false) nReqValues = timeStepCount; // Allocate an array of date/value pairs that TSBlobCoder method will fill TSDateValueStruct[] dateValueArray = new TSDateValueStruct[nReqValues]; // Method in the TSBlobCoder class does the real work nValuesRead = TSBlobCoder.ConvertBlobToArrayIrregular(timeStepCount, applyLimits, nReqValues, reqStartDate, reqEndDate, blobData, dateValueArray, compressionCode); // resize the array so that the List that we make from it will have exactly the right size if(nValuesRead!=nReqValues) Array.Resize<TSDateValueStruct>(ref dateValueArray, nValuesRead); // Convert the array of date/value pairs into the List that will be used by the caller dateValueList = dateValueArray .Select(tsv => (TimeSeriesValue)tsv).ToList<TimeSeriesValue>(); } else { // REGULAR TIME SERIES // If we're not limiting the output list (i.e., we're returning every time step from // the BLOB), then set the size of the intermediate array to match the size of the BLOB. if (applyLimits == false) nReqValues = timeStepCount; // Allocate an array of values that TSBlobCoder method will fill double[] valueArray = new double[nReqValues]; // Method in the TSBlobCoder class does the real work nValuesRead = TSBlobCoder.ConvertBlobToArrayRegular(timeStepUnit, timeStepQuantity, timeStepCount, blobStartDate, applyLimits, nReqValues, reqStartDate, reqEndDate, blobData, valueArray, compressionCode); // Allocate an array to hold the time series' date values DateTime[] dateArray = new DateTime[nValuesRead]; // Fill the array with the date values corresponding to the time steps defined // for this time series in the database. TSDateCalculator.FillDateArray(timeStepUnit, timeStepQuantity, nValuesRead, dateArray, reqStartDate); // Allocate a List of date/value pairs that will be used by the caller dateValueList = new List<TimeSeriesValue>(nValuesRead); // Loop through all values, building the List of date/value pairs out of the // primitive array of dates and primitive array of values. int i; for (i = 0; i < nValuesRead; i++) { dateValueList.Add(new TimeSeriesValue { Date = dateArray[i], Value = valueArray[i] }); } nValuesRead = i; } return nValuesRead; }
public DateTime IncrementDate(DateTime startDate, TSDateCalculator.TimeStepUnitCode unit, short stepSize, int numSteps) { return TSDateCalculator.IncrementDate(startDate, unit, stepSize, numSteps); }
public List<ITimeSeriesTrace> Get3TracesRegular( TSDateCalculator.TimeStepUnitCode u1, short q1, int c1, DateTime sDate1, out DateTime eDate1, Boolean shouldPerturb = false, int perturbTraceIndex = 0, int perturbStep = 0, double perturbVal = 0, double perturbMinutes = 0) { eDate1 = DateTime.Now; // dummy TSLibrary tsLib = new TSLibrary(); List<ITimeSeriesTrace> traceList = new List<ITimeSeriesTrace>(); int compressionCode; for (int t = 0; t < 3; t++) { TSTrace trace1 = new TSTrace { TraceNumber = t + 1 }; List<TimeSeriesValue> tsValues = new List<TimeSeriesValue>(); DateTime curDate = sDate1; Double curVal = 20; for (int i = 0; i < c1; i++) { tsValues.Add(new TimeSeriesValue { Date = curDate, Value = curVal }); curDate = tsLib.IncrementDate(curDate, u1, q1, 1); curVal = curVal + i / (t + 1); } // make a perturbation if called for if (shouldPerturb && t==perturbTraceIndex) { tsValues[perturbStep].Value += perturbVal; tsValues[perturbStep].Date = tsValues[perturbStep].Date.AddMinutes(perturbMinutes); } eDate1 = tsValues.Last().Date; tsLib.ConvertListToBlobWithChecksum( u1, q1, c1, sDate1, eDate1, tsValues, trace1, out compressionCode); traceList.Add(trace1); } return traceList; }
/// <summary> /// This method is to be used as a common utility function for testing the speed of the /// FillDateArray method. /// </summary> public void FillDataArray_Core(TSDateCalculator.TimeStepUnitCode unit, short quantity, Func<DateTime, DateTime> func) { int n = 20; var array = new DateTime[n + 2]; DateTime start = new DateTime(1920, 1, 1); TSDateCalculator.FillDateArray(unit, quantity, n, array, start); for (int i = 1; i < n; i++) Assert.AreEqual(func(array[i - 1]), array[i]); }