Пример #1
0
        private void ProcessGameReport(RankedGameReport report)
        {
            List <PlayerGameStats> pubplayers = new List <PlayerGameStats>();

            foreach (RankedGameReport.PlayerStatLine p in report.PlayerStats)
            {
                ApplicationUser user = _db.UsersWithPlayer().FirstOrDefault(x => x.UserName == p.Name);
                if (user == null)
                {
                    throw new InvalidOperationException("tried to report game with unregistered players.");
                }

                PlayerGameStats pp = new PlayerGameStats()
                {
                    Player     = user.PlayerStats,
                    Team       = p.Team == "Red" ? HqmTeam.red : HqmTeam.blue,
                    Goals      = p.Goals,
                    Assists    = p.Assists,
                    RatingMean = user.PlayerStats.Rating.Mean,
                    RatingStandardDeviation = user.PlayerStats.Rating.StandardDeviation
                };

                pubplayers.Add(pp);
            }

            Game game = new Game()
            {
                GameId      = new Guid(),
                playerStats = pubplayers,
                redScore    = report.RedScore,
                blueScore   = report.BlueScore,
                date        = report.Date
            };

            _db.AddGame(game);

            //apply new ratings
            foreach (KeyValuePair <Player, Rating> kvp in game.GetNewRatings())
            {
                kvp.Key.Rating.Mean = kvp.Value.Mean;
                kvp.Key.Rating.StandardDeviation = kvp.Value.StandardDeviation;
            }
            _db.SaveChanges();
            _leaderboards.FlushLeaderboards();
        }
Пример #2
0
 public IActionResult ReportGame([FromBody] RankedGameReport report)
 {
     ProcessGameReport(report);
     return(Ok(_db.GetUserData()));
 }