/// <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); }
/// <summary> /// Determines the relative index of the block that contains the start date specified. /// </summary> /// <param name="setLimits">The actual limits for the data set.</param> /// <param name="setStatus">The status of the data set when last block was read.</param> /// <param name="firstBlock">The last block in the data set.</param> /// <param name="startDate">The start date that is being searched for.</param> /// <returns>The relative index of the block that contains the start date.</returns> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 10/08/08 RCG 2.00.00 N/A Created private int DetermineStartBlockIndex(LPSetActualLimits setLimits, LPSetStatusRecord setStatus, LPBlockDataRecord firstBlock, DateTime startDate) { int StartBlockIndex = 0; bool IncludeFirstBlock; IncludeFirstBlock = startDate <= firstBlock.BlockEndTime; if (!IncludeFirstBlock) { // We need to determine the starting block for (int iBlock = 1; iBlock < setStatus.NumberOfValidBlocks; iBlock++) { DateTime BlockEndTime = (DateTime)firstBlock.BlockEndTime; BlockEndTime = BlockEndTime.AddMinutes(iBlock * setLimits.IntervalsPerBlock * setLimits.IntervalLength); if (BlockEndTime >= startDate) { StartBlockIndex = iBlock; break; } } } else { StartBlockIndex = 0; } return(StartBlockIndex); }
/// <summary> /// Determines if the last block has rolled over in the data set. /// </summary> /// <param name="initialSetStatus">The initial set status for the data set.</param> /// <param name="currentSetStatus">The new set status for the data set.</param> /// <returns>True if the last block has rolled over since the initial status. False otherwise.</returns> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 10/07/08 RCG 2.00.00 N/A Created private bool HasLastBlockRolledOver(LPSetStatusRecord initialSetStatus, LPSetStatusRecord currentSetStatus) { bool bHasBlockIndexChanged = initialSetStatus.LastBlockElement != currentSetStatus.LastBlockElement; bool bHasIntervalCountBeenReset = initialSetStatus.NumberOfValidIntervals > currentSetStatus.NumberOfValidIntervals; // In the case of a FIFO list we also need to make sure that the number of valid intervals has not been reset. return(bHasBlockIndexChanged || bHasIntervalCountBeenReset); }
/// <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); }
/// <summary> /// Determines the relative index of the block that contains the end date specified. /// </summary> /// <param name="setLimits">The actual limits for the data set.</param> /// <param name="setStatus">The status of the data set when last block was read.</param> /// <param name="lastBlock">The last block in the data set.</param> /// <param name="endDate">The end date that is being searched for.</param> /// <returns>The relative index of the block that contains the end time.</returns> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 10/08/08 RCG 2.00.00 N/A Created // 09/22/09 AF 2.30.02 Corrected the equation for determining last block private int DetermineEndBlockIndex(LPSetActualLimits setLimits, LPSetStatusRecord setStatus, LPBlockDataRecord lastBlock, DateTime endDate) { int EndBlockIndex = 0; DateTime LastBlockStartTime; bool IncludeLastBlock; LastBlockStartTime = DetermineIntervalTime(lastBlock, 0, setLimits.IntervalLength); if (lastBlock.Intervals.Length > 1) { LastBlockStartTime = AdjustTimeForDST(LastBlockStartTime, lastBlock.Intervals[0], lastBlock.Intervals[1], lastBlock.Intervals[setStatus.NumberOfValidIntervals - 1]); } IncludeLastBlock = endDate >= LastBlockStartTime; if (!IncludeLastBlock) { // We need to determine the last block. Start at the next to last block for (int iBlock = setStatus.NumberOfValidBlocks - 2; iBlock >= 1; iBlock--) { DateTime BlockStartTime = LastBlockStartTime; BlockStartTime = BlockStartTime.AddMinutes(-1 * (setStatus.NumberOfValidBlocks - (iBlock + 1)) * setLimits.IntervalsPerBlock * setLimits.IntervalLength); if (BlockStartTime <= endDate) { EndBlockIndex = iBlock; break; } } } else { EndBlockIndex = setStatus.NumberOfValidBlocks - 1; } return(EndBlockIndex); }
/// <summary> /// Determines if a new interval has occurred since the initial reading. /// </summary> /// <param name="initialSetStatus">The initial set status for the load profile data.</param> /// <param name="currentSetStatus">The current set status for the load profile data.</param> /// <returns>True if a new interval has occurred. False otherwise.</returns> // Revision History // MM/DD/YY who Version Issue# Description // -------- --- ------- ------ --------------------------------------- // 10/07/08 RCG 2.00.00 N/A Created private bool HasNewIntervalOccured(LPSetStatusRecord initialSetStatus, LPSetStatusRecord currentSetStatus) { return(initialSetStatus.NumberOfValidIntervals != currentSetStatus.NumberOfValidIntervals); }
/// <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; } }