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) { 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; }
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) { 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; }
protected void UpdatePriorPoint(BoundingValue bound, AggregateState state) { if (state.HasTerminated && (state.LatePoint == null) && bound.PriorPoint == null) { bound.PriorPoint = state.PriorPoint; bound.PriorBadPoints = state.PriorBadPoints; bound.DerivationType = UseSlopedExtrapolation ? BoundingValueType.SlopedExtrapolation : BoundingValueType.SteppedExtrapolation; } }
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 bool WaitForMoreData(TimeSlice bucket, AggregateState state) { bool wait = false; if (!state.HasTerminated) { if (bucket.ContainsTime(state.LatestTimestamp)) { wait = true; } } return(wait); }
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; 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; }
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 abstract DataValue Compute(IAggregationContext context, TimeSlice bucket, AggregateState state);
public abstract bool WaitForMoreData(TimeSlice bucket, AggregateState state);
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) { 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); }
public override void UpdateBoundingValues(TimeSlice bucket, AggregateState state) { BoundingValue EarlyBound = bucket.EarlyBound; BoundingValue LateBound = bucket.LateBound; if (bucket.ExactMatch(state.LatestTimestamp)) { EarlyBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; EarlyBound.DerivationType = BoundingValueType.QualityRaw; } else { if (EarlyBound.DerivationType != BoundingValueType.QualityRaw) { if (EarlyBound.EarlyPoint == null) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.From)) { EarlyBound.EarlyPoint = state.EarlyPoint; } } if (EarlyBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.From)) { EarlyBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < EarlyBound.Timestamp) EarlyBound.CurrentBadPoints.Add(dv); EarlyBound.DerivationType = BoundingValueType.QualityInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { EarlyBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < EarlyBound.Timestamp) EarlyBound.CurrentBadPoints.Add(dv); EarlyBound.DerivationType = BoundingValueType.QualityExtrapolation; } } if (bucket.EndMatch(state.LatestTimestamp)) { LateBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; LateBound.DerivationType = BoundingValueType.QualityRaw; } else { if (LateBound.DerivationType != BoundingValueType.QualityRaw) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.To)) LateBound.EarlyPoint = state.EarlyPoint; if (LateBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.To)) { LateBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < LateBound.Timestamp) LateBound.CurrentBadPoints.Add(dv); LateBound.DerivationType = BoundingValueType.QualityInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { LateBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < LateBound.Timestamp) LateBound.CurrentBadPoints.Add(dv); LateBound.DerivationType = BoundingValueType.QualityExtrapolation; } } }
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 void UpdateBoundingValues(TimeSlice bucket, AggregateState state) { BoundingValue EarlyBound = bucket.EarlyBound; BoundingValue LateBound = bucket.LateBound; if (bucket.ExactMatch(state.LatestTimestamp) && StatusCode.IsGood(state.LatestStatus)) { EarlyBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; EarlyBound.DerivationType = BoundingValueType.Raw; } else { if (EarlyBound.DerivationType != BoundingValueType.Raw) { if (EarlyBound.EarlyPoint == null) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.From)) { EarlyBound.EarlyPoint = state.EarlyPoint; } } if (EarlyBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.From)) { EarlyBound.LatePoint = state.LatePoint; if (SteppedVariable) { EarlyBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < EarlyBound.Timestamp) EarlyBound.CurrentBadPoints.Add(dv); } else { EarlyBound.CurrentBadPoints = state.CurrentBadPoints; } EarlyBound.DerivationType = SteppedVariable ? BoundingValueType.SteppedInterpolation : BoundingValueType.SlopedInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { if (SteppedVariable) { EarlyBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < EarlyBound.Timestamp) EarlyBound.CurrentBadPoints.Add(dv); } else { EarlyBound.CurrentBadPoints = state.CurrentBadPoints; } } } if (bucket.EndMatch(state.LatestTimestamp) && StatusCode.IsGood(state.LatestStatus)) { LateBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; LateBound.DerivationType = BoundingValueType.Raw; } else { if (LateBound.DerivationType != BoundingValueType.Raw) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.To)) LateBound.EarlyPoint = state.EarlyPoint; if (LateBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.To)) { LateBound.LatePoint = state.LatePoint; if (SteppedVariable) { LateBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < LateBound.Timestamp) LateBound.CurrentBadPoints.Add(dv); } else { LateBound.CurrentBadPoints = state.CurrentBadPoints; } LateBound.DerivationType = SteppedVariable ? BoundingValueType.SteppedInterpolation : BoundingValueType.SlopedInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { if (SteppedVariable) { LateBound.CurrentBadPoints = new List<DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) if (dv.SourceTimestamp < LateBound.Timestamp) LateBound.CurrentBadPoints.Add(dv); } else { LateBound.CurrentBadPoints = state.CurrentBadPoints; } } UpdatePriorPoint(LateBound, state); } }
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; }
public override bool WaitForMoreData(TimeSlice bucket, AggregateState state) { bool wait = false; if (!state.HasTerminated) { if (bucket.ContainsTime(state.LatestTimestamp)) { wait = true; } if ((bucket.EarlyBound.Value == null) || (bucket.LateBound.Value == null)) { wait = true; } } return wait; }
public override void UpdateBoundingValues(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) { 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) { 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 void UpdateBoundingValues(TimeSlice bucket, AggregateState state) { base.UpdateBoundingValues(bucket, state); UpdatePriorPoint(bucket.EarlyBound, state); }
public abstract void UpdateBoundingValues(TimeSlice bucket, AggregateState state);
public override void UpdateBoundingValues(TimeSlice bucket, AggregateState state) { BoundingValue EarlyBound = bucket.EarlyBound; BoundingValue LateBound = bucket.LateBound; if (bucket.ExactMatch(state.LatestTimestamp)) { EarlyBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; EarlyBound.DerivationType = BoundingValueType.QualityRaw; } else { if (EarlyBound.DerivationType != BoundingValueType.QualityRaw) { if (EarlyBound.EarlyPoint == null) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.From)) { EarlyBound.EarlyPoint = state.EarlyPoint; } } if (EarlyBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.From)) { EarlyBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < EarlyBound.Timestamp) { EarlyBound.CurrentBadPoints.Add(dv); } } EarlyBound.DerivationType = BoundingValueType.QualityInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { EarlyBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < EarlyBound.Timestamp) { EarlyBound.CurrentBadPoints.Add(dv); } } EarlyBound.DerivationType = BoundingValueType.QualityExtrapolation; } } if (bucket.EndMatch(state.LatestTimestamp)) { LateBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; LateBound.DerivationType = BoundingValueType.QualityRaw; } else { if (LateBound.DerivationType != BoundingValueType.QualityRaw) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.To)) { LateBound.EarlyPoint = state.EarlyPoint; } if (LateBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.To)) { LateBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < LateBound.Timestamp) { LateBound.CurrentBadPoints.Add(dv); } } LateBound.DerivationType = BoundingValueType.QualityInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { LateBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < LateBound.Timestamp) { LateBound.CurrentBadPoints.Add(dv); } } LateBound.DerivationType = BoundingValueType.QualityExtrapolation; } } }
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) { 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); }
private void InitializeAggregation() { m_state = new AggregateState(this, this); }
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 void UpdateBoundingValues(TimeSlice bucket, AggregateState state) { BoundingValue EarlyBound = bucket.EarlyBound; BoundingValue LateBound = bucket.LateBound; if (bucket.ExactMatch(state.LatestTimestamp) && StatusCode.IsGood(state.LatestStatus)) { EarlyBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; EarlyBound.DerivationType = BoundingValueType.Raw; } else { if (EarlyBound.DerivationType != BoundingValueType.Raw) { if (EarlyBound.EarlyPoint == null) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.From)) { EarlyBound.EarlyPoint = state.EarlyPoint; } } if (EarlyBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.From)) { EarlyBound.LatePoint = state.LatePoint; if (SteppedVariable) { EarlyBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < EarlyBound.Timestamp) { EarlyBound.CurrentBadPoints.Add(dv); } } } else { EarlyBound.CurrentBadPoints = state.CurrentBadPoints; } EarlyBound.DerivationType = SteppedVariable ? BoundingValueType.SteppedInterpolation : BoundingValueType.SlopedInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { if (SteppedVariable) { EarlyBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < EarlyBound.Timestamp) { EarlyBound.CurrentBadPoints.Add(dv); } } } else { EarlyBound.CurrentBadPoints = state.CurrentBadPoints; } } } if (bucket.EndMatch(state.LatestTimestamp) && StatusCode.IsGood(state.LatestStatus)) { LateBound.RawPoint = state.LatePoint == null ? state.EarlyPoint : state.LatePoint; LateBound.DerivationType = BoundingValueType.Raw; } else { if (LateBound.DerivationType != BoundingValueType.Raw) { if ((state.EarlyPoint != null) && (state.EarlyPoint.SourceTimestamp < bucket.To)) { LateBound.EarlyPoint = state.EarlyPoint; } if (LateBound.LatePoint == null) { if ((state.LatePoint != null) && (state.LatePoint.SourceTimestamp >= bucket.To)) { LateBound.LatePoint = state.LatePoint; if (SteppedVariable) { LateBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < LateBound.Timestamp) { LateBound.CurrentBadPoints.Add(dv); } } } else { LateBound.CurrentBadPoints = state.CurrentBadPoints; } LateBound.DerivationType = SteppedVariable ? BoundingValueType.SteppedInterpolation : BoundingValueType.SlopedInterpolation; } } } if (state.HasTerminated && (state.LatePoint == null)) { if (SteppedVariable) { LateBound.CurrentBadPoints = new List <DataValue>(); foreach (DataValue dv in state.CurrentBadPoints) { if (dv.SourceTimestamp < LateBound.Timestamp) { LateBound.CurrentBadPoints.Add(dv); } } } else { LateBound.CurrentBadPoints = state.CurrentBadPoints; } } UpdatePriorPoint(LateBound, state); } }
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; 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); }
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 void UpdateProcessedData(DataValue rawValue, AggregateState state) { // step 1: compute new TimeSlice instances to enqueue, until we reach the one the // rawValue belongs in or we've reached the one that goes to the EndTime. Ensure // that the raw value is added to the last one created. TimeSlice tmpTS = null; if (m_pending == null) { m_pending = new Queue <TimeSlice>(); } if (m_latest == null) { tmpTS = TimeSlice.CreateInitial(StartTime, EndTime, ProcessingInterval); if (tmpTS != null) { m_pending.Enqueue(tmpTS); m_latest = tmpTS; } } else { tmpTS = m_latest; } DateTime latestTime = (StartTime > EndTime) ? StartTime : EndTime; while ((tmpTS != null) && (state.HasTerminated || !tmpTS.AcceptValue(rawValue))) { tmpTS = TimeSlice.CreateNext(latestTime, ProcessingInterval, tmpTS); if (tmpTS != null) { m_pending.Enqueue(tmpTS); m_latest = tmpTS; } } // step 2: apply the aggregator to the head of the queue to see if we can convert // it into a processed point. If so, dequeue it and add the processed value to the // m_released list. Keep doing it until one of the TimeSlices returns null or we // run out of enqueued TimeSlices (should only happen on termination). if (m_released == null) { m_released = new List <DataValue>(); } foreach (TimeSlice b in m_pending) { UpdateBoundingValues(b, state); } bool active = true; while ((m_pending.Count > 0) && active) { TimeSlice top = m_pending.Peek(); DataValue computed = null; if (!WaitForMoreData(top, state)) { computed = Compute(this, top, state); } if (computed != null) { m_released.Add(computed); m_pending.Dequeue(); } else { active = false; } } }
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) { 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 void UpdateProcessedData(DataValue rawValue, AggregateState state) { // step 1: compute new TimeSlice instances to enqueue, until we reach the one the // rawValue belongs in or we've reached the one that goes to the EndTime. Ensure // that the raw value is added to the last one created. TimeSlice tmpTS = null; if (m_pending == null) m_pending = new Queue<TimeSlice>(); if (m_latest == null) { tmpTS = TimeSlice.CreateInitial(StartTime, EndTime, ProcessingInterval); if (tmpTS != null) { m_pending.Enqueue(tmpTS); m_latest = tmpTS; } } else { tmpTS = m_latest; } DateTime latestTime = (StartTime > EndTime) ? StartTime : EndTime; while ((tmpTS != null) && (state.HasTerminated || !tmpTS.AcceptValue(rawValue))) { tmpTS = TimeSlice.CreateNext(latestTime, ProcessingInterval, tmpTS); if (tmpTS != null) { m_pending.Enqueue(tmpTS); m_latest = tmpTS; } } // step 2: apply the aggregator to the head of the queue to see if we can convert // it into a processed point. If so, dequeue it and add the processed value to the // m_released list. Keep doing it until one of the TimeSlices returns null or we // run out of enqueued TimeSlices (should only happen on termination). if (m_released == null) m_released = new List<DataValue>(); foreach (TimeSlice b in m_pending) UpdateBoundingValues(b, state); bool active = true; while ((m_pending.Count > 0) && active) { TimeSlice top = m_pending.Peek(); DataValue computed = null; if (!WaitForMoreData(top, state)) computed = Compute(this, top, state); if (computed != null) { m_released.Add(computed); m_pending.Dequeue(); } else { active = false; } } }
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 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); }