예제 #1
0
        public Task <IEnumerable <Highscore> > GetHighscoresAsync(SeasonSelector season, string botName = null)
        {
            var seasonPeriod    = Season.SeasonPeriod(season);
            var seasonBeginning = seasonPeriod.Item1;
            var seasonEnd       = seasonPeriod.Item2;
            var collection      = _database.GetCollection <Highscore>("Highscores");
            var highscores      = collection
                                  .Aggregate(new AggregateOptions
            {
                AllowDiskUse = true,
            })
                                  .Match(highscore => botName == null || highscore.BotName == botName)
                                  .Match(highscore => seasonBeginning == null || highscore.SessionFinishedAt >= seasonBeginning)
                                  .Match(highscore => seasonEnd == null || highscore.SessionFinishedAt <= seasonEnd)
                                  // Get the top score for each bot
                                  .SortByDescending(highscore => highscore.Score)
                                  // NOTE: AFAICT This is equivalent to
                                  // .Group(highscore => highscore.BotName, group => group.First())
                                  // But for some reason that throws a NotSupportedException
                                  // Maybe it requires a newer Mongo server?
                                  .Group("{_id: \"$BotName\", TopScore: {$first: \"$$ROOT\"}}")
                                  .ReplaceRoot <Highscore>("$TopScore")
                                  // Re-sort (since the Group steps destroys the sorting)
                                  .SortByDescending(highscore => highscore.Score)
                                  .Limit(30)
                                  .ToCursor()
                                  .ToEnumerable();

            return(Task.FromResult(highscores));
        }
예제 #2
0
        public async Task <IActionResult> GetAsync(SeasonSelector season = SeasonSelector.Current)
        {
            var highscores = await _storage.GetHighscoresAsync(season);

            if (highscores == null)
            {
                return(NoContent());
            }

            return(Ok(highscores));
        }
예제 #3
0
        public IActionResult Get(SeasonSelector season = SeasonSelector.Current)
        {
            var highscores = _storage.GetHighscores(season);

            if (highscores == null)
            {
                return(NoContent());
            }

            return(Ok(highscores));
        }
예제 #4
0
        public static Tuple <DateTime?, DateTime?> SeasonPeriod(SeasonSelector selector)
        {
            switch (selector)
            {
            case SeasonSelector.All:
                return(new Tuple <DateTime?, DateTime?>(null, null));

            case SeasonSelector.Current:
                var beginning = All[All.Count - 2].EndsAt;
                return(new Tuple <DateTime?, DateTime?>(beginning, null));

            default:
                // COMPLETENESS CHECKING, ANYONE?
                throw new InvalidOperationException("Invalid season selector: " + selector.ToString());
            }
        }
예제 #5
0
 public Task <IEnumerable <Highscore> > GetHighscoresAsync(SeasonSelector season, string botName = null)
 {
     throw new NotImplementedException();
 }