Exemplo n.º 1
0
        public async Task <ActionResult <PaginatedCollection <RankingEntryLight> > > GetRankingAsync(
            [FromRoute] Game game,
            [FromRoute] DateTime?date,
            [FromQuery] int page,
            [FromQuery] int count,
            [FromQuery] bool full,
            [FromQuery] long?simulatedPlayerId)
        {
            var request = new RankingRequest
            {
                Game        = game,
                FullDetails = full
            };

            var now = ServiceProviderAccessor.ClockProvider.Now;

            if (simulatedPlayerId.HasValue && date.HasValue)
            {
                request.PlayerVsLegacy = (simulatedPlayerId.Value, date.Value);
                request.RankingDate    = now;
            }
            else
            {
                request.RankingDate = date ?? now;
            }

            var rankingEntries = await _statisticsProvider
                                 .GetRankingEntriesAsync(request)
                                 .ConfigureAwait(false);

            return(Ok(PaginatedCollection <RankingEntryLight> .CreateInstance(rankingEntries, page, count)));
        }
        private async Task <List <RankingEntry> > GetRankingsWithParamsAsync(
            Game game,
            DateTime rankingDate,
            long?playerId,
            int?monthsPrior,
            Stage[] skipStages,
            bool?excludeWinners,
            int?engine)
        {
            var request = new RankingRequest
            {
                Game                 = game,
                FullDetails          = true,
                SkipStages           = skipStages,
                RankingDate          = rankingDate,
                Engine               = (Engine?)engine,
                IncludeUnknownEngine = true
            };

            if (playerId.HasValue)
            {
                request.PlayerVsLegacy = (playerId.Value, rankingDate);
                request.RankingDate    = DateTime.Now;
            }

            if (excludeWinners != false)
            {
                request.ExcludePlayer = excludeWinners.HasValue
                    ? RankingRequest.ExcludePlayerType.HasWorldRecord
                    : RankingRequest.ExcludePlayerType.HasUntied;
            }

            if (monthsPrior.HasValue)
            {
                request.RankingStartDate = rankingDate.AddMonths(-monthsPrior.Value);
            }

            var rankingEntriesBase = await _statisticsProvider
                                     .GetRankingEntriesAsync(request)
                                     .ConfigureAwait(false);

            return(rankingEntriesBase.Select(r => r as RankingEntry).ToList());
        }