public StatisticsChange MergeWith(StatisticsChange other) { return(new StatisticsChange(Math.Max(Time, other.Time), Change + other.Change, other.Time > Time ? other.After : After, Reason)); }
public void AddValue(double time, float value, TransactionReasons reason) { var newChange = new StatisticsChange(time, value - previousValue, value, reason); previousValue = CurrentValue(); if (changes.Count > 0 && changes[changes.Count - 1].CanMerge(newChange)) { changes[changes.Count - 1] = changes[changes.Count - 1].MergeWith(newChange); } else { changes.Add(newChange); } SumCutoffIndex = SumCutoffIndex; }
public bool CanMerge(StatisticsChange other) { return(Math.Abs(other.Time - Time) < threshold && other.Reason == Reason && Mathf.Sign(Change) == Mathf.Sign(other.Change)); }