protected override void LoadBins(SignalAggregationMetricOptions options, Models.Signal signal) { var signalEventCountAggregationRepository = SignalEventCountAggregationRepositoryFactory .Create(); var signalEventCounts = signalEventCountAggregationRepository.GetSignalEventCountAggregationBySignalIdAndDateRange( signal.SignalID, BinsContainers.Min(b => b.Start), BinsContainers.Max(b => b.End)); if (signalEventCounts != null) { var concurrentBinContainers = new ConcurrentBag <BinsContainer>(); //foreach (var binsContainer in binsContainers) Parallel.ForEach(BinsContainers, binsContainer => { var tempBinsContainer = new BinsContainer(binsContainer.Start, binsContainer.End); var concurrentBins = new ConcurrentBag <Bin>(); //foreach (var bin in binsContainer.Bins) Parallel.ForEach(binsContainer.Bins, bin => { if (signalEventCounts.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)) { var signalEventCountSum = 0; switch (options.SelectedAggregatedDataType.DataName) { case "EventCount": signalEventCountSum = signalEventCounts.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.EventCount); break; } Bin newBin = new Bin { Start = bin.Start, End = bin.End, Sum = signalEventCountSum, Average = signalEventCountSum }; concurrentBins.Add(newBin); } else { concurrentBins.Add(new Bin { Start = bin.Start, End = bin.End, Sum = 0, Average = 0 }); } }); tempBinsContainer.Bins = concurrentBins.OrderBy(c => c.Start).ToList(); concurrentBinContainers.Add(tempBinsContainer); }); BinsContainers = concurrentBinContainers.OrderBy(b => b.Start).ToList(); } }
protected override void SetSpecificAggregateRepositoriesForTest() { SignalEventCountAggregationRepositoryFactory.SetRepository(new InMemorySignalEventCountAggregationRepository(Db)); PreemptAggregationDatasRepositoryFactory.SetArchivedMetricsRepository(new InMemoryPreemptAggregationDatasRepository(Db)); foreach (var signal in Db.Signals) { PopulateSignalData(signal); } }
protected override void SetSpecificAggregateRepositoriesForTest() { var signals = Db.Signals; SignalEventCountAggregationRepositoryFactory.SetRepository(new InMemorySignalEventCountAggregationRepository(Db)); PriorityAggregationDatasRepositoryFactory.SetRepository(new InMemoryPriorityAggregationDatasRepository(Db)); foreach (var signal in signals) { PopulateSignalData(signal); } }