public Group(IEnumerable <Game> games) { this.GroupName = games.Select(x => x.Group).Distinct().Single(); this.TeamNames = new List <string>(); this.FinishedGames = new List <Game>(); this.RemainingGames = new List <Game>(); foreach (var game in games) { if (!this.TeamNames.Contains(game.HomeTeam)) { this.TeamNames.Add(game.HomeTeam); } if (!this.TeamNames.Contains(game.AwayTeam)) { this.TeamNames.Add(game.AwayTeam); } if (game.IsFinal) { this.FinishedGames.Add(game); } else { this.RemainingGames.Add(game); } } this.CurrentStandings = new List <BaseTeamStanding>(); foreach (var teamName in this.TeamNames) { var currentTeamStanding = new BaseTeamStanding(teamName, this.FinishedGames); this.CurrentStandings.Add(currentTeamStanding); } }
public Scenario(string key, List <BaseTeamStanding> baseTeamStandings, List <Game> futureGames) { this.Key = key; var localTeamStandings = baseTeamStandings.Select(x => BaseTeamStanding.CopyTeamStanding(x)).ToList(); foreach (var team in localTeamStandings) { foreach (var game in futureGames) { if (game.HasTeam(team.TeamName)) { team.AddResult(game); } } } var outcomeTiers = localTeamStandings .GroupBy(x => x.Points) .Select(x => new { Points = x.Key, Teams = x.Select(y => new { TeamName = y.TeamName, GoalsScored = y.GoalsScored, GoalsAllowed = y.GoalsAllowed }), Count = x.Count() }) .OrderByDescending(x => x.Points) .ToList(); this.TeamOutcomes = new List <ScenarioTeamOutcome>(); int betterTeams = 0; foreach (var outcomeTier in outcomeTiers) { int bestResult = betterTeams + 1; int worstResult = betterTeams + outcomeTier.Count; foreach (var team in outcomeTier.Teams) { this.TeamOutcomes.Add(new ScenarioTeamOutcome(team.TeamName, outcomeTier.Points, bestResult, worstResult, team.GoalsScored, team.GoalsAllowed)); } betterTeams += outcomeTier.Count; } }