コード例 #1
0
ファイル: UserLogic.cs プロジェクト: Mech0z/Foosball
        public async Task <List <PlayerLeaderboardEntry> > GetPlayerLeaderboardEntries(string email)
        {
            var result       = new List <PlayerLeaderboardEntry>();
            var leaderboards = await _leaderboardViewRepository.GetLeaderboardViews();

            foreach (var leaderboard in leaderboards)
            {
                var leaderboardEntries = leaderboard.Entries.OrderByDescending(x => x.EloRating).ToList();
                var playerEntry        = leaderboardEntries.SingleOrDefault(x => x.UserName == email);
                if (playerEntry != null)
                {
                    result.Add(new PlayerLeaderboardEntry
                    {
                        UserName      = email,
                        EloRating     = playerEntry.EloRating,
                        Losses        = playerEntry.Losses,
                        NumberOfGames = playerEntry.NumberOfGames,
                        Wins          = playerEntry.Wins,
                        SeasonName    = leaderboard.SeasonName,
                        Rank          = leaderboardEntries.IndexOf(playerEntry) + 1
                    });
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: LeaderboardService.cs プロジェクト: Mech0z/Foosball
        public async Task <List <LeaderboardView> > GetLatestLeaderboardViews()
        {
            var seasons = await _seasonLogic.GetStartedSeasons();

            var latestLeaderboardViews = await _leaderboardViewRepository.GetLeaderboardViews();

            foreach (Season season in seasons)
            {
                bool existingLeaderboard = latestLeaderboardViews.Any(x => x.SeasonName == season.Name);

                if (existingLeaderboard == false)
                {
                    var leaderboardView = await RecalculateLeaderboard(season);

                    if (leaderboardView.Entries != null)
                    {
                        latestLeaderboardViews.Add(leaderboardView);
                    }
                }
            }

            foreach (LeaderboardView leaderboardView in latestLeaderboardViews)
            {
                leaderboardView.Entries = leaderboardView.Entries.OrderByDescending(x => x.EloRating).ToList();
            }

            List <LeaderboardView> startDateSorted = latestLeaderboardViews
                                                     .Select(x => new { Lbw = x, Season = seasons.Single(s => s.Name == x.SeasonName) })
                                                     .OrderByDescending(x => x.Season.StartDate).Select(x => x.Lbw).ToList();

            return(startDateSorted);
        }
コード例 #3
0
        public List <LeaderboardView> GetLatestLeaderboardViews()
        {
            var seasons = _seasonLogic.GetSeasons();

            var latestLeaderboardViews = _leaderboardViewRepository.GetLeaderboardViews();

            foreach (var season in seasons)
            {
                var existingLeaderboard = latestLeaderboardViews.Any(x => x.SeasonName == season.Name);

                if (existingLeaderboard == false)
                {
                    latestLeaderboardViews.Add(RecalculateLeaderboard(season.Name));
                }
            }

            foreach (var season in latestLeaderboardViews)
            {
                season.Entries = season.Entries.OrderByDescending(x => x.EloRating).ToList();
            }

            return(latestLeaderboardViews);
        }