public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { StatusCode returnCode = StatusCodes.BadNoData; foreach (DataValue dv in bucket.Values) { if (returnCode == StatusCodes.BadNoData) { returnCode = dv.StatusCode; } else { // StatusCodes.Bad = 0x80000000 // StatusCodes.Uncertain = 0x40000000 // StatusCodes.Good = 0x00000000 uint code = dv.StatusCode.Code >> 28; // 7 Hexadecimal digits = 28 binary digits. switch (code) { case 8: // 8 is maximum returnCode = StatusCodes.Bad; break; case 4: if (StatusCode.IsNotBad(returnCode)) { returnCode = StatusCodes.Uncertain; } break; case 0: // 0 is minimum break; default: Debug.Assert(true, "should not touch this line"); throw new Exception(String.Format("Unknown error in WorstQuality aggregate calculation, code = {0}", dv.StatusCode)); } } } DataValue retVal = new DataValue() { SourceTimestamp = bucket.From }; if (returnCode != StatusCodes.BadNoData) { retVal.Value = returnCode; StatusCode status = StatusCodes.Good; status.AggregateBits |= AggregateBits.Calculated; if (bucket.Incomplete) { status.AggregateBits |= AggregateBits.Partial; } retVal.StatusCode = status; } else { retVal.StatusCode = returnCode; } return(retVal); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = base.ComputeStatus(context, numGood, numBad, bucket); if (bucket.EarlyBound.Value == null || StatusCode.IsNotGood(bucket.EarlyBound.Value.StatusCode)) code = StatusCodes.Uncertain; return code; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue initValue = bucket.EarlyBound.Value, finalValue = bucket.LateBound.Value; IEnumerator <DataValue> enumerator = bucket.Values.GetEnumerator(); if (initValue == null && enumerator.MoveNext()) // first element { initValue = enumerator.Current; bucket.Incomplete = true; } if (finalValue == null) { while (enumerator.MoveNext()) { finalValue = enumerator.Current; } bucket.Incomplete = true; } DataValue retVal = base.Compute(context, bucket, state); if (retVal.StatusCode.CodeBits == StatusCodes.BadNoData) { retVal.Value = null; } else { retVal.Value = Convert.ToDouble(retVal.Value) / Math.Abs((finalValue.SourceTimestamp - initValue.SourceTimestamp).TotalMilliseconds); // revisit } return(retVal); }
/// <summary> /// Calculates the status for the time slice. /// </summary> protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = (bucket.EarlyBound.Value == null && numGood + numBad == 0) ? // no inital bound, do not extrapolate StatusCodes.BadNoData : base.ComputeStatus(context, numGood, numBad, bucket); return(code); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = base.ComputeStatus(context, numGood, numBad, bucket); if (code.CodeBits == StatusCodes.GoodNoData) // can be removed if GoodNoData is used. code = StatusCodes.Good; return code; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue previous = RightState(bucket.EarlyBound.Value) ? bucket.EarlyBound.Value : null; double total = 0.0; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = StatusCodes.BadNoData; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; if (previous != null) total += (v.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; previous = RightState(v) ? v : null; } else { numBad += 1; } } if (previous != null) total += (bucket.LateBound.Value.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; retval.Value = total; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; double total = 0.0; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; total += Convert.ToDouble(v.Value, CultureInfo.InvariantCulture); } else { numBad += 1; } } DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; if (StatusCode.IsNotBad(code)) retval.Value = total; retval.StatusCode = code; GoodDataCount = numGood; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; } else { numBad += 1; } } StatusCode code = StatusCodes.Good; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; retval.Value = numGood; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = base.ComputeStatus(context, numGood, numBad, bucket); if (bucket.EarlyBound.Value == null || StatusCode.IsNotGood(bucket.EarlyBound.Value.StatusCode)) code = StatusCodes.Uncertain; return code; }
/// <summary> /// Computes the status code for the processing interval using the percent good/bad information in the context. /// </summary> protected virtual StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { var total = numGood + numBad; if (total > 0) { double pbad = numBad * 100 / total; if (pbad > context.PercentDataBad) { return(StatusCodes.Bad); } double pgood = numGood * 100 / total; if (pgood >= context.PercentDataGood) { return(StatusCodes.Good); } return(StatusCodes.Uncertain); } else { return(StatusCodes.GoodNoData); } }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue dv = base.Compute(context, bucket, state); double duration = Convert.ToDouble(dv.Value) / Math.Abs((bucket.To - bucket.From).TotalMilliseconds) * 100; dv.Value = duration; return dv; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue initValue = bucket.EarlyBound.Value, finalValue = bucket.LateBound.Value; IEnumerator<DataValue> enumerator = bucket.Values.GetEnumerator(); if (initValue == null && enumerator.MoveNext()) // first element { initValue = enumerator.Current; bucket.Incomplete = true; } if (finalValue == null) { while (enumerator.MoveNext()) { finalValue = enumerator.Current; } bucket.Incomplete = true; } DataValue retVal = base.Compute(context, bucket, state); if (retVal.StatusCode.CodeBits == StatusCodes.BadNoData) retVal.Value = null; else retVal.Value = Convert.ToDouble(retVal.Value) / Math.Abs((finalValue.SourceTimestamp - initValue.SourceTimestamp).TotalMilliseconds); // revisit return retVal; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { List<DataValue> l = new List<DataValue>(bucket.Values); DataValue dv = l.Count > 0 ? GetDataValue(l) : null; if (SteppedVariable && dv == null) dv = bucket.LateBound.Value; DataValue retval = new DataValue(); StatusCode code = StatusCodes.BadNoData; if (dv != null) { code = StatusCode.IsNotGood(dv.StatusCode) ? StatusCodes.UncertainDataSubNormal : StatusCodes.Good; retval.SourceTimestamp = dv.SourceTimestamp; retval.Value = dv.Value; code.AggregateBits = AggregateBits.Raw; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; } else { retval.SourceTimestamp = bucket.From; } retval.StatusCode = code; return retval; }
/// <summary> /// Creates a new instance. /// </summary>> public AggregateState(IAggregationContext context, IAggregationActor actor) { AggregationContext = context; AggregationActor = actor; CurrentBadPoints = new List <DataValue>(); PriorBadPoints = new List <DataValue>(); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { List <DataValue> l = new List <DataValue>(bucket.Values); DataValue dv = l.Count > 0 ? GetDataValue(l) : null; if (SteppedVariable && dv == null) { dv = bucket.LateBound.Value; } DataValue retval = new DataValue(); StatusCode code = StatusCodes.BadNoData; if (dv != null) { code = StatusCode.IsNotGood(dv.StatusCode) ? StatusCodes.UncertainDataSubNormal : StatusCodes.Good; retval.SourceTimestamp = dv.SourceTimestamp; retval.Value = dv.Value; code.AggregateBits = AggregateBits.Raw; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } } else { retval.SourceTimestamp = bucket.From; } retval.StatusCode = code; return(retval); }
protected abstract bool Comparison(DataValue value1, DataValue value2); // true if keep value1. public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue valueToKeep = new DataValue() { SourceTimestamp = bucket.From, StatusCode = StatusCodes.BadNoData }; bool moreData = false; bool hasGoodData = false; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { hasGoodData = true; if (valueToKeep.StatusCode == StatusCodes.BadNoData) { valueToKeep = dv; } else { moreData = valueToKeep == dv; if (Comparison(dv, valueToKeep)) { valueToKeep = dv; } } numGood++; } else { numBad++; if (!hasGoodData) { valueToKeep = dv; } } } DataValue retval = valueToKeep.StatusCode == StatusCodes.BadNoData ? valueToKeep : (DataValue)valueToKeep.Clone(); if (hasGoodData) { StatusCode code = StatusCodes.Good; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = moreData ? AggregateBits.ExtraData : AggregateBits.Raw; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; } // numGood = 0, hasGoodData = false beyond this point, i.e., no good data else if (numBad > 0) { retval.Value = null; retval.StatusCode = StatusCodes.Bad; retval.StatusCode = retval.StatusCode.SetAggregateBits(AggregateBits.Raw); } return(retval); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; double minV = double.MaxValue; double maxV = double.MinValue; bool uncertainDataSubNormal = false; double range = double.NaN; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { double v = Convert.ToDouble(dv.Value); if (minV > v) { minV = v; } if (maxV < v) { maxV = v; } numGood++; } else { uncertainDataSubNormal = true; numBad++; } } if (minV != double.MaxValue && maxV != double.MinValue) { range = Math.Abs(maxV - minV); } StatusCode code = (uncertainDataSubNormal) ? StatusCodes.UncertainDataSubNormal : StatusCodes.Good; if (numGood + numBad == 0) { code = StatusCodes.BadNoData; } DataValue retval = new DataValue { SourceTimestamp = bucket.From }; if (!double.IsNaN(range)) { retval.Value = range; } code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { if (numGood + numBad == 0) return StatusCodes.GoodNoData; if (numGood == 0 && numBad > 0) return StatusCodes.Bad; return base.ComputeStatus(context, numGood, numBad, bucket); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue dv = base.Compute(context, bucket, state); double duration = Convert.ToDouble(dv.Value) / Math.Abs((bucket.To - bucket.From).TotalMilliseconds) * 100; dv.Value = duration; return(dv); }
/// <summary> /// Calculates the value for the time slice. /// </summary> public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { var retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = StatusCodes.Good; var previous = new DataValue { SourceTimestamp = bucket.From }; if (bucket.EarlyBound.Value != null) { previous.StatusCode = (StatusCode)bucket.EarlyBound.Value.WrappedValue.Value; } else { previous.StatusCode = StatusCodes.Bad; } if (!RightStatusCode(previous)) { previous = null; } var total = 0.0; foreach (var v in bucket.Values) { if (previous != null) { total += (v.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; } if (RightStatusCode(v)) { previous = v; } else { previous = null; } } if (previous != null) { total += (bucket.To - previous.SourceTimestamp).TotalMilliseconds; } retval.Value = total; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = base.ComputeStatus(context, numGood, numBad, bucket); if (code.CodeBits == StatusCodes.GoodNoData) // can be removed if GoodNoData is used. { code = StatusCodes.Good; } return(code); }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { if (numGood + numBad == 0) { return(StatusCodes.GoodNoData); } if (numGood == 0 && numBad > 0) { return(StatusCodes.Bad); } return(base.ComputeStatus(context, numGood, numBad, bucket)); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue dv = base.Compute(context, bucket, state); if (dv.SourceTimestamp != bucket.From) { dv.SourceTimestamp = bucket.From; StatusCode code = dv.StatusCode; code.AggregateBits |= AggregateBits.Calculated; dv.StatusCode = code; } return dv; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue firstGoodDv = null; DataValue lastGoodDv = null; DataValue lastDv = null; bool uncertainDataSubNormal = false; double delta = double.NaN; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { if (firstGoodDv == null) { firstGoodDv = dv; } lastGoodDv = dv; numGood++; } else { // check for non-good value occuring before first good value if (firstGoodDv == null) uncertainDataSubNormal = true; numBad++; } lastDv = dv; } if (firstGoodDv != null) { double fv = Convert.ToDouble(firstGoodDv.Value); double lv = Convert.ToDouble(lastGoodDv.Value); delta = lv - fv; } // check for non-good value occuring after latest good value if (!uncertainDataSubNormal && lastGoodDv != null && lastGoodDv.SourceTimestamp < lastDv.SourceTimestamp) uncertainDataSubNormal = true; StatusCode code = (uncertainDataSubNormal) ? StatusCodes.UncertainDataSubNormal : (numGood > 0) ? StatusCodes.Good : StatusCodes.BadNoData; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; if (!double.IsNaN(delta)) retval.Value = delta; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue dv = base.Compute(context, bucket, state); if (dv.SourceTimestamp != bucket.From) { dv.SourceTimestamp = bucket.From; StatusCode code = dv.StatusCode; code.AggregateBits |= AggregateBits.Calculated; dv.StatusCode = code; } return(dv); }
protected abstract bool Comparison(DataValue value1, DataValue value2); // true if keep value1. public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue valueToKeep = new DataValue() { SourceTimestamp = bucket.From, StatusCode = StatusCodes.BadNoData }; bool moreData = false; bool hasGoodData = false; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { hasGoodData = true; if (valueToKeep.StatusCode == StatusCodes.BadNoData) { valueToKeep = dv; } else { moreData = valueToKeep == dv; if (Comparison(dv, valueToKeep)) { valueToKeep = dv; } } numGood++; } else { numBad++; if (!hasGoodData) valueToKeep = dv; } } DataValue retval = valueToKeep.StatusCode == StatusCodes.BadNoData ? valueToKeep : (DataValue)valueToKeep.Clone(); if (hasGoodData) { StatusCode code = StatusCodes.Good; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = moreData ? AggregateBits.ExtraData : AggregateBits.Raw; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; } // numGood = 0, hasGoodData = false beyond this point, i.e., no good data else if(numBad > 0) { retval.Value = null; retval.StatusCode = StatusCodes.Bad; retval.StatusCode = retval.StatusCode.SetAggregateBits(AggregateBits.Raw); } return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = StatusCodes.BadNoData; DataValue boundValue = context.IsReverseAggregation ? bucket.LateBound.Value : bucket.EarlyBound.Value; if (boundValue != null) { code = bucket.EarlyBound.Value.StatusCode.Code; code.AggregateBits = bucket.EarlyBound.Value.StatusCode.AggregateBits; retval.Value = Convert.ToDouble(bucket.EarlyBound.Value.Value, CultureInfo.InvariantCulture); } if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue initValue = bucket.EarlyBound.Value; IEnumerator<DataValue> enumerator = bucket.Values.GetEnumerator(); if (enumerator.MoveNext()) // first element { if(initValue == null && bucket.From != enumerator.Current.SourceTimestamp) bucket.Incomplete = true; } DataValue retVal = base.Compute(context, bucket, state); if (GoodDataCount > 0) retVal.Value = Convert.ToDouble(retVal.Value) / GoodDataCount; else retVal.Value = null; return retVal; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { StatusCode returnCode = StatusCodes.BadNoData; foreach(DataValue dv in bucket.Values) { if (returnCode == StatusCodes.BadNoData) { returnCode = dv.StatusCode; } else { // StatusCodes.Bad = 0x80000000 // StatusCodes.Uncertain = 0x40000000 // StatusCodes.Good = 0x00000000 uint code = dv.StatusCode.Code >> 28; // 7 Hexadecimal digits = 28 binary digits. switch (code) { case 8: // 8 is maximum returnCode = StatusCodes.Bad; break; case 4: if(StatusCode.IsNotBad(returnCode)) returnCode = StatusCodes.Uncertain; break; case 0: // 0 is minimum break; default: Debug.Assert(true, "should not touch this line"); throw new Exception(String.Format("Unknown error in WorstQuality aggregate calculation, code = {0}", dv.StatusCode)); } } } DataValue retVal = new DataValue() { SourceTimestamp = bucket.From }; if (returnCode != StatusCodes.BadNoData) { retVal.Value = returnCode; StatusCode status = StatusCodes.Good; status.AggregateBits |= AggregateBits.Calculated; if (bucket.Incomplete) status.AggregateBits |= AggregateBits.Partial; retVal.StatusCode = status; } else { retVal.StatusCode = returnCode; } return retVal; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; double minV = double.MaxValue; double maxV = double.MinValue; bool uncertainDataSubNormal = false; double range = double.NaN; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { double v = Convert.ToDouble(dv.Value); if (minV > v) { minV = v; } if (maxV < v) { maxV = v; } numGood++; } else { uncertainDataSubNormal = true; numBad++; } } if (minV != double.MaxValue && maxV != double.MinValue) { range = Math.Abs(maxV - minV); } StatusCode code = (uncertainDataSubNormal) ? StatusCodes.UncertainDataSubNormal : StatusCodes.Good; if (numGood + numBad == 0) code = StatusCodes.BadNoData; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; if (!double.IsNaN(range)) retval.Value = range; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue previous = RightState(bucket.EarlyBound.Value) ? bucket.EarlyBound.Value : null; double total = 0.0; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = StatusCodes.BadNoData; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; if (previous != null) { total += (v.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; } previous = RightState(v) ? v : null; } else { numBad += 1; } } if (previous != null) { total += (bucket.LateBound.Value.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; } retval.Value = total; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = StatusCodes.BadNoData; DataValue boundValue = context.IsReverseAggregation ? bucket.LateBound.Value : bucket.EarlyBound.Value; if (boundValue != null) { code = bucket.EarlyBound.Value.StatusCode.Code; code.AggregateBits = bucket.EarlyBound.Value.StatusCode.AggregateBits; retval.Value = Convert.ToDouble(bucket.EarlyBound.Value.Value, CultureInfo.InvariantCulture); } if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue initValue = bucket.EarlyBound.Value; IEnumerator <DataValue> enumerator = bucket.Values.GetEnumerator(); if (enumerator.MoveNext()) // first element { if (initValue == null && bucket.From != enumerator.Current.SourceTimestamp) { bucket.Incomplete = true; } } DataValue retVal = base.Compute(context, bucket, state); if (GoodDataCount > 0) { retVal.Value = Convert.ToDouble(retVal.Value) / GoodDataCount; } else { retVal.Value = null; } return(retVal); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; double total = 0.0; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; total += Convert.ToDouble(v.Value, CultureInfo.InvariantCulture); } else { numBad += 1; } } DataValue retval = new DataValue { SourceTimestamp = bucket.From }; StatusCode code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } if (StatusCode.IsNotBad(code)) { retval.Value = total; } retval.StatusCode = code; GoodDataCount = numGood; return(retval); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; } else { numBad += 1; } } StatusCode code = StatusCodes.Good; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; retval.Value = numGood; code = ComputeStatus(context, numGood, numBad, bucket).Code; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { return numBad + numGood == 0 ? StatusCodes.BadNoData : base.ComputeStatus(context, numGood, numBad, bucket); }
/// <summary> /// Creates a new instance. /// </summary>> public AggregateState(IAggregationContext context, IAggregationActor actor) { AggregationContext = context; AggregationActor = actor; CurrentBadPoints = new List<DataValue>(); PriorBadPoints = new List<DataValue>(); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; int nTransitions = 0; long stateCode = -1; IEnumerator<DataValue> enumerator = bucket.Values.GetEnumerator(); bool bucketValueNotEmpty = enumerator.MoveNext(); if (bucketValueNotEmpty && enumerator.Current != null) { if (bucket.EarlyBound != null) { if (enumerator.Current.SourceTimestamp == bucket.EarlyBound.Timestamp && bucket.EarlyBound.PriorPoint != null) { stateCode = Convert.ToInt32(Convert.ToBoolean(bucket.EarlyBound.PriorPoint.Value)); } else if (bucket.EarlyBound.Value != null) { stateCode = Convert.ToInt32(Convert.ToBoolean(bucket.EarlyBound.Value.Value)); } } } // viz. UA MultiStateNodeState & TwoStateNodeState, // assume DataValue.Value is either an EnumValueType or a bool if (bucketValueNotEmpty) { do { DataValue dv = enumerator.Current; if (state.RawValueIsGood(dv)) { EnumValueType ev = dv.Value as EnumValueType; if (ev == null) { bool b; if (bool.TryParse(dv.Value.ToString(), out b)) { if (stateCode < 0) stateCode = b ? 1 : 0; else if (b.CompareTo(Convert.ToBoolean(stateCode)) != 0) { nTransitions++; stateCode = b ? 1 : 0; } } else continue; } else { long s = ev.Value; if (stateCode < 0) stateCode = s; else if (!s.Equals(stateCode)) { nTransitions++; stateCode = s; } } numGood++; } else { numBad++; } } while (enumerator.MoveNext()); } StatusCode code = ComputeStatus(context, numGood, numBad, bucket).Code; DataValue retval = new DataValue { SourceTimestamp = bucket.From, Value = nTransitions }; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; DataValue firstGoodDv = null; DataValue lastGoodDv = null; DataValue lastDv = null; bool uncertainDataSubNormal = false; double delta = double.NaN; foreach (DataValue dv in bucket.Values) { if (state.RawValueIsGood(dv)) { if (firstGoodDv == null) { firstGoodDv = dv; } lastGoodDv = dv; numGood++; } else { // check for non-good value occuring before first good value if (firstGoodDv == null) { uncertainDataSubNormal = true; } numBad++; } lastDv = dv; } if (firstGoodDv != null) { double fv = Convert.ToDouble(firstGoodDv.Value); double lv = Convert.ToDouble(lastGoodDv.Value); delta = lv - fv; } // check for non-good value occuring after latest good value if (!uncertainDataSubNormal && lastGoodDv != null && lastGoodDv.SourceTimestamp < lastDv.SourceTimestamp) { uncertainDataSubNormal = true; } StatusCode code = (uncertainDataSubNormal) ? StatusCodes.UncertainDataSubNormal : (numGood > 0) ? StatusCodes.Good : StatusCodes.BadNoData; DataValue retval = new DataValue { SourceTimestamp = bucket.From }; if (!double.IsNaN(delta)) { retval.Value = delta; } code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
/// <summary> /// Computes the aggregate value for the time slice. /// </summary> public abstract DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state);
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue retval = new DataValue { SourceTimestamp = bucket.From }; DataValue initValue = bucket.EarlyBound.Value, finalValue = bucket.LateBound.Value; IEnumerator<DataValue> enumerator = bucket.Values.GetEnumerator(); StatusCode code = StatusCodes.BadNoData; if (initValue == null && enumerator.MoveNext()) // first element { initValue = enumerator.Current; } if (finalValue == null) { while (enumerator.MoveNext()) { finalValue = enumerator.Current; } } if (initValue != null && finalValue != null) { int numGood = 0; int numBad = 0; double total = 0.0; double early = 0.0; double late = 0.0; double width = 0.0; Debug.WriteLine(String.Format("bucket starts @ {0}, ends @ {1}", bucket.From.TimeOfDay, bucket.To.TimeOfDay)); if ((initValue.StatusCode.AggregateBits & AggregateBits.Raw) == 0) { if (state.RawValueIsGood(initValue)) numGood += 1; else numBad += 1; } if ((finalValue.StatusCode.AggregateBits & AggregateBits.Raw) == 0) { if (state.RawValueIsGood(finalValue)) numGood += 1; else numBad += 1; } DataValue preceding = initValue; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; early = Convert.ToDouble(preceding.Value, CultureInfo.InvariantCulture); late = Convert.ToDouble(v.Value, CultureInfo.InvariantCulture); width = (v.SourceTimestamp - preceding.SourceTimestamp).TotalMilliseconds; total += SteppedVariable ? width * early : width * (late + early) / 2; preceding = v; } else { numBad += 1; } } early = Convert.ToDouble(preceding.Value, CultureInfo.InvariantCulture); late = Convert.ToDouble(finalValue.Value, CultureInfo.InvariantCulture); width = (finalValue.SourceTimestamp - preceding.SourceTimestamp).TotalMilliseconds; total += SteppedVariable ? width * early : width * (late + early) / 2; retval.Value = total; code = ComputeStatus(context, numGood, numBad, bucket).Code; } code.AggregateBits = AggregateBits.Calculated; if (StatusCode.IsNotBad(code) && bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue retval = new DataValue { SourceTimestamp = bucket.From }; DataValue initValue = bucket.EarlyBound.Value, finalValue = bucket.LateBound.Value; IEnumerator<DataValue> enumerator = bucket.Values.GetEnumerator(); StatusCode code = StatusCodes.BadNoData; if (initValue == null && enumerator.MoveNext()) // first element { initValue = enumerator.Current; } if (finalValue == null) { while (enumerator.MoveNext()) { finalValue = enumerator.Current; } } if (initValue != null && finalValue != null) { int numGood = 0; int numBad = 0; double total = 0.0; double early = 0.0; double late = 0.0; double width = 0.0; Debug.WriteLine(String.Format("bucket starts @ {0}, ends @ {1}", bucket.From.TimeOfDay, bucket.To.TimeOfDay)); if ((initValue.StatusCode.AggregateBits & AggregateBits.Raw) == 0) { if (state.RawValueIsGood(initValue)) numGood += 1; else numBad += 1; } if ((finalValue.StatusCode.AggregateBits & AggregateBits.Raw) == 0) { if (state.RawValueIsGood(finalValue)) numGood += 1; else numBad += 1; } DataValue preceding = initValue; foreach (DataValue v in bucket.Values) { if (state.RawValueIsGood(v)) { numGood += 1; early = Convert.ToDouble(preceding.Value, CultureInfo.InvariantCulture); late = Convert.ToDouble(v.Value, CultureInfo.InvariantCulture); width = (v.SourceTimestamp - preceding.SourceTimestamp).TotalMilliseconds; total += SteppedVariable ? width * early : width * (late + early) / 2; preceding = v; } else { numBad += 1; } } early = Convert.ToDouble(preceding.Value, CultureInfo.InvariantCulture); late = Convert.ToDouble(finalValue.Value, CultureInfo.InvariantCulture); width = (finalValue.SourceTimestamp - preceding.SourceTimestamp).TotalMilliseconds; total += SteppedVariable ? width * early : width * (late + early) / 2; retval.Value = total; code = ComputeStatus(context, numGood, numBad, bucket).Code; } code.AggregateBits = AggregateBits.Calculated; if (StatusCode.IsNotBad(code) && bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { return(numBad + numGood == 0 ? StatusCodes.BadNoData : base.ComputeStatus(context, numGood, numBad, bucket)); }
public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { int numGood = 0; int numBad = 0; int nTransitions = 0; long stateCode = -1; IEnumerator <DataValue> enumerator = bucket.Values.GetEnumerator(); bool bucketValueNotEmpty = enumerator.MoveNext(); if (bucketValueNotEmpty && enumerator.Current != null) { if (bucket.EarlyBound != null) { if (enumerator.Current.SourceTimestamp == bucket.EarlyBound.Timestamp && bucket.EarlyBound.PriorPoint != null) { stateCode = Convert.ToInt32(Convert.ToBoolean(bucket.EarlyBound.PriorPoint.Value)); } else if (bucket.EarlyBound.Value != null) { stateCode = Convert.ToInt32(Convert.ToBoolean(bucket.EarlyBound.Value.Value)); } } } // viz. UA MultiStateNodeState & TwoStateNodeState, // assume DataValue.Value is either an EnumValueType or a bool if (bucketValueNotEmpty) { do { DataValue dv = enumerator.Current; if (state.RawValueIsGood(dv)) { EnumValueType ev = dv.Value as EnumValueType; if (ev == null) { bool b; if (bool.TryParse(dv.Value.ToString(), out b)) { if (stateCode < 0) { stateCode = b ? 1 : 0; } else if (b.CompareTo(Convert.ToBoolean(stateCode)) != 0) { nTransitions++; stateCode = b ? 1 : 0; } } else { continue; } } else { long s = ev.Value; if (stateCode < 0) { stateCode = s; } else if (!s.Equals(stateCode)) { nTransitions++; stateCode = s; } } numGood++; } else { numBad++; } } while (enumerator.MoveNext()); } StatusCode code = ComputeStatus(context, numGood, numBad, bucket).Code; DataValue retval = new DataValue { SourceTimestamp = bucket.From, Value = nTransitions }; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) { code.AggregateBits |= AggregateBits.Partial; } retval.StatusCode = code; return(retval); }
/// <summary> /// Computes the aggregate value for the time slice. /// </summary> public abstract DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state);
/// <summary> /// Calculates the value for the time slice. /// </summary> public override DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state) { DataValue retval = new DataValue { SourceTimestamp = bucket.From }; ; StatusCode code = StatusCodes.Good; DataValue previous = new DataValue { SourceTimestamp = bucket.From }; if (bucket.EarlyBound.Value != null) previous.StatusCode = (StatusCode)bucket.EarlyBound.Value.WrappedValue.Value; else previous.StatusCode = StatusCodes.Bad; if (!RightStatusCode(previous)) previous = null; double total = 0.0; foreach (DataValue v in bucket.Values) { if (previous != null) total += (v.SourceTimestamp - previous.SourceTimestamp).TotalMilliseconds; if (RightStatusCode(v)) previous = v; else previous = null; } if (previous != null) total += (bucket.To - previous.SourceTimestamp).TotalMilliseconds; retval.Value = total; code.AggregateBits = AggregateBits.Calculated; if (bucket.Incomplete) code.AggregateBits |= AggregateBits.Partial; retval.StatusCode = code; return retval; }
/// <summary> /// Calculates the status for the time slice. /// </summary> protected override StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { StatusCode code = (bucket.EarlyBound.Value == null && numGood + numBad == 0) ? // no inital bound, do not extrapolate StatusCodes.BadNoData : base.ComputeStatus(context, numGood, numBad, bucket); return code; }
/// <summary> /// Computes the status code for the processing interval using the percent good/bad information in the context. /// </summary> protected virtual StatusCode ComputeStatus(IAggregationContext context, int numGood, int numBad, TimeSlice bucket) { int total = numGood + numBad; if (total > 0) { double pbad = (numBad * 100) / total; if (pbad > context.PercentDataBad) return StatusCodes.Bad; double pgood = (numGood * 100) / total; if (pgood >= context.PercentDataGood) return StatusCodes.Good; return StatusCodes.Uncertain; } else { return StatusCodes.GoodNoData; } }