public YellowRedActivationsAggregationByApproach(Approach approach, ApproachYellowRedActivationsAggregationOptions options,
                                                  DateTime startDate,
                                                  DateTime endDate,
                                                  bool getProtectedPhase, AggregatedDataType dataType) : base(approach, options, startDate, endDate,
                                                                                                              getProtectedPhase, dataType)
 {
 }
Example #2
0
 public AggregationByApproach(Approach approach, ApproachAggregationMetricOptions options, DateTime startDate,
                              DateTime endDate, bool getProtectedPhase, AggregatedDataType dataType)
 {
     BinsContainers = BinFactory.GetBins(options.TimeOptions);
     Approach       = approach;
     if (options.ShowEventCount)
     {
         ApproachEventCountAggregations = GetApproachEventCountAggregations(options, approach, true);
         if (approach.PermissivePhaseNumber != null)
         {
             ApproachEventCountAggregations.AddRange(GetApproachEventCountAggregations(options, approach, false));
         }
     }
     LoadBins(approach, options, getProtectedPhase, dataType);
 }
 protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options, bool getProtectedPhase,
                                  AggregatedDataType dataType)
 {
     for (var i = 0; i < BinsContainers.Count; i++)
     {
         for (var binIndex = 0; binIndex < BinsContainers[i].Bins.Count; binIndex++)
         {
             var bin = BinsContainers[i].Bins[binIndex];
             foreach (var detectorAggregationByDetector in detectorAggregationByDetectors)
             {
                 bin.Sum += detectorAggregationByDetector.BinsContainers[i].Bins[binIndex].Sum;
             }
             bin.Average = detectorAggregationByDetectors.Count > 0
                 ? bin.Sum / detectorAggregationByDetectors.Count
                 : 0;
         }
     }
 }
Example #4
0
        //protected List<ApproachEventCountAggregation> GetApproachEventCountAggregations(ApproachAggregationMetricOptions options, Approach approach, bool getProtectedPhase)
        //{
        //    var approachEventCountAggregationRepository =
        //        MOE.Common.Models.Repositories.ApproachEventCountAggregationRepositoryFactory.Create();
        //    return
        //        approachEventCountAggregationRepository.GetPhaseEventCountAggregationByPhaseIdAndDateRange(
        //            Approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase);
        //}


        protected abstract void LoadBins(Models.Signal signal, int phaseNumber, PhaseAggregationMetricOptions options, AggregatedDataType dataType);
Example #5
0
 public AggregationByPhase(Models.Signal signal, int phaseNumber, PhaseAggregationMetricOptions options, AggregatedDataType dataType)
 {
     BinsContainers = BinFactory.GetBins(options.TimeOptions);
     PhaseNumber    = phaseNumber;
     //if (options.ShowEventCount)
     //{
     //    ApproachEventCountAggregations = GetApproachEventCountAggregations(options, approach, true);
     //    if (approach.PermissivePhaseNumber != null)
     //    {
     //        ApproachEventCountAggregations.AddRange(GetApproachEventCountAggregations(options, approach, false));
     //    }
     //}
     LoadBins(signal, phaseNumber, options, dataType);
 }
Example #6
0
        protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options,
                                         bool getProtectedPhase,
                                         AggregatedDataType dataType)
        {
            var splitFailAggregationRepository =
                ApproachSplitFailAggregationRepositoryFactory.Create();
            var splitFails =
                splitFailAggregationRepository.GetApproachSplitFailsAggregationByApproachIdAndDateRange(
                    approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase);

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

                            default:

                                throw new Exception("Unknown Aggregate Data Type for Split Failure");
                            }

                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = splitFailCount,
                                Average = splitFailCount
                            });
                        }
                        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();
            }
        }
