/* * AverageOverTime.cs * * Copyright © 2009 * Diversified Technical Systems, Inc. * All Rights Reserved */ using System.Collections.Generic; namespace DTS.Common.Utilities { /// /// A class to represent the average value of a dynamically specified set over time. This /// class is intended to be used to keep a running average of sets of piecemeal-collected /// data, and it is assumed that a subclass will implement the type-specific features of /// this task. /// /// /// /// The type we're talking the average value over time of. /// /// public abstract class AverageValueOverTime : Exceptional { /// /// Initialize an instance of the AverageValueOverTime class, assuming that no /// averaging has been done yet. /// /// /// /// The begin time of the average (using the time units specified /// by the "TimeUnitSymbol" property. /// /// /// /// The sample rate of the items being averaged (using the time units /// specifed by the "TimeUnitSymbol" property. /// /// /// /// The "zero" value of our generic data type. /// /// /// /// The time unit description for begin/end times and the sample rate. /// /// protected AverageValueOverTime(double initialTime, double sampleRate, T initialAverage, string timeUnitSymbol) : this(initialTime, initialTime, sampleRate, initialAverage, timeUnitSymbol) { } /// /// Initialize an instance of the AverageValueOverTime class. /// /// /// /// The begin time of the average (using the time units specified /// by the "TimeUnitSymbol" property. /// /// /// /// The end time of the average (using the time units specified /// by the "TimeUnitSymbol" property. /// /// /// /// The sample rate of the items being averaged (using the time units /// specifed by the "TimeUnitSymbol" property. /// /// /// /// The initial average value to be appended to. /// /// /// /// The time unit description for begin/end times and the sample rate. /// /// protected AverageValueOverTime(double beginTime, double endTime, double sampleRate, T initialAverage, string timeUnitSymbol) { try { // // Initialize the known knowns. // BeginTime = beginTime; EndTime = endTime; SampleRate = sampleRate; TimeUnitSymbol = timeUnitSymbol; CurrentAverage = initialAverage; } catch (System.Exception ex) { throw new Exception("encountered problem constructing " + GetType().FullName, ex); } } // // These properties should be useful no matter what we're taking // the running average of. // /// /// Beginning Time /// public double BeginTime { get; protected set; } /// /// Ending Time /// public double EndTime { get; protected set; } /// /// The sampling rate /// public double SampleRate { get; protected set; } /// /// the time unit symbol /// public string TimeUnitSymbol { get; protected set; } /// /// the current average /// public T CurrentAverage { get; protected set; } /// /// appends a list of values /// /// list of values /// inheriting clases should know more about the nature of the data type /// and averaging them over time. /// public abstract void AppendValues(List values); /// /// appends an array of values /// /// array of values /// inheriting clases should know more about the nature of the data type /// and averaging them over time. /// public abstract void AppendValues(T[] values); } }