private void UpdatePlayerRatings() { var calculator = new RatingCalculator(/* initVolatility, tau */); // Instantiate a RatingPeriodResults object. var results = new RatingPeriodResults(); var ratingsPlayers = new List <Tuple <User, Rating> >(); double team1Rating = Team1.Sum(x => x.SkillRating) / Team1.Count; double team2Rating = Team2.Sum(x => x.SkillRating) / Team2.Count; double team1RatingsDeviation = Team1.Sum(x => x.RatingsDeviation) / Team1.Count; double team2RatingsDeviation = Team2.Sum(x => x.RatingsDeviation) / Team2.Count; double team1Volatility = Team1.Sum(x => x.Volatility) / Team1.Count; double team2Volatility = Team2.Sum(x => x.Volatility) / Team2.Count; var team1RatingCalc = new Rating(calculator, team1Rating, team1RatingsDeviation, team1Volatility); var team2RatingCalc = new Rating(calculator, team2Rating, team2RatingsDeviation, team2Volatility); foreach (var player in Team1) { var playerRating = new Rating(calculator, player.SkillRating, player.RatingsDeviation, player.Volatility); ratingsPlayers.Add(new Tuple <User, Rating>(player, playerRating)); if (WinningTeam == Team1) { results.AddResult(playerRating, team2RatingCalc); } else if (WinningTeam == Team2) { results.AddResult(team2RatingCalc, playerRating); } } foreach (var player in Team2) { var playerRating = new Rating(calculator, player.SkillRating, player.RatingsDeviation, player.Volatility); ratingsPlayers.Add(new Tuple <User, Rating>(player, playerRating)); if (WinningTeam == Team1) { results.AddResult(team1RatingCalc, playerRating); } else if (WinningTeam == Team2) { results.AddResult(playerRating, team1RatingCalc); } } calculator.UpdateRatings(results); foreach (var player in ratingsPlayers) { player.Item1.PreviousSkillRating = player.Item1.SkillRating; player.Item1.SkillRating = player.Item2.GetRating(); player.Item1.RatingsDeviation = player.Item2.GetRatingDeviation(); player.Item1.Volatility = player.Item2.GetVolatility(); db.Users.Update(player.Item1); } db.SaveChanges(); }