/// <summary> /// 存入数值 /// </summary> /// <param name="key">聚合Key</param> /// <param name="value">数值</param> public void PutDouble(AggregateKey key, double value) { var threadId = Thread.CurrentThread.ManagedThreadId; Dictionary<AggregateKey, AggregateResult> localData = data.GetOrAdd(threadId, k => new Dictionary<AggregateKey, AggregateResult>()); AggregateResult result; if (localData.TryGetValue(key, out result)) { if (value > result.Max) result.Max = value; if (value < result.Min) result.Min = value; result.Sum += value; result.Count++; result.Avg = result.Sum / result.Count; } else { result = new AggregateResult(); result.Max = value; result.Min = value; result.Avg = value; result.Sum = value; result.Count = 1; localData.Add(key, result); } }
public void AggregateGroup_Test1() { DateTime dateTime = DateTime.Now; AggregateGroup group2 = new AggregateGroup("Histogramtest", AggregateType.Histogram, dateTime); System.Collections.Generic.Dictionary<string, string> tag = new System.Collections.Generic.Dictionary<string, string>(); AggregateKey key = new AggregateKey("", "count", tag, AggregateType.Histogram); group2.PutDouble(key, 2); Dictionary<AggregateKey, AggregateResult> result = group2.MergeResult(); Assert.AreEqual(result.Count, 1); Assert.AreEqual((int)result[key].Avg, 2); Assert.AreEqual((int)result[key].Count, 1); Assert.AreEqual((int)result[key].Max, 2); Assert.AreEqual((int)result[key].Min, 2); Assert.AreEqual((int)result[key].Sum, 2); Assert.AreEqual(group2.AggregateType, AggregateType.Histogram); Assert.AreEqual(group2.CycleTime, dateTime); Assert.AreEqual(group2.FullName, "Histogramtest"); result = group2.MergeResult(); }
/// <summary> /// 存入数值 /// </summary> /// <param name="key">聚合Key</param> /// <param name="value">数值</param> public void PutDouble(AggregateKey key, double value) { AggregateGroup group = data.GetOrAdd(key.FullName, k => new AggregateGroup(k, key.AggregateType, cycleTime)); group.PutDouble(key, value); }
/// <summary> /// 存入数值 /// </summary> /// <param name="key">聚合Key</param> /// <param name="value">数值</param> public static void PutDouble(AggregateKey key, double value) { if (key == null) throw new ArgumentNullException("key"); FlushBuffer(); buffer.PutDouble(key, value); }
public void AggregateBlock_Data_Test() { Thread.GetDomain().SetData(".appPath", AppDomain.CurrentDomain.BaseDirectory); Thread.GetDomain().SetData(".appVPath", "/"); Thread.GetDomain().SetData(".appDomain", "*"); AggregateBlock aggregateBlock = new AggregateBlock(DateTime.Now); System.Collections.Generic.Dictionary<string, string> tag = new System.Collections.Generic.Dictionary<string, string>(); tag.Add("url", "localhost"); AggregateKey key = new AggregateKey("", "count", tag, AggregateType.Count); aggregateBlock.PutDouble(key, 10.10); AggregateKey key1 = new AggregateKey("", "Histogram", tag, AggregateType.Histogram); aggregateBlock.PutDouble(key1, 10.10); Assert.AreEqual(aggregateBlock.Data.Count, 2); }
public void AggregateGroup_Test() { DateTime dateTime = DateTime.Now; AggregateGroup group1 = new AggregateGroup("Counttest", AggregateType.Count, dateTime); System.Collections.Generic.Dictionary<string, string> tag = new System.Collections.Generic.Dictionary<string, string>(); AggregateKey key = new AggregateKey("", "count", tag, AggregateType.Count); group1.PutDouble(key, 122); Dictionary<AggregateKey, AggregateResult> result = group1.MergeResult(); Assert.IsTrue(group1.HasMerged); Assert.AreEqual(result.Count, 1); Assert.AreEqual((int)result[key].Avg, 122); Assert.AreEqual((int)result[key].Count, 1); Assert.AreEqual((int)result[key].Max, 122); Assert.AreEqual((int)result[key].Min, 122); Assert.AreEqual((int)result[key].Sum, 122); }