예제 #1
0
        /// <summary>
        /// Reads a block from the specified data set.
        /// </summary>
        /// <param name="dataSetTable">The data set to read from.</param>
        /// <param name="blockToRead">The block index for the block to read.</param>
        /// <param name="validIntervals">The number of valid intervals in the block</param>
        /// <returns>The block.</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 10/07/08 RCG 2.00.00 N/A    Created
        // 12/12/11 RCG 2.53.20        Modified for Extended LP and IP support

        private LPBlockDataRecord ReadLPBlock(StdTable64 dataSetTable, ushort blockToRead, ushort validIntervals)
        {
            PSEMResponse      Response = PSEMResponse.Ok;
            LPBlockDataRecord Block    = null;

            Response = dataSetTable.ReadBlock(blockToRead, validIntervals, out Block);

            // Handle any communication errors.
            if (Response != PSEMResponse.Ok)
            {
                throw new PSEMException(PSEMException.PSEMCommands.PSEM_READ, Response,
                                        "Error reading Load Profile block " + blockToRead.ToString(CultureInfo.CurrentCulture));
            }

            return(Block);
        }
예제 #2
0
        /// <summary>
        /// Gets the last block of Load Profile data.
        /// </summary>
        /// <param name="statusTable">The status table for the data set</param>
        /// <param name="dataSetTable">The data set to get the last block of.</param>
        /// <param name="setStatus">The set status at the time of reading.</param>
        /// <returns>The last load profile block.</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 10/07/08 RCG 2.00.00 N/A    Created
        // 12/12/11 RCG 2.53.20        Modified for Extended LP and IP support

        private LPBlockDataRecord GetLastBlock(StdTable63 statusTable, StdTable64 dataSetTable, out LPSetStatusRecord setStatus)
        {
            LPBlockDataRecord LastBlock           = null;
            LPSetStatusRecord SetStatusBeforeRead = null;
            LPSetStatusRecord SetStatusAfterRead  = null;
            int BlockReadRetries = 0;

            do
            {
                SetStatusBeforeRead = statusTable.GetSetStatusRecord(dataSetTable.DataSet);

                LastBlock = ReadLPBlock(dataSetTable, SetStatusBeforeRead.LastBlockElement, SetStatusBeforeRead.NumberOfValidIntervals);

                SetStatusAfterRead = statusTable.GetSetStatusRecord(dataSetTable.DataSet);
            }while (BlockReadRetries < LP_READ_RETRIES && (HasLastBlockRolledOver(SetStatusBeforeRead, SetStatusAfterRead) ||
                                                           HasNewIntervalOccured(SetStatusBeforeRead, SetStatusAfterRead)));

            setStatus = SetStatusAfterRead;

            return(LastBlock);
        }
예제 #3
0
        /// <summary>
        /// Gets the first block of the load profile data
        /// </summary>
        /// <param name="actualLimitingTable">The actual limiting table that applies to the data set</param>
        /// <param name="statusTable">The status table that applies to the data set</param>
        /// <param name="dataSetTable">The data set</param>
        /// <param name="setStatus">The status record for the data set at the time of the read</param>
        /// <returns>The first block of Load Profile Data</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 10/07/08 RCG 2.00.00 N/A    Created
        // 12/12/11 RCG 2.53.20        Modified for Extended LP and IP support

        private LPBlockDataRecord GetFirstBlock(StdTable61 actualLimitingTable, StdTable63 statusTable, StdTable64 dataSetTable, out LPSetStatusRecord setStatus)
        {
            LPBlockDataRecord FirstBlock          = null;
            LPSetActualLimits SetLimits           = actualLimitingTable.GetSetLimits(dataSetTable.DataSet);
            LPSetStatusRecord SetStatusBeforeRead = null;
            LPSetStatusRecord SetStatusAfterRead  = null;
            int    BlockReadRetries = 0;
            ushort FirsBlockIndex   = 0;

            do
            {
                SetStatusBeforeRead = statusTable.GetSetStatusRecord(dataSetTable.DataSet);

                if (SetStatusBeforeRead.DataListType == LPSetStatusRecord.ListType.Circular)
                {
                    FirsBlockIndex = (ushort)((SetStatusBeforeRead.LastBlockElement + 1) % SetStatusBeforeRead.NumberOfValidBlocks);
                }

                if (SetStatusBeforeRead.NumberOfValidBlocks > 1)
                {
                    FirstBlock = ReadLPBlock(dataSetTable, FirsBlockIndex, SetLimits.IntervalsPerBlock);
                }
                else
                {
                    // The first block is the last block so we need to use the number of valid intervals
                    FirstBlock = ReadLPBlock(dataSetTable, FirsBlockIndex, SetStatusBeforeRead.NumberOfValidIntervals);
                }

                SetStatusAfterRead = statusTable.GetSetStatusRecord(dataSetTable.DataSet);
            }while (BlockReadRetries < LP_READ_RETRIES && HasLastBlockRolledOver(SetStatusBeforeRead, SetStatusAfterRead));

            setStatus = SetStatusAfterRead;

            return(FirstBlock);
        }
