public void InBetweenInclusive() { Assert.IsTrue(MathJ.InBetweenInclusive(1, 0, 2)); Assert.IsTrue(MathJ.InBetweenInclusive(1, 2, 0)); Assert.IsFalse(MathJ.InBetweenInclusive(3, 0, 2)); Assert.IsFalse(MathJ.InBetweenInclusive(3, 2, 0)); }
static void Main(string[] args) { provider.GetTeams(); Schedule = provider.GetSchedule(); // Load result data structure Dictionary <Team, List <SeasonResult> > SeasonResults = new Dictionary <Team, List <SeasonResult> >(); foreach (var team in Schedule.Teams) { SeasonResults.Add(team, new List <SeasonResult>()); } IEnumerable <double> allScores = Schedule.Weeks.SelectMany(w => w.Matchups).Select(m => m.Team1ScoreInformation).Where(i => i.ActualScore.HasValue).Select(i => i.ActualScore.Value).Concat(Schedule.Weeks.SelectMany(w => w.Matchups).Select(m => m.Team2ScoreInformation).Where(i => i.ActualScore.HasValue).Select(i => i.ActualScore.Value)); ActualScores_StandardDeviation = MathJ.StandardDeviation(allScores); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); List <string> allResults = new List <string>(); StringBuilder header = new StringBuilder(","); for (int i = 1; i <= Schedule.Teams.Count; i++) { header.Append($"{i},"); } allResults.Add(header.ToString()); // Simulate seasons for (int i = 0; i < SIMULATIONS; i++) { if ((i + 1) % 1000 == 0) { Console.WriteLine($"Simulating season {i + 1}..."); } StringBuilder resultsStringBuilder = new StringBuilder($"{i + 1},"); foreach (var team in Schedule.Teams) { SeasonResults[team].Add(new SeasonResult(team)); } foreach (var week in Schedule.Weeks) { foreach (Matchup matchup in week.Matchups) { Result result = GetMatchupResult(matchup.Team1ScoreInformation, matchup.Team2ScoreInformation); SeasonResults[matchup.Team1ScoreInformation.Team].Last().Results.Add(result); SeasonResults[matchup.Team2ScoreInformation.Team].Last().Results.Add(result); } } List <SeasonResult> combinedLastSeasonResults = new List <SeasonResult>(); foreach (var team in Schedule.Teams) { combinedLastSeasonResults.Add(SeasonResults[team].Last()); } List <SeasonResult> rankedLastSeasonResults = combinedLastSeasonResults.OrderByDescending(r => r.Wins).ThenByDescending(r => r.PointsFor).ToList(); for (int j = 0; j < rankedLastSeasonResults.Count; j++) { rankedLastSeasonResults[j].Placement = j + 1; } if (rankedLastSeasonResults.Any(r => rankedLastSeasonResults.Any(r2 => r2.Team != r.Team && r2.Wins == r.Wins && r2.PointsFor == r.PointsFor))) { List <SeasonResult> tiedResults = rankedLastSeasonResults.Where(r => rankedLastSeasonResults.Any(r2 => r2.Team != r.Team && r2.Wins == r.Wins && r2.PointsFor == r.PointsFor)).ToList(); List <SeasonResult> headToHead = new List <SeasonResult>(); foreach (var result in tiedResults) { foreach (var opposingTeam in tiedResults.Where(r => r.Team != result.Team).Select(r => r.Team)) { headToHead.Add(new SeasonResult(result.Team, result.GetMatchesVs(opposingTeam))); } } int placeIndex = tiedResults.Min(r => r.Placement); foreach (var teamResult in headToHead) { tiedResults.First(r => r.Team == teamResult.Team).Placement = placeIndex; placeIndex++; } rankedLastSeasonResults.OrderBy(r => r.Placement); } foreach (var result in rankedLastSeasonResults) { resultsStringBuilder.Append($"{result.Team} - {result.RecordString} - {result.PointsFor},"); } allResults.Add(resultsStringBuilder.ToString()); } Console.WriteLine($"Simulations complete. Generating output csv..."); File.WriteAllLines(Path.Combine(Files.ProjectDirectory, @"Data\Summary.csv"), GetSeasonRecordsCsvList(SeasonResults).Concat(GetSeasonPlacementCsvList(SeasonResults)).ToArray()); if (PRINT_ALL_RESULTS) { File.WriteAllLines(Path.Combine(Files.ProjectDirectory, @"Data\Results.csv"), allResults.ToArray()); } stopwatch.Stop(); Console.WriteLine($"Completed in {stopwatch.Elapsed}"); }