|
|
|
|
@ -105,8 +105,15 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { |
|
|
|
|
|
|
|
|
|
dispatch.timedMatches.forEach { matchSchedule in |
|
|
|
|
if let match = matches.first(where: { $0.id == matchSchedule.matchID }) { |
|
|
|
|
let estimatedDuration = match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration) |
|
|
|
|
let timeIntervalToAdd = (Double(matchSchedule.rotationIndex)) * Double(estimatedDuration) * 60 |
|
|
|
|
var estimatedDuration = match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration) |
|
|
|
|
if accountGroupStageBreakTime { |
|
|
|
|
estimatedDuration += match.matchFormat.breakTime.breakTime * 60 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var timeIntervalToAdd = (Double(matchSchedule.rotationIndex)) * Double(estimatedDuration) * 60 |
|
|
|
|
|
|
|
|
|
timeIntervalToAdd += Double(matchSchedule.rotationIndex) * Double(self.groupStageRotationDifference) * Double(match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) * 60 |
|
|
|
|
|
|
|
|
|
if let startDate = match.groupStageObject?.startDate { |
|
|
|
|
let matchStartDate = startDate.addingTimeInterval(timeIntervalToAdd) |
|
|
|
|
match.startDate = matchStartDate |
|
|
|
|
@ -129,8 +136,16 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { |
|
|
|
|
|
|
|
|
|
dispatch.timedMatches.forEach { matchSchedule in |
|
|
|
|
if let match = matches.first(where: { $0.id == matchSchedule.matchID }) { |
|
|
|
|
let estimatedDuration = match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration) |
|
|
|
|
let timeIntervalToAdd = (Double(matchSchedule.rotationIndex)) * Double(estimatedDuration) * 60 |
|
|
|
|
var estimatedDuration = match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration) |
|
|
|
|
|
|
|
|
|
if accountGroupStageBreakTime { |
|
|
|
|
estimatedDuration += match.matchFormat.breakTime.breakTime * 60 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var timeIntervalToAdd = (Double(matchSchedule.rotationIndex)) * Double(estimatedDuration) * 60 |
|
|
|
|
|
|
|
|
|
timeIntervalToAdd += Double(matchSchedule.rotationIndex) * Double(self.groupStageRotationDifference) * Double(match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) * 60 |
|
|
|
|
|
|
|
|
|
if let startDate = match.groupStageObject?.startDate { |
|
|
|
|
let matchStartDate = startDate.addingTimeInterval(timeIntervalToAdd) |
|
|
|
|
match.startDate = matchStartDate |
|
|
|
|
@ -207,8 +222,16 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { |
|
|
|
|
courtsAvailable.forEach { courtIndex in |
|
|
|
|
print("Checking availability for court \(courtIndex) in rotation \(rotationIndex)") |
|
|
|
|
if let first = rotationMatches.first(where: { match in |
|
|
|
|
let estimatedDuration = match.matchFormat.getEstimatedDuration(additionalEstimationDuration) |
|
|
|
|
let timeIntervalToAdd = Double(rotationIndex) * Double(estimatedDuration) * 60 |
|
|
|
|
var estimatedDuration = match.matchFormat.getEstimatedDuration(additionalEstimationDuration) |
|
|
|
|
|
|
|
|
|
if accountGroupStageBreakTime { |
|
|
|
|
estimatedDuration += match.matchFormat.breakTime.breakTime * 60 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var timeIntervalToAdd = (Double(rotationIndex)) * Double(estimatedDuration) * 60 |
|
|
|
|
|
|
|
|
|
timeIntervalToAdd += Double(rotationIndex) * Double(self.groupStageRotationDifference) * Double(match.matchFormat.getEstimatedDuration(additionalEstimationDuration)) * 60 |
|
|
|
|
|
|
|
|
|
let rotationStartDate: Date = startingDate.addingTimeInterval(timeIntervalToAdd) |
|
|
|
|
|
|
|
|
|
let courtsUnavailable = courtsUnavailable(startDate: rotationStartDate, duration: match.matchFormat.getEstimatedDuration(additionalEstimationDuration), courtsUnavailability: courtsUnavailability) |
|
|
|
|
@ -822,7 +845,31 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { |
|
|
|
|
if tournament.groupStages(atStep: 1).isEmpty == false { |
|
|
|
|
lastDate = updateGroupStageSchedule(tournament: tournament, atStep: 1, startDate: lastDate) |
|
|
|
|
} |
|
|
|
|
return updateBracketSchedule(tournament: tournament, fromRoundId: nil, fromMatchId: nil, startDate: lastDate) |
|
|
|
|
let allMatches = tournament.groupStagesMatches().filter({ $0.hasEnded() == false && $0.hasStarted() == false }) |
|
|
|
|
|
|
|
|
|
let groupMatchesByDay = tournament.groupMatchesByDay(matches: allMatches) |
|
|
|
|
|
|
|
|
|
let countedSet = tournament.matchCountPerDay(matchesByDay: groupMatchesByDay) |
|
|
|
|
|
|
|
|
|
var bracketStartDate = lastDate |
|
|
|
|
print("lastDate", lastDate) |
|
|
|
|
var errorFormat = false |
|
|
|
|
let dates = countedSet.keys |
|
|
|
|
if let first = dates.first, let matchesInLastDate = countedSet[first] { |
|
|
|
|
let totalMatches = matchesInLastDate.totalCount() |
|
|
|
|
let count = matchesInLastDate.count(for: tournament.groupStageMatchFormat) |
|
|
|
|
let totalForThisFormat = tournament.groupStageMatchFormat.maximumMatchPerDay(for: totalMatches) |
|
|
|
|
print(totalMatches, count, totalForThisFormat) |
|
|
|
|
errorFormat = count >= totalForThisFormat |
|
|
|
|
print("bracketStartDate", bracketStartDate) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if tournament.dayDuration > 1 && (lastDate.timeOfDay == .evening || errorFormat) { |
|
|
|
|
bracketStartDate = lastDate.tomorrowAtNine |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return updateBracketSchedule(tournament: tournament, fromRoundId: nil, fromMatchId: nil, startDate: bracketStartDate) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -886,3 +933,14 @@ extension Match { |
|
|
|
|
return groupStageObject._matchUp(for: index).map { groupStageObject.id + "_\($0)" } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Extension to compute the total count in an NSCountedSet |
|
|
|
|
extension NSCountedSet { |
|
|
|
|
func totalCount() -> Int { |
|
|
|
|
var total = 0 |
|
|
|
|
for element in self { |
|
|
|
|
total += self.count(for: element) |
|
|
|
|
} |
|
|
|
|
return total |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|