public virtual IList<QualifiyingStatistic> GetTopQualifiersForCurrentSeason(PlaceMetric metric)
 {
     return new SeasonStatistician(_seasonRepository.GetCurrent()).GetTopQualifiers(metric);
 }
        public virtual IList<QualifiyingStatistic> GetTopQualifiers(PlaceMetric metric)
        {
            IList<QualifiyingStatistic> drivers = new List<QualifiyingStatistic>();

            foreach (var race in _season.Races)
            {
                var qualiResults = race.GetQualificationResults();
                var poleResult = qualiResults.FirstOrDefault(x => x.Position == 1);

                foreach (var result in qualiResults)
                {
                    var driver = drivers.FirstOrDefault(x => x.Entrant.Driver.Id == result.Entrant.Driver.Id);
                    if (driver == null)
                    {
                        driver = new QualifiyingStatistic(result.Entrant);
                        drivers.Add(driver);
                    }
                    driver.RegisterResult(result.Position, result.LapTime, poleResult.LapTime);
                }
            }

            if (metric == PlaceMetric.Position)
                return drivers.OrderBy(x => x.AveragePosition).ToList();
            else
            {
                var sorted = drivers.OrderBy(x => x.AveragePercentBack).ToList();
                var fastest = sorted.Take(1).FirstOrDefault();
                if (fastest != null)
                {
                    foreach (var result in sorted.Skip(1))
                    {
                        result.SetAverageLapTime(fastest.AverageLapTime);
                    }
                }
                return sorted;
            }
        }
 public override IList<QualifiyingStatistic> GetTopQualifiersForCurrentSeason(PlaceMetric metric)
 {
     const string key = "TopSeasonQualifiers";
     return CacheHelper.Get<IList<QualifiyingStatistic>>(key, base.GetTopQualifiersForCurrentSeason(metric));
 }