protected DataValue ComputeNumberOfTransitions(TimeSlice slice)
{
// get the values in the slice.
List<DataValue> values = GetValues(slice);
// check for empty slice.
if (values == null)
{
return GetNoDataValue(slice);
}
// determine whether a transition occurs at the StartTime
double lastValue = Double.NaN;
if (slice.EarlyBound != null)
{
if (StatusCode.IsGood(slice.EarlyBound.Value.StatusCode))
{
try
{
lastValue = CastToDouble(slice.EarlyBound.Value);
}
catch (Exception)
{
lastValue = Double.NaN;
}
}
}
// count the transitions.
int count = 0;
for (int ii = 0; ii < values.Count; ii++)
{
if (!IsGood(values[ii]))
{
continue;
}
double nextValue = 0;
try
{
nextValue = CastToDouble(values[ii]);
}
catch (Exception)
{
continue;
}
if (!Double.IsNaN(lastValue))
{
if (lastValue != nextValue)
{
count++;
}
}
lastValue = nextValue;
}
// set the timestamp and status.
DataValue value = new DataValue();
value.WrappedValue = new Variant(count, TypeInfo.Scalars.Int32);
value.SourceTimestamp = GetTimestamp(slice);
value.ServerTimestamp = GetTimestamp(slice);
value.StatusCode = value.StatusCode.SetAggregateBits(AggregateBits.Calculated);
value.StatusCode = GetValueBasedStatusCode(slice, values, value.StatusCode);
// return result.
return value;
}
#endregion