예제 #1
0
        public async Task <ActionResult <IReadOnlyCollection <Standing> > > GetLongestStandingsAsync(
            [FromRoute] Game game,
            [FromQuery][Required] StandingType standingType,
            [FromQuery] bool?stillOngoing,
            [FromQuery] DateTime?endDate,
            [FromQuery] int?count)
        {
            var standings = await _statisticsProvider
                            .GetLongestStandingsAsync(game, endDate, standingType, stillOngoing)
                            .ConfigureAwait(false);

            return(Ok(standings.Take(count ?? 100).ToList()));
        }
        public async Task <IActionResult> GetLongestStandingAsync(
            [FromRoute] Game game,
            [FromQuery] StandingType standingType,
            [FromQuery] bool?stillOngoing)
        {
            return(await DoAndCatchAsync(
                       LastStandingViewName,
                       standingType.AsPageTitle(stillOngoing == true),
                       async() =>
            {
                var standings = await _statisticsProvider
                                .GetLongestStandingsAsync(game, null, standingType, stillOngoing)
                                .ConfigureAwait(false);

                return new StandingWrViewData
                {
                    TopDetails = standings
                                 .Take(25)
                                 .Select(x => x.ToStandingWrLevelItemData())
                                 .ToList()
                };
            }).ConfigureAwait(false));
        }
예제 #3
0
        internal static string AsPageTitle(this StandingType standingType, bool stillOngoing)
        {
            var onGoing = stillOngoing ? "; ongoing" : string.Empty;

            switch (standingType)
            {
            case StandingType.BetweenTwoTimes:
                return($"Longest run between 2 WRs{onGoing}");

            case StandingType.Unslayed:
                return($"Longest run before a WR slay{onGoing}");

            case StandingType.UnslayedExceptSelf:
                return($"Longest run before a WR slay; self-slay excluded{onGoing}");

            case StandingType.Untied:
                return($"Longest run before a WR untied{onGoing}");

            case StandingType.UntiedExceptSelf:
                return($"Longest run before a WR untied; self-untied excluded{onGoing}");
            }

            throw new NotImplementedException();
        }
예제 #4
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <Standing> > GetLongestStandingsAsync(
            Game game,
            DateTime?endDate,
            StandingType standingType,
            bool?stillOngoing)
        {
            var standings = new List <Standing>();

            var wrs = await GetWorldRecordsAsync(game, endDate).ConfigureAwait(false);

            foreach (var stage in game.GetStages())
            {
                foreach (var level in SystemExtensions.Enumerate <Level>())
                {
                    var locWrs = wrs
                                 .Where(wr => wr.Stage == stage && wr.Level == level)
                                 .OrderBy(wr => wr.Date)
                                 .ThenByDescending(wr => wr.Time);

                    Standing currentStanding = null;
                    foreach (var locWr in locWrs)
                    {
                        switch (standingType)
                        {
                        case StandingType.Unslayed:
                            standings.AddRange(locWr.Holders.Select(_ => new Standing(locWr.Time)
                            {
                                Slayer    = locWr.SlayPlayer,
                                EndDate   = locWr.SlayDate,
                                StartDate = _.Item2,
                                Author    = _.Item1,
                                Level     = level,
                                Stage     = stage
                            }));
                            break;

                        case StandingType.UnslayedExceptSelf:
                            var slayer  = locWr.SlayPlayer;
                            var holders = locWr.Holders.ToList();
                            if (currentStanding != null)
                            {
                                currentStanding.AddTime(locWr.Time);
                                holders.RemoveAll(_ => _.Item1.Id == currentStanding.Author.Id);
                                if (slayer == null || slayer.Id != currentStanding.Author.Id)
                                {
                                    currentStanding.Slayer  = slayer;
                                    currentStanding.EndDate = locWr.SlayDate;
                                    currentStanding         = null;
                                }
                            }
                            foreach (var holder in holders)
                            {
                                var locCurrentStanding = new Standing(locWr.Time)
                                {
                                    StartDate = holder.Item2,
                                    Author    = holder.Item1,
                                    Level     = level,
                                    Stage     = stage
                                };
                                standings.Add(locCurrentStanding);

                                if (slayer == null || slayer.Id != locCurrentStanding.Author.Id)
                                {
                                    locCurrentStanding.Slayer  = slayer;
                                    locCurrentStanding.EndDate = locWr.SlayDate;
                                }
                                else
                                {
                                    currentStanding = locCurrentStanding;
                                }
                            }
                            break;

                        case StandingType.Untied:
                            standings.Add(new Standing(locWr.Time)
                            {
                                Slayer    = locWr.UntiedSlayPlayer ?? locWr.SlayPlayer,
                                EndDate   = locWr.UntiedSlayDate ?? locWr.SlayDate,
                                StartDate = locWr.Date,
                                Author    = locWr.Player,
                                Level     = level,
                                Stage     = stage
                            });
                            break;

                        case StandingType.UntiedExceptSelf:
                            if (currentStanding == null)
                            {
                                currentStanding = new Standing(locWr.Time)
                                {
                                    StartDate = locWr.Date,
                                    Author    = locWr.Player,
                                    Level     = level,
                                    Stage     = stage
                                };
                                standings.Add(currentStanding);
                            }

                            currentStanding.AddTime(locWr.Time);

                            var untiedSlayer = locWr.UntiedSlayPlayer ?? locWr.SlayPlayer;
                            if (untiedSlayer == null || untiedSlayer.Id != currentStanding.Author.Id)
                            {
                                currentStanding.Slayer  = untiedSlayer;
                                currentStanding.EndDate = locWr.UntiedSlayDate ?? locWr.SlayDate;
                                currentStanding         = null;
                            }
                            break;

                        case StandingType.BetweenTwoTimes:
                            for (var i = 0; i < locWr.Holders.Count; i++)
                            {
                                var holder = locWr.Holders.ElementAt(i);
                                var isLast = i == locWr.Holders.Count - 1;
                                standings.Add(new Standing(locWr.Time)
                                {
                                    Slayer = isLast
                                            ? locWr.SlayPlayer
                                            : locWr.Holders.ElementAt(i + 1).Item1,
                                    EndDate = isLast
                                            ? locWr.SlayDate
                                            : locWr.Holders.ElementAt(i + 1).Item2,
                                    StartDate = holder.Item2,
                                    Author    = holder.Item1,
                                    Level     = level,
                                    Stage     = stage
                                });
                            }
                            break;
                        }
                    }
                }
            }

            var now = ServiceProviderAccessor.ClockProvider.Now;

            return(standings
                   .Where(x => stillOngoing == true
                    ? !x.EndDate.HasValue
                    : (stillOngoing == false
                        ? x.EndDate.HasValue
                        : true))
                   .OrderByDescending(x => x.WithDays(now).Days)
                   .ToList());
        }