@ -496,6 +496,11 @@ defer {
}
}
func loserMatches ( ) -> [ Match ] {
guard let roundObject else { return [ ] }
return [ roundObject . upperBracketTopMatch ( ofMatchIndex : index , previousRound : nil ) , roundObject . upperBracketBottomMatch ( ofMatchIndex : index , previousRound : nil ) ] . compactMap ( { $0 } )
}
func loserMatch ( _ teamPosition : TeamPosition ) -> Match ? {
if teamPosition = = . one {
return roundObject ? . upperBracketTopMatch ( ofMatchIndex : index , previousRound : nil )
@ -718,7 +723,7 @@ defer {
func availableCourts ( ) -> [ Int ] {
let courtUsed = currentTournament ( ) ? . courtUsed ( ) ? ? [ ]
return Array ( Set ( allCourts ( ) . map { $0 } ) . subtracting ( Set ( courtUsed ) ) )
return Set ( allCourts ( ) . map { $0 } ) . subtracting ( Set ( courtUsed ) ) . sorted ( )
}
func removeCourt ( ) {
@ -970,9 +975,27 @@ defer {
return confirmed = = false && startDate . timeIntervalSinceNow < 0
}
func expectedFormattedStartDate ( ) -> String {
func expectedFormattedStartDate ( updatedField : Int ? ) -> String {
guard let startDate else { return " " }
return " était prévu à " + startDate . formattedAsHourMinute ( )
guard hasEnded ( ) = = false , isRunning ( ) = = false else { return " " }
let depthReadiness = depthReadiness ( )
if depthReadiness = = 0 {
let availableCourts = availableCourts ( )
if canBePlayedInSpecifiedCourt ( ) {
return " possible tout de suite "
} else if let updatedField , availableCourts . contains ( updatedField ) {
return " possible tout de suite \( courtName ( for : updatedField ) ) "
} else if let first = availableCourts . first {
return " possible tout de suite \( courtName ( for : first ) ) "
} else if let estimatedStartDate = estimatedStartDate ( ) {
return " dans ~ " + estimatedStartDate . 1. timeElapsedString ( ) + " " + courtName ( for : estimatedStartDate . 0 )
}
return " était prévu à " + startDate . formattedAsHourMinute ( )
} else if depthReadiness = = 1 {
return " possible prochaine rotation "
} else {
return " dans \( depthReadiness ) rotation \( depthReadiness . pluralSuffix ) , ~ \( ( getDuration ( ) * depthReadiness ) . durationInHourMinutes ( ) ) "
}
}
func runningDuration ( ) -> String {
@ -1032,6 +1055,22 @@ defer {
} )
}
func depthReadiness ( ) -> Int {
// B a s e c a s e : I f t h i s m a t c h i s r e a d y , t h e d e p t h i s 0
if isReady ( ) {
return 0
}
// R e c u r s i v e c a s e : I f n o t r e a d y , c h e c k t h e m a x i m u m d e p t h o f r e a d i n e s s a m o n g p r e v i o u s m a t c h e s
// I f p r e v i o u s M a t c h e s ( ) i s e m p t y , r e t u r n a d e f a u l t d e p t h o f - 1
let previousDepth = ancestors ( ) . map { $0 . depthReadiness ( ) } . max ( ) ? ? - 1
return previousDepth + 1
}
func ancestors ( ) -> [ Match ] {
previousMatches ( ) + loserMatches ( )
}
enum CodingKeys : String , CodingKey {
case _id = " id "