private bool UpdateFrames(UnitInfo unit, int startingFrame, int endingFrame, ProteinBenchmark benchmark) { bool result = false; for (int i = startingFrame; i <= endingFrame; i++) { WorkUnitFrameData frameData = unit.GetFrameData(i); if (frameData != null) { if (benchmark.SetFrameDuration(frameData.Duration)) { result = true; } } else { Logger.DebugFormat("({0}) FrameID '{1}' not found for Project {2}", unit.OwningSlotName, i, unit.ProjectID); } } return(result); }
/// <summary> /// Get the average duration over the specified number of most recent frames /// </summary> /// <param name="numberOfFrames">Number of most recent frames</param> private int GetDurationInSeconds(int numberOfFrames) { // the numberOfFrames must be 1 or greater // if CurrentFrame is null then no frames have been captured yet if (numberOfFrames < 1 || _unitInfo.CurrentFrame == null) { return(0); } // init return value int averageSeconds = 0; // Make sure we only add frame durations greater than a Zero TimeSpan // The first frame will always have a Zero TimeSpan for frame duration // we don't want to take this frame into account when calculating 'AllFrames' - Issue 23 TimeSpan totalTime = TimeSpan.Zero; int countFrames = 0; int frameId = _unitInfo.CurrentFrame.ID; for (int i = 0; i < numberOfFrames; i++) { // Issue 199 var frameData = _unitInfo.GetFrameData(frameId); if (frameData != null && frameData.Duration > TimeSpan.Zero) { totalTime = totalTime.Add(frameData.Duration); countFrames++; } frameId--; } if (countFrames > 0) { averageSeconds = Convert.ToInt32(totalTime.TotalSeconds) / countFrames; } return(averageSeconds); }