public async Task <IEnumerable <ExpertStatsInTourReadDto> > Handle(GetExpertStats request,
                                                                           CancellationToken cancellationToken = default(CancellationToken))
        {
            var tournamentId = request.TournamentId;

            var tournament = await _context.Tournaments
                             .FetchWithToursAndMatchesAndPredictionsAndExperts(FetchMode.ForRead)
                             .WithIdAsync(tournamentId, cancellationToken);

            var tours = tournament.Tours.ToList();
            var expertStatsInTournament = new List <ExpertStatsInTourReadDto>();

            foreach (var tour in tours)
            {
                if (!tour.IsClosed)
                {
                    break;
                }

                var matches          = tour.Matches;
                var threePointSystem = new DefaultPredictionPointSystem();

                var predictionResultsByExpert = _predictionService.GroupPredictionsResultsByExpert(matches);
                var expertStats = _statService.DenormalizePredictionResultsToDto(predictionResultsByExpert, threePointSystem);
                expertStats = expertStats.OrderByDescending(es => es.Sum).ToList();

                var expertStatsInTour = new ExpertStatsInTourReadDto(tour.Number, expertStats);

                expertStatsInTournament.Add(expertStatsInTour);
            }

            return(expertStatsInTournament);
        }
        public async Task <IEnumerable <ExpertStatsReadDto> > Handle(GetExpertStats request,
                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            var tourId = request.TourId;
            var tour   = await _context
                         .Tours
                         .FetchWithBasePredictionsInfo(FetchMode.ForRead)
                         .WithIdAsync(tourId, cancellationToken);

            var matches          = tour.Matches;
            var threePointSystem = new DefaultPredictionPointSystem();

            var expertResults             = new ExpertsResultAccumulator(matches);
            var predictionResultsByExpert = expertResults.ExpertsTable;
            var expertStats = _statService.DenormalizePredictionResultsToDto(predictionResultsByExpert, threePointSystem);

            return(expertStats.OrderBy(s => s.Sum));
        }
        public async Task <IEnumerable <ExpertStatsReadDto> > Handle(GetExpertStatsByTourNumber request,
                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            var tourNumber   = request.TourNumber;
            var tournamentId = request.TournamentId;

            var tourId = await _context.GetTourId(tourNumber, tournamentId, cancellationToken);

            var tour = await _context
                       .Tours
                       .FetchWithBasePredictionsInfo(FetchMode.ForRead)
                       .WithIdAsync(tourId, cancellationToken);

            var matches          = tour.Matches;
            var threePointSystem = new DefaultPredictionPointSystem();

            var predictionResultsByExpert = _predictionService.GroupPredictionsResultsByExpert(matches);
            var expertStats = _statService.DenormalizePredictionResultsToDto(predictionResultsByExpert, threePointSystem);

            return(expertStats.OrderByDescending(s => s.Sum));
        }