public PlayerResponse Create(Player player) { return new PlayerResponse( name: player.Name, dropped: player.Dropped ); }
public decimal GetOpponentsGameWinPercentage(Tournament tournament, Player player, int? roundNumber = null) { var opponents = tournament.GetPlayerOpponents(player, roundNumber); return opponents .Select(opponent => GetGameWinPercentage(tournament, opponent, roundNumber)) .DefaultIfEmpty(0) .Average(); }
public int GetGamePoints(Tournament tournament, Player player, int? roundNumber = null) { return tournament .GetPlayerGames(player, roundNumber) .Select(game => new PlayerStats( wins: game.Winner == player ? 1 : 0, losses: game.Winner != player && game.Winner != null ? 1 : 0, draws: game.Winner == null ? 1 : 0 )) .Aggregate(0, (sum, stats) => sum + (stats.Wins * GameWin + stats.Draws * GameDraw + stats.Losses * GameLoss)); }
public static IEnumerable<Game> GetPlayerGames(this Tournament tournament, Player player, int? roundNumber = null) { if(tournament == null) return null; if(player == null) return null; return tournament .GetPlayerMatches(player, roundNumber) .SelectMany(match => match.Games); }
public static Match GetMatch(this Round round, Player player) { if(round == null) return null; if(player == null) return null; return round .Matches .Where(m => m.Players.Contains(player)) .FirstOrDefault(); }
public static IEnumerable<Match> GetPlayerMatches(this Tournament tournament, Player player, int? roundNumber = null) { if(tournament == null) return null; if(player == null) return null; return tournament .Rounds .Where(round => roundNumber == null || round.Number <= roundNumber) .SelectMany(round => round.Matches) .Where(match => match.Players.Contains(player)); }
public PlayerMatchStatsResponse Create(Player player, Match match) { if(player == null) throw new ArgumentNullException("player"); if(match == null) throw new ArgumentNullException("match"); return new PlayerMatchStatsResponse( name: player.Name, dropped: player.Dropped, wins: match.Games.Where(game => game.Winner == player).Count(), losses: match.Games.Where(game => game.Winner != player && game.Winner != null).Count(), draws: match.Games.Where(game => game.Winner == null).Count() ); }
public decimal GetMatchWinPercentage(Tournament tournament, Player player, int? roundNumber = null) { var achieved = GetMatchPoints(tournament, player, roundNumber); var maximum = tournament .GetPlayerMatches(player, roundNumber) .Count() * MatchWin; if(maximum == 0) return 0.33m; var rawPercentage = achieved / (decimal)maximum; // Match win percentage is capped at 0.33 on the low end return Math.Max(0.33m, rawPercentage); }
public int GetMatchPoints(Tournament tournament, Player player, int? roundNumber = null) { return tournament .GetPlayerMatches(player, roundNumber) .Select(match => new PlayerStats( wins: match.Games.Where(game => game.Winner == player).Count(), losses: match.Games.Where(game => game.Winner != player && game.Winner != null).Count(), draws: match.Games.Where(game => game.Winner == player).Count() )) .Select(stats => stats.Wins > stats.Losses ? MatchWin : stats.Wins == stats.Losses ? MatchDraw : MatchLoss) .Sum(); }
public static IEnumerable<Player> GetPlayerOpponents(this Tournament tournament, Player player, int? roundNumber = null) { if(tournament == null) return null; if(player == null) return null; return tournament .GetPlayerMatches(player, roundNumber) .SelectMany(match => match.Players) .Except(new[] { player }) .Distinct(); }