public void Generate() { HistoricalTeamRanks = new Dictionary <string, List <int> >(); foreach (var team in teamRepository.GetTeams()) { HistoricalTeamRanks.Add(TeamToKey(team), new List <int> { EloHandler.StartingScore }); } foreach (var game in gameRepository.GetGames().OrderBy(g => g.GameTime)) { var blueTeam = new DisplayTeam { DefenseID = game.BlueDefense, OffenseID = game.BlueOffense, }; var redTeam = new DisplayTeam { DefenseID = game.RedDefense, OffenseID = game.RedOffense }; blueTeam.GamesPlayed = HistoricalTeamRanks[TeamToKey(blueTeam)].Count - 1; redTeam.GamesPlayed = HistoricalTeamRanks[TeamToKey(redTeam)].Count - 1; var blueRankList = HistoricalTeamRanks[TeamToKey(blueTeam)]; var redRankList = HistoricalTeamRanks[TeamToKey(redTeam)]; blueTeam.Rank = blueRankList[blueRankList.Count - 1]; redTeam.Rank = redRankList[redRankList.Count - 1]; var updatedRanks = EloHandler.UpdatedRanks(blueTeam, redTeam, game); HistoricalTeamRanks[TeamToKey(blueTeam)].Add(updatedRanks[0]); HistoricalTeamRanks[TeamToKey(redTeam)].Add(updatedRanks[1]); } //var blueIDs = $"{blueTeam.DefenseID} {blueTeam.OffenseID}"; //var redIDs = $"{blueTeam.DefenseID} {blueTeam.OffenseID}"; //try //{ // HistoricalTeamRanks[blueIDs].Add(blueTeam.Rank); //} //catch //{ // HistoricalTeamRanks.Add(blueIDs, new List<int> { 1200,blueTeam.Rank }); //} //try //{ // HistoricalTeamRanks[redIDs].Add(redTeam.Rank); //} //catch //{ // HistoricalTeamRanks.Add(redIDs, new List<int> { 1200,redTeam.Rank }); //} }
public void Update(Game newGame) { //win = {blue,red} var win = new[] { 0, 0 }; if (newGame.BlueScore > newGame.RedScore) { win = new[] { 1, 0 }; } else { win = new[] { 0, 1 }; } var blueTeam = teamStatsRetriever.GetTeamByPlayers(newGame.BlueDefense, newGame.BlueOffense); var redTeam = teamStatsRetriever.GetTeamByPlayers(newGame.RedDefense, newGame.RedOffense); if (blueTeam == null) { teamCreator.Create(new Team { DefenseID = newGame.BlueDefense, OffenseID = newGame.BlueOffense, GamesPlayed = 0, GamesWon = 0, }); blueTeam = new DisplayTeam { DefenseID = newGame.BlueDefense, OffenseID = newGame.BlueOffense, GamesPlayed = 0, GamesWon = 0, Rank = EloHandler.StartingScore }; } if (redTeam == null) { teamCreator.Create(new Team { DefenseID = newGame.RedDefense, OffenseID = newGame.RedOffense, GamesPlayed = 0, GamesWon = 0, }); redTeam = new DisplayTeam { DefenseID = newGame.RedDefense, OffenseID = newGame.RedOffense, GamesPlayed = 0, GamesWon = 0, Rank = EloHandler.StartingScore }; } var updatedScores = EloHandler.UpdatedRanks(blueTeam, redTeam, newGame); blueTeam.GamesPlayed += 1; blueTeam.GamesWon += win[0]; blueTeam.Rank = updatedScores[0]; redTeam.GamesPlayed += 1; redTeam.GamesWon += win[1]; redTeam.Rank = updatedScores[1]; teamRepository.Update(blueTeam); teamRepository.Update(redTeam); }