예제 #4
0
        /// <summary>
        /// Gets the first and last blocks of the load profile data.
        /// </summary>
        /// <param name="actualLimitingTable">The limiting table for the data set</param>
        /// <param name="statusTable">The status table for the data set</param>
        /// <param name="dataSetTable">The set to get the blocks from.</param>
        /// <param name="firstBlock">The first block.</param>
        /// <param name="lastBlock">The last block.</param>
        /// <param name="setStatus">The set status of the load profile data at the time of read.</param>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 10/07/08 RCG 2.00.00 N/A    Created
        // 12/12/11 RCG 2.53.20        Modified for Extended LP and IP support
        // 06/15/12 jrf 2.60.32 199972 Adding logging statements to help debug issue next time we see it.
        //
        private void GetFirstAndLastBlock(StdTable61 actualLimitingTable, StdTable63 statusTable, StdTable64 dataSetTable, out LPBlockDataRecord firstBlock, out LPBlockDataRecord lastBlock, out LPSetStatusRecord setStatus)
        {
            LPSetStatusRecord FirstBlockStatus;
            LPSetStatusRecord LastBlockStatus;

            m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Read First Block");
            firstBlock = GetFirstBlock(actualLimitingTable, statusTable, dataSetTable, out FirstBlockStatus);

            OnStepProgress(new ProgressEventArgs());

            if (FirstBlockStatus.NumberOfValidBlocks > 1)
            {
                m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Read Last Block");
                lastBlock = GetLastBlock(statusTable, dataSetTable, out LastBlockStatus);

                OnStepProgress(new ProgressEventArgs());

                // Make sure the first block is still valid.
                if (HasLastBlockRolledOver(FirstBlockStatus, LastBlockStatus))
                {
                    m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Read First Block, Again");
                    firstBlock = GetFirstBlock(actualLimitingTable, statusTable, dataSetTable, out FirstBlockStatus);
                }

                // At this point we do not need to check the last block again as we should never
                // have multiple block rollovers in such a short period of time. We will use the
                // last blocks status in order to ensure the values match the last block.
                setStatus = LastBlockStatus;
            }
            else
            {
                // We only have one block so we should be ok.
                OnStepProgress(new ProgressEventArgs());

                lastBlock = null;
                setStatus = FirstBlockStatus;
            }
        }
