TimeSeriesLibrary.TSLibrary.ConvertListToBlobWithChecksum C# (CSharp) Method

ConvertListToBlobWithChecksum() public method

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.
public ConvertListToBlobWithChecksum ( TSDateCalculator timeStepUnit, short timeStepQuantity, int timeStepCount, System.DateTime blobStartDate, System.DateTime blobEndDate, List dateValueList, ITimeSeriesTrace traceObject, int &compressionCode ) : byte[]
timeStepUnit TSDateCalculator TSDateCalculator.TimeStepUnitCode value for /// Minute, Hour, Day, Week, Month, Year, or Irregular
timeStepQuantity short 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.
timeStepCount int The number of time steps stored in the BLOB
blobStartDate System.DateTime Date of the first time step in the BLOB
blobEndDate System.DateTime Date of the last time step in the BLOB
dateValueList List A List of TimeSeriesValue objects that will be converted to a BLOB
traceObject ITimeSeriesTrace 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.
compressionCode int a generation number that indicates what compression technique to use
return byte[]
        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;
        }

Usage Example

        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;
        }
All Usage Examples Of TimeSeriesLibrary.TSLibrary::ConvertListToBlobWithChecksum