예제 #1
0
        protected override void SetSpecificAggregateRepositoriesForTest()
        {
            var signals = Db.Signals;

            foreach (var signal in signals)
            {
                foreach (var approach in signal.Approaches)
                {
                    PopulateApproachData(approach);
                }
            }
            ApproachPcdAggregationRepositoryFactory.SetApplicationEventRepository(
                new InMemoryApproachPcdAggregationRepository(Db));
            ApproachEventCountAggregationRepositoryFactory.SetRepository(new InMemoryApproachEventCountAggregationRepository(Db));
        }
        protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options,
                                         bool getProtectedPhase,
                                         AggregatedDataType dataType)
        {
            var eventCountAggregationRepository =
                ApproachEventCountAggregationRepositoryFactory.Create();
            var eventCounts =
                eventCountAggregationRepository.GetPhaseEventCountAggregationByPhaseIdAndDateRange(
                    approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase);

            if (eventCounts != 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 (eventCounts.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                        {
                            var eventCountCount = 0;
                            switch (dataType.DataName)
                            {
                            case "EventCount":
                                eventCountCount =
                                    eventCounts.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.EventCount);
                                break;

                            default:

                                throw new Exception("Unknown Aggregate Data Type for Event Count");
                            }

                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = eventCountCount,
                                Average = eventCountCount
                            });
                        }
                        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();
            }
        }