private List <PhaseLeftTurnGapTracker> GetGapsFromControllerData(IEnumerable <Controller_Event_Log> greenList,
                                                                         List <Controller_Event_Log> redList, List <Controller_Event_Log> orderedDetectorCallList)
        {
            var phaseTrackerList = new List <PhaseLeftTurnGapTracker>();

            foreach (var green in greenList)
            {
                //Find the corresponding red
                var red = redList.Where(x => x.Timestamp > green.Timestamp).OrderBy(x => x.Timestamp).FirstOrDefault();
                if (red == null)
                {
                    continue;
                }

                double trendLineGapTimeCounter = 0;

                var phaseTracker = new PhaseLeftTurnGapTracker {
                    GreenTime = green.Timestamp
                };

                var gapsList = new List <Controller_Event_Log>();
                gapsList.Add(green);
                gapsList.AddRange(orderedDetectorCallList.Where(x =>
                                                                x.Timestamp > green.Timestamp && x.Timestamp < red.Timestamp));
                gapsList.Add(red);

                for (var i = 1; i < gapsList.Count; i++)
                {
                    var gap = gapsList[i].Timestamp.TimeOfDay.TotalSeconds -
                              gapsList[i - 1].Timestamp.TimeOfDay.TotalSeconds;

                    if (gap < 0)
                    {
                        continue;
                    }

                    AddGapToCounters(phaseTracker, gap);

                    if (gap >= _options.TrendLineGapThreshold)
                    {
                        trendLineGapTimeCounter += gap;
                    }
                }

                //Decimal rounding errors can cause the number to be > 100
                var percentTurnable =
                    Math.Min(trendLineGapTimeCounter / (red.Timestamp - green.Timestamp).TotalSeconds, 100);
                phaseTracker.PercentPhaseTurnable = percentTurnable;

                phaseTrackerList.Add(phaseTracker);
            }

            return(phaseTrackerList);
        }
 public void AddGapToCounters(PhaseLeftTurnGapTracker phaseTracker, double gap)
 {
     if (gap > _options.Gap1Min && gap <= _options.Gap1Max)
     {
         phaseTracker.ShortGapCounter++;
     }
     else if (gap > _options.Gap2Min && gap <= _options.Gap2Max)
     {
         phaseTracker.MediumGapCounter++;
     }
     else if (gap > _options.Gap3Min && gap <= _options.Gap3Max)
     {
         phaseTracker.LargeGapCounter++;
     }
     else if (gap > _options.Gap4Min)
     {
         phaseTracker.HugeGapCounter++;
     }
 }