Пример #1
0
        private MessageResult RollbackGame(Command command, Match args)
        {
            var leagueName       = args.Group("league");
            var gamesPersistence = new ListPersistenceApi <Game>(m_Persistence, "games." + leagueName);
            var existingGames    = gamesPersistence.ReadList();

            var lastGame = existingGames.Last();

            gamesPersistence.RemoveFromList(x => x.Id == lastGame.Id);

            existingGames = gamesPersistence.ReadList();
            var league = GetCurrentLeague(existingGames);

            // Wipe the leaderboard
            var playersPersistence = new HashPersistenceApi <int>(m_Persistence, "players." + leagueName);

            playersPersistence.Clear();

            // Recalculate
            var leaderboard = league.GetLeaderBoard(m_EloScoringStrategy).ToList();

            foreach (var player in leaderboard.Select(x => x.Name))
            {
                var newRanking = GetRatingForPlayer(leaderboard, player);
                playersPersistence.Set(player, int.Parse(newRanking.ToString()));
            }

            return(new MessageResult(new List <Response>()
            {
                Response.ToMessage(command, "Successfully rolled back the last game")
            }));
        }
Пример #2
0
        public MessageResult ProcessTimerTick()
        {
            var trackedTickets = m_Persistence.ReadList();

            var comparison = trackedTickets.Select(x =>
                                                   new Update <TeamcityBuildStatus>(x.Channel, x.Value, m_TeamcityBuildApi.GetBuild(x.Value.Id).Result)
                                                   ).Where(x => x.NewValue.IsNotDefault());

            var results = m_TeamcityBuildCompareEngine.Compare(comparison).ToList();

            foreach (var result in results)
            {
                var id = result.NewValue.Id;
                m_Persistence.RemoveFromList(x => x.Value.Id == id);
                m_Persistence.AddToList(new Tracked <TeamcityBuildStatus>(result.NewValue, result.Response.Channel));
            }

            return(new MessageResult(results.Select(x => x.Response).ToList()));
        }
Пример #3
0
        private MessageResult RecordGame(Command command, Match args)
        {
            // TODO: try and break up this method a bit more
            var resultsString = args.Group("results");
            var gameResults   = ParseGameResults(resultsString);

            //Console.WriteLine(String.Join("\n", gameResults.Select(x => $"{x.Player} {x.Position}")));
            if (!gameResults.Any())
            {
                if (String.IsNullOrWhiteSpace(resultsString))
                {
                    return(Response.ToMessage(command, "Please provide some game results"));
                }
                return(Response.ToMessage(command, string.Format("Could not parse results `{0}`", resultsString)));
            }
            var responses = new List <Response>();

            var leagueName       = args.Group("league");
            var gamesPersistence = new ListPersistenceApi <Game>(m_Persistence, "games." + leagueName);
            var existingGames    = gamesPersistence.ReadList();
            var league           = GetCurrentLeague(existingGames);

            var playersPersistence = new HashPersistenceApi <int>(m_Persistence, "players." + leagueName);
            var playerNames        = playersPersistence.GetKeys();

            if (!existingGames.Any())
            {
                responses.Add(Response.ToMessage(command, string.Format("Creating new league `{0}`", leagueName)));
            }

            gameResults = GetCanonicalPlayerNames(gameResults, playerNames);

            var newPlayers = FindNewPlayers(gameResults, playerNames);

            responses.AddRange(newPlayers.Select(x =>
                                                 Response.ToMessage(command, string.Format("Adding new player *{0}*", m_AliasList.GetDisplayNameFor(x)))));

            var nextId = existingGames.Count != 0 ? existingGames.Max(x => x.Id) + 1 : 1;

            var newGame = new Game(gameResults, nextId);

            gamesPersistence.AddToList(newGame);
            league.RecordGame(GetPlayerRankGame(newGame));

            var leaderboardHistory = league.GetLeaderBoardHistory(m_EloScoringStrategy).ToList();
            var totalGames         = leaderboardHistory.Count;
            var latestLeaderboard  = leaderboardHistory[totalGames - 1].Leaderboard.ToList();

            var leaderboardChanges = ResultChangeStats.GetResultChangesBewteenGames(
                leaderboardHistory, totalGames, totalGames > 1 ? totalGames - 1 : 1);

            foreach (var player in newGame.Results.Select(x => x.Player))
            {
                var newRanking = GetRatingForPlayer(latestLeaderboard, player);
                playersPersistence.Set(player, int.Parse(newRanking.ToString()));
            }

            var rankingChanges = GetResultsWithRankingChanges(leaderboardChanges);

            responses.AddRange(rankingChanges.Select(x => Response.ToMessage(command, x)));
            return(new MessageResult(responses));
        }