Average Value of Previous Hour
The equation can be used to calculate the average value of each previous hour.
bool FirstIn = true;
int HourIndex = 0;
double AverageValue = 0;
double SumValue = 0;
int PreviousHour = 0;
//Equation to calculate the average value of the previous hour
public double HourAverage(double Input)
//first time get in this function, initialize some variables.
FirstIn = false;
SumValue = Input;
AverageValue = Input;
PreviousHour = this.StartTime.Hour;
CurrentTime = this.StartTime;
CurrentTime = CurrentTime.AddSeconds(this.SampleInterval);
if (CurrentTime.Hour != PreviousHour)
PreviousHour = CurrentTime.Hour;
AverageValue = SumValue / HourIndex;
SumValue = 0;
HourIndex = 0;
SumValue += Input;
//Average value of the previous hour.
//Note: the first hours value is always the first reading