Skip to content

Commit

Permalink
Update MatchScheduler.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
axunonb committed Jan 20, 2024
1 parent 3d20cc4 commit 1169639
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions TournamentManager/TournamentManager/Plan/MatchScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void SetMatchDates(RoundEntity round, ParticipantCombinations<long, long
// Get the selected turn combinations for the given turn.
var selectedTurnCombinations = combinations.GetCombinations(turn).ToList();

// Get match dates for every combination of a group.
// Get match dates for every combination of a turn.
// Matches in the same turnCombinations can even take place at the same time.
var datesFound = GetMatchDatesForTurn(turn, combinations, roundMatches);
_logger.LogDebug("Found dates for combination: {dates}",
Expand All @@ -139,7 +139,7 @@ private void SetMatchDates(RoundEntity round, ParticipantCombinations<long, long
.Select(bd => bd?.MatchStartTime.ToShortDateString() ?? "(null)"))
.Trim(',', ' '));

// MatchDates contains calculated dates in the same order as turn combinations,
// datesFound contains calculated dates in the same order as turn combinations,
// so the index can be used for both.
for (var index = 0; index < selectedTurnCombinations.Count; index++)
{
Expand Down Expand Up @@ -287,6 +287,7 @@ private static List<DateTime> GetOccupiedMatchDates(ParticipantCombination<long,
// initialize MinTimeDiff for the whole list
availableDatesForCombination.ForEach(amd => amd.MinTimeDiff = TimeSpan.MaxValue);

#if DEBUG
// Get the last match for at least one of the teams, if any
var lastMatchOfCombination = roundMatches.OrderBy(gm => gm.PlannedStart).LastOrDefault(gm =>
gm.HomeTeamId == combination.Home || gm.GuestTeamId == combination.Guest);
Expand All @@ -298,7 +299,7 @@ private static List<DateTime> GetOccupiedMatchDates(ParticipantCombination<long,
{
_logger.LogDebug("No matches yet for home team '{homeTeam}' or guest team '{guestTeam}'", combination.Home, combination.Guest);
}

#endif
// If no dates could be found, the date will be left blank.
if (availableDatesForCombination.Count == 0)
{
Expand All @@ -324,6 +325,7 @@ private static List<DateTime> GetOccupiedMatchDates(ParticipantCombination<long,

/// <summary>
/// Finds the best match dates from a list of available match dates for each combination.
/// The best match is the date that has the smallest distance to the smallest date in the other turn(s).
/// If no match dates could be determined for a team, bestDate will be set to null.
/// </summary>
/// <param name="availableMatchDates"></param>
Expand Down Expand Up @@ -358,7 +360,7 @@ private static List<DateTime> GetOccupiedMatchDates(ParticipantCombination<long,
} // end dates1
} // end j

// Get the date that has the least distance to the most small date in other turn(s)
// Get the date that has the smallest distance to the smallest date in the other turn(s).
// Note: If no match dates could be determined for a team, bestDate will be null.
var bestDate = availableMatchDates[i]
.Where(md => md.MinTimeDiff == availableMatchDates[i]
Expand Down

0 comments on commit 1169639

Please sign in to comment.