예제 #5
0
        /// <summary>
        /// Gets the load profile data between the specified dates.
        /// </summary>
        /// <param name="startDate">The start date of the load profile data to get.</param>
        /// <param name="endDate">The end date of the load profile data to get.</param>
        /// <param name="actualLimitingTable">The actual limiting table for the data set</param>
        /// <param name="controlTable">The control table for the data set</param>
        /// <param name="statusTable">The status table for the data set</param>
        /// <param name="dataSetTable">The data set table for the data set</param>
        /// <returns>The load profile data from the dates specified.</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 12/06/11 RCG 2.53.20 N/A    Created

        public LoadProfileData GetProfileData(DateTime startDate, DateTime endDate, StdTable61 actualLimitingTable, StdTable62 controlTable, StdTable63 statusTable, StdTable64 dataSetTable)
        {
            LPSetActualLimits SetLimits = actualLimitingTable.GetSetLimits(dataSetTable.DataSet);
            LPBlockDataRecord FirstBlock;
            LPBlockDataRecord LastBlock;

            LPBlockDataRecord[] Blocks;
            LPSetStatusRecord   SetStatus;
            LoadProfileData     LPData = null;

            int StartBlockIndex;
            int EndBlockIndex;
            int FirstBlockIndex;

            SetStatus = statusTable.GetSetStatusRecord(dataSetTable.DataSet);

            if (SetStatus != null)
            {
                if (SetStatus.NumberOfValidBlocks > 1 && SetStatus.NumberOfValidIntervals > 0)
                {
                    OnShowProgress(new ShowProgressEventArgs(1, 2, "Determining blocks to read...", "Determining blocks to read..."));

                    // Get the first and last blocks in order to determine the blocks we need to read.
                    GetFirstAndLastBlock(actualLimitingTable, statusTable, dataSetTable, out FirstBlock, out LastBlock, out SetStatus);

                    OnStepProgress(new ProgressEventArgs());

                    // Determine which blocks to read
                    StartBlockIndex = DetermineStartBlockIndex(SetLimits, SetStatus, FirstBlock, startDate);
                    EndBlockIndex   = DetermineEndBlockIndex(SetLimits, SetStatus, LastBlock, endDate);

                    Blocks          = new LPBlockDataRecord[EndBlockIndex - StartBlockIndex + 1];
                    FirstBlockIndex = (SetStatus.LastBlockElement + 1) % SetStatus.NumberOfValidBlocks;

                    OnHideProgress(new EventArgs());
                    OnShowProgress(new ShowProgressEventArgs(1, EndBlockIndex - StartBlockIndex, "Reading Load Profile data...", "Reading Load Profile data..."));

                    // Read the blocks
                    for (int RelativeBlockIndex = StartBlockIndex; RelativeBlockIndex <= EndBlockIndex; RelativeBlockIndex++)
                    {
                        int BlockArrayIndex = RelativeBlockIndex - StartBlockIndex;

                        OnStepProgress(new ProgressEventArgs());

                        // We already have the first and last blocks so just add those if included.
                        if (RelativeBlockIndex == 0)
                        {
                            Blocks[BlockArrayIndex] = FirstBlock;
                        }
                        else if (RelativeBlockIndex == SetStatus.NumberOfValidBlocks - 1)
                        {
                            // The last block
                            Blocks[BlockArrayIndex] = LastBlock;
                        }
                        else
                        {
                            // We need to read the block
                            ushort ActualBlockIndex = (ushort)((FirstBlockIndex + RelativeBlockIndex) % SetStatus.NumberOfValidBlocks);

                            Blocks[BlockArrayIndex] = ReadLPBlock(dataSetTable, ActualBlockIndex, SetLimits.IntervalsPerBlock);
                        }
                    }

                    OnStepProgress(new ProgressEventArgs("Creating Load Profile object..."));

                    // Create the LoadProfileData object.
                    LPData = CreateLoadProfileDataObject(Blocks, SetLimits, controlTable.GetDataSelection(dataSetTable.DataSet));

                    OnStepProgress(new ProgressEventArgs("Removing additional intervals..."));

                    // Trim out intervals that were not requested.
                    LPData.Intervals.RemoveAll(delegate(LPInterval interval) { return(interval.Time < startDate || interval.Time > endDate); });

                    OnHideProgress(new EventArgs());
                }
                else if (SetStatus.NumberOfValidBlocks == 1)
                {
                    OnShowProgress(new ShowProgressEventArgs(1, 3, "Reading Load Profile data...", "Reading Load Profile data..."));

                    // Just get the first block the trim will take care of anything outside the range
                    FirstBlock = GetFirstBlock(actualLimitingTable, statusTable, dataSetTable, out SetStatus);

                    OnStepProgress(new ProgressEventArgs());

                    LPData = CreateLoadProfileDataObject(new LPBlockDataRecord[] { FirstBlock }, SetLimits, controlTable.GetDataSelection(dataSetTable.DataSet));

                    OnStepProgress(new ProgressEventArgs());

                    // Trim out intervals that were not requested.
                    LPData.Intervals.RemoveAll(delegate(LPInterval interval) { return(interval.Time < startDate || interval.Time > endDate); });

                    OnStepProgress(new ProgressEventArgs());
                    OnHideProgress(new EventArgs());
                }
            }

            return(LPData);
        }
