Пример #1
0
        public IActionResult OnGet()
        {
            Predictions = _predictionData.GetAll();
            var EntityGames = Predictions.Select(p => p.Game).Distinct().OrderBy(g => g.Order);

            Games = new List <GameEditModel>();
            foreach (var game in EntityGames)
            {
                if (Games.All(g => g.Id != game.Id))
                {
                    Games.Add(_gameConverter.ToEditModel(game));
                }
            }
            Users       = _userData.GetAll();
            TotalScores = new Dictionary <int, int>();
            foreach (var user in Users)
            {
                var total = 0;
                foreach (var p in Predictions.Where(p => p.User.Id == user.Id))
                {
                    total += _scoreCalculator.Calculate(p.Game.HalftimeScore, p.Game.FulltimeScore, p.HalftimeScore,
                                                        p.FulltimeScore);
                }
                TotalScores.Add(user.Id, total);
            }
            return(Page());
        }
Пример #2
0
        public void Handle(GamePlayed @event)
        {
            _gamesPlayed++;
            HandleVinkekatSituations(@event);
            var result = _scoreCalculator.Calculate(_playerCache[@event.RedOffensive],
                                                    _playerCache[@event.RedDefensive],
                                                    _playerCache[@event.BlueOffensive],
                                                    _playerCache[@event.BlueDefensive],
                                                    @event.ScoreRed,
                                                    @event.ScoreBlue,
                                                    _gamesPlayed / _playerCount, @event.Date);

            _activitites.Add(result.Story);
            SetScore(result, @event.RedWinner);
            _minMaxCache.Update(result.BlueDefensive.ScoreCount, result.BlueOffensive.ScoreCount, result.RedDefensive.ScoreCount, result.RedOffensive.ScoreCount);
        }
Пример #3
0
        internal async Task <ScoreResult[]> CalculatePlayerScores(string tenantId, string tournamentId, MatchResult result)
        {
            // 1. Get Players from tournament
            // 1.1 Get Tournament Entry
            var entry = await GetStateEntry(tenantId);

            // 1.2 Convert into List
            var tournaments = ToList(entry);

            // 1.3 Try get Tournament
            if (!tournaments.Any(t => t.Id == tournamentId))
            {
                throw new NotFoundException($"Tournament Id {tournamentId} is not found");
            }
            var tournament = tournaments.First(t => t.Id == tournamentId);

            // 1.4 Players must exist in Tournament
            if (!tournament.Players.Any(p => p.Id == result.Player1Id))
            {
                throw new BadRequestException($"Player Id \"{result.Player1Id}\" does not exist in this Tournament.");
            }

            if (!tournament.Players.Any(p => p.Id == result.Player2Id))
            {
                throw new BadRequestException($"Player Id \"{result.Player2Id}\" does not exist in this Tournament.");
            }

            var players = tournament.Players.ToDictionary(p => p.Id);

            // 1.5 Get each player's current score and parse to ScoreResult
            ScoreResult playerOne = new ScoreResult(result.Player1Id, players[result.Player1Id].RankingScore);
            ScoreResult playerTwo = new ScoreResult(result.Player2Id, players[result.Player2Id].RankingScore);

            ScoreResult[] scores = { playerOne, playerTwo };

            // 2. Calculate score
            ScoreResult[] newScores = _scoreCalculator.Calculate(scores, result.WinnerId);

            // 3. Return score results
            return(newScores);
        }