private static void ManipulatePartnerResults(string email, Match match, List <PartnerPercentResult> result, int playerIndex, int partnerIndex, int enemy1Index, int enemy2Index) { if (match.PlayerList[playerIndex] == email) { PartnerPercentResult partner = result.Single(x => x.Email == match.PlayerList[partnerIndex]); partner.MatchesTogether++; PartnerPercentResult enemy1 = result.Single(x => x.Email == match.PlayerList[enemy1Index]); enemy1.MatchesAgainst++; PartnerPercentResult enemy2 = result.Single(x => x.Email == match.PlayerList[enemy2Index]); enemy2.MatchesAgainst++; if ((playerIndex == 0 || playerIndex == 1) && match.MatchResult.Team1Won) { partner.WinsTogether++; enemy1.WinsAgainst++; enemy2.WinsAgainst++; } if ((playerIndex == 2 || playerIndex == 3) && match.MatchResult.Team1Won == false) { partner.WinsTogether++; enemy1.WinsAgainst++; enemy2.WinsAgainst++; } } }
public List <PartnerPercentResult> GetPartnerWinPercent(string email, string season) { var leaderboard = _leaderboardViewRepository.GetLeaderboardView(season); double?normalWinRate = null; if (leaderboard != null) { normalWinRate = leaderboard.Entries.Where(e => e.UserName == email).Select(e => Math.Round((((double)e.Wins / (double)e.NumberOfGames) * 100), 2)).FirstOrDefault(); } var result = new List <PartnerPercentResult>(); foreach (User user in _userRepository.GetUsers()) { if (user.Email.NormalizedValue.ToLower() != email.ToLower()) { result.Add(new PartnerPercentResult { Username = user.UserName, Email = user.LowerEmail, UsersNormalWinrate = normalWinRate }); } } var matches = _matchRepository.GetMatches(season); foreach (Match match in matches) { if (match.PlayerList[0] == email) { PartnerPercentResult resultToManipulate = result.Single(x => x.Email == match.PlayerList[1]); resultToManipulate.Matches++; if (match.MatchResult.Team1Won) { resultToManipulate.Wins++; } } if (match.PlayerList[1] == email) { PartnerPercentResult resultToManipulate = result.Single(x => x.Email == match.PlayerList[0]); resultToManipulate.Matches++; if (match.MatchResult.Team1Won) { resultToManipulate.Wins++; } } if (match.PlayerList[2] == email) { PartnerPercentResult resultToManipulate = result.Single(x => x.Email == match.PlayerList[3]); resultToManipulate.Matches++; if (!match.MatchResult.Team1Won) { resultToManipulate.Wins++; } } if (match.PlayerList[3] == email) { PartnerPercentResult resultToManipulate = result.Single(x => x.Email == match.PlayerList[2]); resultToManipulate.Matches++; if (!match.MatchResult.Team1Won) { resultToManipulate.Wins++; } } } return(result .Where(x => x.Matches > 0) .OrderByDescending(x => (double)x.Wins / (double)x.Matches) .ToList()); }