예제 #6
0
        /// <summary>
        /// Get the all of the Profile Data from the specified set of tables
        /// </summary>
        /// <param name="actualLimitingTable">The actual limiting table for the data set</param>
        /// <param name="controlTable">The control table for the data set</param>
        /// <param name="statusTable">The status table for the data set</param>
        /// <param name="dataSetTable">The data set table for the data set</param>
        /// <returns>The profile data that has been read.</returns>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 12/06/11 RCG 2.53.20 N/A    Created
        // 06/15/12 jrf 2.60.32 199972 Adding logging statements to help debug issue next time we see it.
        //
        protected LoadProfileData GetProfileData(StdTable61 actualLimitingTable, StdTable62 controlTable, StdTable63 statusTable, StdTable64 dataSetTable)
        {
            LoadProfileData    LPData           = null;
            LPSetActualLimits  SetLimits        = actualLimitingTable.GetSetLimits(dataSetTable.DataSet);
            LPSetDataSelection SetDataSelection = controlTable.GetDataSelection(dataSetTable.DataSet);

            LPBlockDataRecord[] Blocks;
            LPBlockDataRecord   FirstBlock;
            LPBlockDataRecord   LastBlock;
            LPSetStatusRecord   SetStatus;
            ushort NumberOfBlocks;
            ushort FirstBlockIndex;

            m_Logger.WriteLine(Logger.LoggingLevel.Functional, "Getting Profile Data");
            SetStatus = statusTable.GetSetStatusRecord(dataSetTable.DataSet);

            m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Number of Blocks: " + SetStatus.NumberOfValidBlocks.ToString(CultureInfo.InvariantCulture));
            m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Number of Intervals: " + SetStatus.NumberOfValidIntervals.ToString(CultureInfo.InvariantCulture));
            if (SetStatus.NumberOfValidBlocks > 0 && SetStatus.NumberOfValidIntervals > 0)
            {
                OnShowProgress(new ShowProgressEventArgs(1, SetStatus.NumberOfValidBlocks, "Reading Load Profile data...", "Reading Load Profile data..."));

                // Read the first and last blocks
                GetFirstAndLastBlock(actualLimitingTable, statusTable, dataSetTable, out FirstBlock, out LastBlock, out SetStatus);

                // Read the rest of the blocks using the last block status
                NumberOfBlocks = SetStatus.NumberOfValidBlocks;
                Blocks         = new LPBlockDataRecord[NumberOfBlocks];

                Blocks[0] = FirstBlock;

                if (NumberOfBlocks > 1)
                {
                    Blocks[NumberOfBlocks - 1] = LastBlock;

                    FirstBlockIndex = (ushort)((SetStatus.LastBlockElement + 1) % NumberOfBlocks);

                    for (ushort RelativeBlockIndex = 1; RelativeBlockIndex < NumberOfBlocks - 1; RelativeBlockIndex++)
                    {
                        ushort ActualBlockIndex = (ushort)((FirstBlockIndex + RelativeBlockIndex) % NumberOfBlocks);

                        m_Logger.WriteLine(Logger.LoggingLevel.Detailed, "Reading Block # " + ActualBlockIndex.ToString(CultureInfo.InvariantCulture));
                        Blocks[RelativeBlockIndex] = ReadLPBlock(dataSetTable, ActualBlockIndex, SetLimits.IntervalsPerBlock);

                        OnStepProgress(new ProgressEventArgs());
                    }
                }

                OnHideProgress(new EventArgs());

                // Create the LoadProfileData object.
                LPData = CreateLoadProfileDataObject(Blocks, SetLimits, SetDataSelection);
            }

            return(LPData);
        }