예제 #1
0
        public virtual Statistics GetTeamStatistics(Team team)
        {
            var stats = new Statistics();

                var seasons = _seasonRepository.GetAll();
                foreach (var season in seasons)
                {
                    var hasCountedSeason = false;
                    var average = stats.NewSeasonAverageStatistic(season.Name);
                    foreach (var race in season.Races)
                    {
                        var entries = race.Entries.Where(re => re.Entrant.Team.Id == team.Id);
                        foreach (var entry in entries)
                            if (entry != null)
                            {
                                stats.Entered += 1;
                                stats.Poles += entry.QualifyingPosition == 1 ? 1 : 0;
                                stats.Wins += entry.RacePlace == 1 ? 1 : 0;
                                stats.Podiums += entry.RacePlace <= 3 ? 1 : 0;
                                stats.Finished += entry.DidNotFinish ? 0 : 1;
                                stats.Points += (int) entry.Points;

                                if (!entry.DidNotQualify)
                                    average.AddQualifyingResult(entry.QualifyingPosition);

                                if (entry.HasFinished)
                                    average.AddRaceResult(entry.RacePlace);

                                if (!hasCountedSeason)
                                {
                                    stats.Seasons += 1;
                                    hasCountedSeason = true;
                                }
                            }

                        var seasonResult = season.GetTeamStandings().SingleOrDefault(e => e.Entrant.Team.Id == team.Id);

                        if (seasonResult != null)
                        {
                            if (seasonResult.Position < stats.BestChampionshipResult)
                                stats.BestChampionshipResult = seasonResult.Position;
                        }
                    }
                }

            return stats;
        }
예제 #2
0
        public virtual Statistics GetDriverStatistics(Driver driver)
        {
            var stats = new Statistics();
            var racerRatio = 0.0;

            foreach (var season in driver.Contracts.Select(c => c.Season))
            {
                if (!season.Entrants.Any(x => x.Driver.Id == driver.Id))
                    continue;

                bool hasCountedSeason = false;
                var average = stats.NewSeasonAverageStatistic(season.Name);
                foreach (var race in season.Races)
                {
                    var entry = race.Entries.FirstOrDefault(re => re.Entrant.Driver.Id == driver.Id);
                    if (entry != null)
                    {
                        if (entry.RacerRatio != null)
                            racerRatio += entry.RacerRatio.Value;

                        stats.Entered += 1;
                        if (season.Year >= 4) stats.FastestLapsEntered += 1;
                        stats.Poles += entry.QualifyingPosition == 1 ? 1 : 0;
                        stats.Wins += entry.RacePlace == 1 ? 1 : 0;
                        stats.Podiums += entry.RacePlace <= 3 ? 1 : 0;
                        stats.Finished += entry.DidNotFinish ? 0 : 1;
                        stats.Points += (int) entry.Points;
                        stats.FastestLaps += race.GotFastestLap(driver) ? 1 : 0;

                        if (!entry.DidNotQualify)
                            average.AddQualifyingResult(entry.QualifyingPosition);

                        if (entry.HasFinished)
                            average.AddRaceResult(entry.RacePlace);

                        if (!hasCountedSeason)
                        {
                            stats.Seasons += 1;
                            hasCountedSeason = true;
                        }
                    }

                    var seasonResult =
                        season.GetDriverStandings().FirstOrDefault(e => e.Entrant.Driver.Id == driver.Id);

                    if (seasonResult != null)
                    {
                        if (seasonResult.Position < stats.BestChampionshipResult)
                            stats.BestChampionshipResult = seasonResult.Position;
                    }
                }
            }

            stats.RacerRatio = racerRatio / stats.Entered;

            return stats;
        }