protected AggregationByDetector(Models.Detector detector, DetectorAggregationMetricOptions options) { Detector = detector; BinsContainers = BinFactory.GetBins(options.TimeOptions); if (options.ShowEventCount) { DetectorEventCountAggregations = GetdetectorEventCountAggregations(options, detector); } LoadBins(detector, options); }
protected override void LoadBins(Models.Detector detector, DetectorAggregationMetricOptions options) { var detectorAggregationRepository = DetectorAggregationsRepositoryFactory.Create(); var detectorAggregations = detectorAggregationRepository.GetDetectorAggregationByApproachIdAndDateRange( detector.ID, options.StartDate, options.EndDate); if (detectorAggregations != 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 (detectorAggregations.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)) { var volume = 0; switch (options.SelectedAggregatedDataType.DataName) { case "DetectorActivationCount": volume = detectorAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.Volume); break; default: throw new Exception("Unknown Aggregate Data Type for Split Failure"); } concurrentBins.Add(new Bin { Start = bin.Start, End = bin.End, Sum = volume, Average = volume }); } 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 abstract void LoadBins(Models.Detector detector, DetectorAggregationMetricOptions options);
protected List <DetectorEventCountAggregation> GetdetectorEventCountAggregations(DetectorAggregationMetricOptions options, Models.Detector detector) { var detectorEventCountAggregationRepository = MOE.Common.Models.Repositories.DetectorEventCountAggregationRepositoryFactory.Create(); return (detectorEventCountAggregationRepository.GetDetectorEventCountAggregationByDetectorIdAndDateRange( Detector.ID, options.StartDate, options.EndDate)); }