protected StatusCode GetTimeBasedStatusCode(List<SubRegion> regions, StatusCode statusCode)
{
// check for empty set.
if (regions == null || regions.Count == 0)
{
return StatusCodes.BadNoData;
}
// compute the total good/bad/uncertain.
double badDuration = 0;
double goodDuration = 0;
double totalDuration = 0;
foreach (SubRegion region in regions)
{
totalDuration += region.Duration;
if (StatusCode.IsBad(region.StatusCode))
{
badDuration += region.Duration;
continue;
}
if (StatusCode.IsGood(region.StatusCode))
{
goodDuration += region.Duration;
}
}
// default to good.
statusCode = statusCode.SetCodeBits(StatusCodes.Good);
// uncertain if the good duration is less than the configured threshold.
if ((goodDuration/totalDuration)*100 < Configuration.PercentDataGood)
{
statusCode = statusCode.SetCodeBits(StatusCodes.UncertainDataSubNormal);
}
// bad if the bad duration is greater than or equal to the configured threshold.
if ((badDuration/totalDuration)*100 >= Configuration.PercentDataBad)
{
statusCode = StatusCodes.Bad;
}
// always calculated.
return statusCode;
}
#endregion