Example #7
0
 public SplitFailAggregationByApproach(Approach approach, ApproachSplitFailAggregationOptions options, DateTime startDate,
                                       DateTime endDate,
                                       bool getProtectedPhase, AggregatedDataType dataType) : base(approach, options, startDate, endDate,
                                                                                                   getProtectedPhase, dataType)
 {
 }
        protected override void LoadBins(Models.Signal signal, int phaseNumber, PhaseAggregationMetricOptions options,
                                         AggregatedDataType dataType)
        {
            var phaseTerminationAggregationRepository = PhaseTerminationAggregationRepositoryFactory.Create();
            var splitFails = phaseTerminationAggregationRepository.GetPhaseTerminationsAggregationBySignalIdPhaseNumberAndDateRange(
                signal.SignalID, phaseNumber, options.StartDate, options.EndDate);

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

                            case "ForceOffs":
                                terminationCount =
                                    splitFails.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.ForceOffs);
                                break;

                            case "MaxOuts":
                                terminationCount =
                                    splitFails.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.MaxOuts);
                                break;

                            case "Unknown":
                                terminationCount =
                                    splitFails.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.UnknownTerminationTypes);
                                break;

                            default:

                                throw new Exception("Unknown Aggregate Data Type for Split Failure");
                            }

                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = terminationCount,
                                Average = terminationCount
                            });
                        }
                        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();
            }
        }
 public PhaseTerminationAggregationByPhase(Models.Signal signal, int phaseNumber, PhaseTerminationAggregationOptions options, AggregatedDataType dataType)
     : base(signal, phaseNumber, options, dataType)
 {
 }
        protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options,
                                         bool getProtectedPhase,
                                         AggregatedDataType dataType)
        {
            var approachPcdAggregationRepository =
                ApproachPcdAggregationRepositoryFactory.Create();
            var pcdAggregations =
                approachPcdAggregationRepository.GetApproachPcdsAggregationByApproachIdAndDateRange(
                    approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase);

            if (pcdAggregations != 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>();
                    var cycleAggregationRepository = Models.Repositories.ApproachCycleAggregationRepositoryFactory.Create();
                    var cycleAggregtaions          =
                        cycleAggregationRepository.GetApproachCyclesAggregationByApproachIdAndDateRange(
                            approach.ApproachID, options.StartDate, options.EndDate, getProtectedPhase);
                    //foreach (var bin in binsContainer.Bins)
                    Parallel.ForEach(binsContainer.Bins, bin =>
                    {
                        if (pcdAggregations.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                        {
                            double pcdCount = 0;
                            switch (dataType.DataName)
                            {
                            case "ArrivalsOnGreen":
                                pcdCount =
                                    pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.ArrivalsOnGreen);
                                break;

                            case "ArrivalsOnRed":
                                pcdCount =
                                    pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.ArrivalsOnRed);
                                break;

                            case "ArrivalsOnYellow":
                                pcdCount =
                                    pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.ArrivalsOnYellow);
                                break;

                            case "PercentArrivalsOnGreen":
                                pcdCount = Convert.ToInt32(Math.Round(GetPercentArrivalOnGreen(bin, pcdAggregations) * 100));
                                break;

                            case "PlatoonRatio":
                                double percentArrivalOnGreen = GetPercentArrivalOnGreen(bin, pcdAggregations);
                                var aggregations             = cycleAggregtaions.Where(s =>
                                                                                       s.BinStartTime >= bin.Start && s.BinStartTime < bin.End).ToList();

                                double greenTime = aggregations.Sum(s => s.GreenTime);
                                double totalTime = greenTime + aggregations.Sum(s => s.YellowTime) + aggregations.Sum(s => s.RedTime);
                                if (greenTime > 0)
                                {
                                    pcdCount = percentArrivalOnGreen / (greenTime / totalTime);
                                }
                                break;

                            case "ApproachVolume":
                                pcdCount = pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End).Sum(s => s.ArrivalsOnYellow)
                                           + pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End).Sum(s => s.ArrivalsOnGreen)
                                           + pcdAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End).Sum(s => s.ArrivalsOnRed);
                                break;

                            default:
                                throw new Exception("Unknown Aggregate Data Type for Split Failure");
                            }

                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = pcdCount,
                                Average = pcdCount
                            });
                        }
                        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();
            }
        }
Example #11
0
 protected abstract void LoadBins(Approach approach, ApproachAggregationMetricOptions options,
                                  bool getProtectedPhase, AggregatedDataType dataType);
Example #12
0
        protected override void LoadBins(Approach approach, ApproachAggregationMetricOptions options,
                                         bool getProtectedPhase,
                                         AggregatedDataType dataType)
        {
            var approachSpeedAggregationRepository =
                ApproachSpeedAggregationRepositoryFactory.Create();
            var speedAggregations =
                approachSpeedAggregationRepository.GetSpeedsByApproachIDandDateRange(approach.ApproachID, options.StartDate, options.EndDate);

            if (speedAggregations != 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 (speedAggregations.Any(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                        {
                            double speedAggregationCount = 0;
                            switch (dataType.DataName)
                            {
                            case "AverageSpeed":
                                if (speedAggregations.Any(s =>
                                                          s.BinStartTime >= bin.Start && s.BinStartTime < bin.End))
                                {
                                    double summedSpeed = speedAggregations.Where(s =>
                                                                                 s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                         .Sum(s => s.SummedSpeed);
                                    double summedVolume = speedAggregations.Where(s =>
                                                                                  s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                                          .Sum(s => s.SpeedVolume);
                                    if (summedVolume > 0)
                                    {
                                        speedAggregationCount = summedSpeed / summedVolume;
                                    }
                                }
                                break;

                            case "SpeedVolume":
                                speedAggregationCount =
                                    speedAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.SpeedVolume);
                                break;

                            case "Speed85Th":
                                speedAggregationCount =
                                    speedAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.Speed85Th);
                                break;

                            case "Speed15Th":
                                speedAggregationCount =
                                    speedAggregations.Where(s => s.BinStartTime >= bin.Start && s.BinStartTime < bin.End)
                                    .Sum(s => s.Speed15Th);
                                break;

                            default:

                                throw new Exception("Unknown Aggregate Data Type for Split Failure");
                            }

                            concurrentBins.Add(new Bin
                            {
                                Start   = bin.Start,
                                End     = bin.End,
                                Sum     = Convert.ToInt32(Math.Round(speedAggregationCount)),
                                Average = speedAggregationCount
                            });
                        }
                        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();
            }
        }
Example #13
0
        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();
            }
        }
Example #14
0
 public CycleAggregationByApproach(Approach approach, ApproachAggregationMetricOptions options, DateTime startDate,
                                   DateTime endDate,
                                   bool getProtectedPhase, AggregatedDataType dataType) : base(approach, options, startDate, endDate,
                                                                                               getProtectedPhase, dataType)
 {
 }