1.877.352.9158  (Price in US$)

Welcome Guest!   

My Account  |  Cart Contents  |  Checkout

Quick Links To Products
Average Value of Previous Hour
Equation Description:
The equation can be used to calculate the average value of each previous hour.
Equation Contents:
DateTime CurrentTime ;
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.
if(FirstIn)
{
FirstIn = false;
SumValue = Input;
AverageValue = Input;
PreviousHour = this.StartTime.Hour;
CurrentTime = this.StartTime;
}
else
{
CurrentTime = CurrentTime.AddSeconds(this.SampleInterval);
if(CurrentTime.Hour != PreviousHour)
{
PreviousHour = CurrentTime.Hour;
AverageValue = SumValue / HourIndex;
SumValue = 0;
HourIndex = 0;
}
SumValue += Input;
}
HourIndex++;
//Average value of the previous hour.
//Note: the first hours value is always the first reading
return AverageValue;
}