protected StatusCode GetValueBasedStatusCode(TimeSlice slice, List<DataValue> values, StatusCode statusCode)
{
// compute the total good/bad/uncertain.
double badCount = 0;
double goodCount = 0;
double totalCount = 0;
for (int ii = 0; ii < values.Count; ii++)
{
totalCount++;
if (StatusCode.IsBad(values[ii].StatusCode))
{
badCount++;
continue;
}
if (StatusCode.IsGood(values[ii].StatusCode))
{
goodCount++;
}
}
// default to good.
statusCode = statusCode.SetCodeBits(StatusCodes.Good);
// uncertain if the good duration is less than the configured threshold.
if ((goodCount / totalCount) * 100 < Configuration.PercentDataGood)
{
statusCode = statusCode.SetCodeBits(StatusCodes.UncertainDataSubNormal);
}
// bad if the bad duration is greater than or equal to the configured threshold.
if ((badCount / totalCount) * 100 >= Configuration.PercentDataBad)
{
statusCode = StatusCodes.Bad;
}
return statusCode;
}