|
|
|
|
@ -393,7 +393,7 @@ final class MatchScheduler : ModelObject, Storable { |
|
|
|
|
print("Setting minimumTargetedEndDate to the earlier of \(minimumPossibleEndDate) and \(minimumTargetedEndDate)") |
|
|
|
|
minimumTargetedEndDate = min(minimumPossibleEndDate, minimumTargetedEndDate) |
|
|
|
|
} |
|
|
|
|
print("Targeted start date is before the minimum possible end date, returning false.") |
|
|
|
|
print("Targeted start date \(targetedStartDate) is before the minimum possible end date, returning false. \(minimumTargetedEndDate)") |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -462,11 +462,20 @@ final class MatchScheduler : ModelObject, Storable { |
|
|
|
|
var freeCourtPerRotation = [Int: [Int]]() |
|
|
|
|
var courts = initialCourts ?? Array(courtsAvailable) |
|
|
|
|
var shouldStartAtDispatcherDate = rotationIndex > 0 |
|
|
|
|
var suitableDate: Date? |
|
|
|
|
|
|
|
|
|
while !availableMatchs.isEmpty && !issueFound && rotationIndex < 50 { |
|
|
|
|
freeCourtPerRotation[rotationIndex] = [] |
|
|
|
|
let previousRotationSlots = slots.filter({ $0.rotationIndex == rotationIndex - 1 }) |
|
|
|
|
var rotationStartDate: Date = getNextStartDate(fromPreviousRotationSlots: previousRotationSlots, includeBreakTime: false) ?? dispatcherStartDate |
|
|
|
|
|
|
|
|
|
var rotationStartDate: Date |
|
|
|
|
if previousRotationSlots.isEmpty && rotationIndex > 0 { |
|
|
|
|
let computedSuitableDate = slots.sorted(by: \.computedEndDateForSorting).last?.computedEndDateForSorting |
|
|
|
|
print("Previous rotation was empty, find a suitable rotationStartDate \(suitableDate)") |
|
|
|
|
rotationStartDate = suitableDate ?? computedSuitableDate ?? dispatcherStartDate |
|
|
|
|
} else { |
|
|
|
|
rotationStartDate = getNextStartDate(fromPreviousRotationSlots: previousRotationSlots, includeBreakTime: false) ?? dispatcherStartDate |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if shouldStartAtDispatcherDate { |
|
|
|
|
rotationStartDate = dispatcherStartDate |
|
|
|
|
@ -539,7 +548,7 @@ final class MatchScheduler : ModelObject, Storable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Dispatch courts and schedule matches |
|
|
|
|
dispatchCourts(courts: courts, availableMatchs: &availableMatchs, slots: &slots, rotationIndex: rotationIndex, rotationStartDate: rotationStartDate, freeCourtPerRotation: &freeCourtPerRotation, courtsUnavailability: courtsUnavailability) |
|
|
|
|
suitableDate = dispatchCourts(courts: courts, availableMatchs: &availableMatchs, slots: &slots, rotationIndex: rotationIndex, rotationStartDate: rotationStartDate, freeCourtPerRotation: &freeCourtPerRotation, courtsUnavailability: courtsUnavailability) |
|
|
|
|
rotationIndex += 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -561,7 +570,7 @@ final class MatchScheduler : ModelObject, Storable { |
|
|
|
|
return MatchDispatcher(timedMatches: slots, freeCourtPerRotation: freeCourtPerRotation, rotationCount: rotationIndex, issueFound: issueFound) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dispatchCourts(courts: [Int], availableMatchs: inout [Match], slots: inout [TimeMatch], rotationIndex: Int, rotationStartDate: Date, freeCourtPerRotation: inout [Int: [Int]], courtsUnavailability: [DateInterval]?) { |
|
|
|
|
func dispatchCourts(courts: [Int], availableMatchs: inout [Match], slots: inout [TimeMatch], rotationIndex: Int, rotationStartDate: Date, freeCourtPerRotation: inout [Int: [Int]], courtsUnavailability: [DateInterval]?) -> Date { |
|
|
|
|
var matchPerRound = [String: Int]() |
|
|
|
|
var minimumTargetedEndDate = rotationStartDate |
|
|
|
|
|
|
|
|
|
@ -644,6 +653,8 @@ final class MatchScheduler : ModelObject, Storable { |
|
|
|
|
if freeCourtPerRotation[rotationIndex]?.count == courtsAvailable.count { |
|
|
|
|
print("All courts in rotation \(rotationIndex) are free") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return minimumTargetedEndDate |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@discardableResult func updateBracketSchedule(tournament: Tournament, fromRoundId roundId: String?, fromMatchId matchId: String?, startDate: Date) -> Bool { |
|
|
|
|
@ -839,6 +850,10 @@ struct TimeMatch { |
|
|
|
|
let minutesToAdd = Double(durationLeft + (includeBreakTime ? minimumBreakTime : 0)) |
|
|
|
|
return startDate.addingTimeInterval(minutesToAdd * 60.0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var computedEndDateForSorting: Date { |
|
|
|
|
estimatedEndDate(includeBreakTime: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct GroupStageMatchDispatcher { |
|
|
|
|
|