private AggregatedValue Calculate(AggregationKey key, List <double> valuesList, DateTime d) { try { if (key.Date > d) { foreach (var value in valuesList) { _bag.Add(new Tuple <AggregationKey, double>(key, value)); //_events.GetOrAdd(kvp.Key, new ConcurrentBag<double>()).Add(value); } return(null); } var av = new AggregatedValue(key); foreach (var aggregationOperation in _aggregationOperations) { try { av.AddResult(aggregationOperation.Do(valuesList)); } catch (InvalidOperationException) { } } //TODO dirty hack if ( _aggregationOperations.Any( op => op.GetType() == typeof(PercentileAggregationOperation) || op.GetType() == typeof(DistributionGroupAggregationOperation))) { av.AddRawValues(valuesList); } return(av); //_onAggregateCompleteAction(av); /*ThreadPool.QueueUserWorkItem(state => * { * Thread.Sleep(500); * int countAfter = kvp.Value.Count; * int i; * if (countBefore != countAfter) * i = 1; * }); */ } catch (Exception exception) { Console.WriteLine(exception); } return(null); }
public static IEnumerable <AggregatedValue> Compact(this IEnumerable <AggregatedValue> source) { Dictionary <AggregationKey, List <AggregatedValue> > dic = new Dictionary <AggregationKey, List <AggregatedValue> >(); foreach (var aggregatedValue in source) { var aggregationKey = new AggregationKey(aggregatedValue.Date, aggregatedValue.Props); if (!dic.ContainsKey(aggregationKey)) { dic[aggregationKey] = new List <AggregatedValue>(); } dic[aggregationKey].Add(aggregatedValue); } foreach (var kvp in dic) { AggregatedValue result = new AggregatedValue(kvp.Key); if (kvp.Value.Any(v => v.Sum.HasValue)) { result.AddResult(new AggregationOperationResult(AggregationType.Sum, kvp.Value.Where(v => v.Sum.HasValue).Sum(v => v.Sum.Value))); } if (kvp.Value.Any(v => v.Count.HasValue)) { result.AddResult(new AggregationOperationResult(AggregationType.Count, kvp.Value.Where(v => v.Count.HasValue).Sum(v => v.Count.Value))); } if (kvp.Value.Any(v => v.Min.HasValue)) { result.AddResult(new AggregationOperationResult(AggregationType.Min, kvp.Value.Where(v => v.Min.HasValue).Min(v => v.Min.Value))); } if (kvp.Value.Any(v => v.Max.HasValue)) { result.AddResult(new AggregationOperationResult(AggregationType.Max, kvp.Value.Where(v => v.Max.HasValue).Max(v => v.Max.Value))); } if (kvp.Value.Any(v => v.Avg.HasValue)) { result.AddResult(new AggregationOperationResult(AggregationType.Avg, kvp.Value.Where(v => v.Avg.HasValue).Average(v => v.Avg.Value))); } if (result.Count != 0 && (result.Max == 0.0)) { Console.WriteLine("!"); } yield return(result); } }
public void Push(LogEvent logEvent) { var props = new Dictionary <string, string>(); props["cCat"] = logEvent.Category; props["cName"] = logEvent.Counter; props["src"] = logEvent.Source; if (!String.IsNullOrEmpty(logEvent.Instance)) { props["instance"] = logEvent.Instance; } if (!String.IsNullOrEmpty(logEvent.ExtendedData)) { props["ext_data"] = logEvent.ExtendedData; } var aggregationKey = new AggregationKey(logEvent.DateTime.RoundTo(_aggregationPeriod), props); /*_events.AddOrUpdate(aggregationKey, * new ConcurrentBag<double>() {SlowPokeParse(logEvent)}, * (key, bag) => * { * bag.Add(SlowPokeParse(logEvent)); * return bag; * }); */ var value = Double.Parse(logEvent.Value); //_rwLock.EnterReadLock(); try { _bag.Add(new Tuple <AggregationKey, double>(aggregationKey, value)); //_events.GetOrAdd(aggregationKey, new ConcurrentBag<double>()).Add(value); } finally { // _rwLock.ExitReadLock(); } }
public AggregatedValue(AggregationKey aggregationKey) { Date = aggregationKey.Date; Props = aggregationKey.Props; }