public void Initialize() { Db.ClearTables(); Db.PopulateSignal(); Db.PopulateSignalsWithApproaches(); Db.PopulateApproachesWithDetectors(); var signals = Db.Signals; foreach (var signal in signals) { foreach (var approach in signal.Approaches) { Db.PopulateApproachCycleAggregationsWithRandomRecords(Convert.ToDateTime("1/1/2016"), Convert.ToDateTime("1/1/2018"), approach); } } ApproachCycleAggregationRepositoryFactory.SetApplicationEventRepository( new InMemoryApproachCycleAggregationRepository(Db)); MOE.Common.Models.Repositories.SignalsRepositoryFactory.SetSignalsRepository( new InMemorySignalsRepository(Db)); MetricTypeRepositoryFactory.SetMetricsRepository(new InMemoryMetricTypeRepository(Db)); ApplicationEventRepositoryFactory.SetApplicationEventRepository(new InMemoryApplicationEventRepository(Db)); Models.Repositories.DirectionTypeRepositoryFactory.SetDirectionsRepository( new InMemoryDirectionTypeRepository()); SignalsRepository = SignalsRepositoryFactory.Create(); }
protected override void SetSpecificAggregateRepositoriesForTest() { var signals = Db.Signals; foreach (var signal in signals) { foreach (var approach in signal.Approaches) { PopulateApproachData(approach); } } ApproachCycleAggregationRepositoryFactory.SetApplicationEventRepository( new InMemoryApproachCycleAggregationRepository(Db)); }
protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options, bool getProtectedPhase, AggregatedDataType dataType) { var approachCycleAggregationRepository = ApproachCycleAggregationRepositoryFactory.Create(); var approachCycles = approachCycleAggregationRepository.GetApproachCyclesAggregationByApproachIdAndDateRange( approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase); if (approachCycles != 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 (approachCycles.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)) { var approachCycleCount = 0; switch (dataType.DataName) { case "TotalCycles": approachCycleCount = approachCycles.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.TotalCycles); break; case "RedTime": approachCycleCount = (int)approachCycles.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.RedTime); break; case "YellowTime": approachCycleCount = (int)approachCycles.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.YellowTime); break; case "GreenTime": approachCycleCount = (int)approachCycles.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.GreenTime); break; case "PedActuations": approachCycleCount = approachCycles.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End) .Sum(s => s.PedActuations); break; default: throw new Exception("Unknown Aggregate Data Type for Approach Cycle"); } Bin newBin = new Bin { Start = bin.Start, End = bin.End, Sum = approachCycleCount, Average = approachCycleCount }; 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(); } }