@ -32,7 +32,6 @@ class Tournament : ModelObject, Storable {
var federalCategory : TournamentCategory
var federalLevelCategory : TournamentLevel
var federalAgeCategory : FederalTournamentAge
var groupStageCourtCount : Int ?
var closedRegistrationDate : Date ?
var groupStageAdditionalQualified : Int
var courtCount : Int = 2
@ -44,9 +43,8 @@ class Tournament : ModelObject, Storable {
var additionalEstimationDuration : Int = 0
var isDeleted : Bool = false
var isCanceled : Bool = false
var publishManually : Bool = false
var publishTeams : Bool = false
var publishWaitingList : Bool = fals e
// v a r p u b l i s h W a i t i n g L i s t : B o o l = f a l s e
var publishSummons : Bool = false
var publishGroupStages : Bool = false
var publishBrackets : Bool = false
@ -75,7 +73,6 @@ class Tournament : ModelObject, Storable {
case _federalCategory = " federalCategory "
case _federalLevelCategory = " federalLevelCategory "
case _federalAgeCategory = " federalAgeCategory "
case _groupStageCourtCount = " groupStageCourtCount "
case _seedCount = " seedCount "
case _closedRegistrationDate = " closedRegistrationDate "
case _groupStageAdditionalQualified = " groupStageAdditionalQualified "
@ -88,15 +85,14 @@ class Tournament : ModelObject, Storable {
case _isDeleted = " isDeleted "
case _isCanceled = " localId "
case _payment = " globalId "
case _publishManually = " publishManually "
case _publishTeams = " publishTeams "
case _publishWaitingList = " publishWaitingList "
// c a s e _ p u b l i s h W a i t i n g L i s t = " p u b l i s h W a i t i n g L i s t "
case _publishSummons = " publishSummons "
case _publishGroupStages = " publishGroupStages "
case _publishBrackets = " publishBrackets "
}
internal init ( event : String ? = nil , name : String ? = nil , startDate : Date = Date ( ) , endDate : Date ? = nil , creationDate : Date = Date ( ) , isPrivate : Bool = false , groupStageFormat : MatchFormat ? = nil , roundFormat : MatchFormat ? = nil , loserRoundFormat : MatchFormat ? = nil , groupStageSortMode : GroupStageOrderingMode , groupStageCount : Int = 4 , rankSourceDate : Date ? = nil , dayDuration : Int = 1 , teamCount : Int = 24 , teamSorting : TeamSortingType ? = nil , federalCategory : TournamentCategory , federalLevelCategory : TournamentLevel , federalAgeCategory : FederalTournamentAge , groupStageCourtCount : Int ? = nil , closedRegistrationDate : Date ? = nil , groupStageAdditionalQualified : Int = 0 , courtCount : Int = 2 , prioritizeClubMembers : Bool = false , qualifiedPerGroupStage : Int = 1 , teamsPerGroupStage : Int = 4 , entryFee : Double ? = nil , additionalEstimationDuration : Int = 0 , isDeleted : Bool = false , publishManually : Bool = false , publishTeams : Bool = false , publishWaitingList : Bool = false , publishSummons : Bool = false , publishGroupStages : Bool = false , publishBrackets : Bool = false ) {
internal init ( event : String ? = nil , name : String ? = nil , startDate : Date = Date ( ) , endDate : Date ? = nil , creationDate : Date = Date ( ) , isPrivate : Bool = false , groupStageFormat : MatchFormat ? = nil , roundFormat : MatchFormat ? = nil , loserRoundFormat : MatchFormat ? = nil , groupStageSortMode : GroupStageOrderingMode , groupStageCount : Int = 4 , rankSourceDate : Date ? = nil , dayDuration : Int = 1 , teamCount : Int = 24 , teamSorting : TeamSortingType ? = nil , federalCategory : TournamentCategory , federalLevelCategory : TournamentLevel , federalAgeCategory : FederalTournamentAge , closedRegistrationDate : Date ? = nil , groupStageAdditionalQualified : Int = 0 , courtCount : Int = 2 , prioritizeClubMembers : Bool = false , qualifiedPerGroupStage : Int = 1 , teamsPerGroupStage : Int = 4 , entryFee : Double ? = nil , additionalEstimationDuration : Int = 0 , isDeleted : Bool = false , publishTeams : Bool = false , publishSummons : Bool = false , publishGroupStages : Bool = false , publishBrackets : Bool = false ) {
self . event = event
self . name = name
self . startDate = startDate
@ -115,7 +111,6 @@ class Tournament : ModelObject, Storable {
self . federalCategory = federalCategory
self . federalLevelCategory = federalLevelCategory
self . federalAgeCategory = federalAgeCategory
self . groupStageCourtCount = groupStageCourtCount
self . closedRegistrationDate = closedRegistrationDate
self . groupStageAdditionalQualified = groupStageAdditionalQualified
self . courtCount = courtCount
@ -125,6 +120,10 @@ class Tournament : ModelObject, Storable {
self . entryFee = entryFee
self . additionalEstimationDuration = additionalEstimationDuration
self . isDeleted = isDeleted
self . publishTeams = publishTeams
self . publishSummons = publishSummons
self . publishBrackets = publishBrackets
self . publishGroupStages = publishGroupStages
}
required init ( from decoder : Decoder ) throws {
@ -148,7 +147,6 @@ class Tournament : ModelObject, Storable {
federalCategory = try container . decode ( TournamentCategory . self , forKey : . _federalCategory )
federalLevelCategory = try container . decode ( TournamentLevel . self , forKey : . _federalLevelCategory )
federalAgeCategory = try container . decode ( FederalTournamentAge . self , forKey : . _federalAgeCategory )
groupStageCourtCount = try container . decodeIfPresent ( Int . self , forKey : . _groupStageCourtCount )
closedRegistrationDate = try container . decodeIfPresent ( Date . self , forKey : . _closedRegistrationDate )
groupStageAdditionalQualified = try container . decode ( Int . self , forKey : . _groupStageAdditionalQualified )
courtCount = try container . decode ( Int . self , forKey : . _courtCount )
@ -160,9 +158,7 @@ class Tournament : ModelObject, Storable {
additionalEstimationDuration = try container . decode ( Int . self , forKey : . _additionalEstimationDuration )
isDeleted = try container . decode ( Bool . self , forKey : . _isDeleted )
isCanceled = try Tournament . _decodeCanceled ( container : container )
publishManually = try container . decodeIfPresent ( Bool . self , forKey : . _publishManually ) ? ? false
publishTeams = try container . decodeIfPresent ( Bool . self , forKey : . _publishTeams ) ? ? false
publishWaitingList = try container . decodeIfPresent ( Bool . self , forKey : . _publishWaitingList ) ? ? false
publishSummons = try container . decodeIfPresent ( Bool . self , forKey : . _publishSummons ) ? ? false
publishGroupStages = try container . decodeIfPresent ( Bool . self , forKey : . _publishGroupStages ) ? ? false
publishBrackets = try container . decodeIfPresent ( Bool . self , forKey : . _publishBrackets ) ? ? false
@ -222,7 +218,6 @@ class Tournament : ModelObject, Storable {
try container . encode ( federalCategory , forKey : . _federalCategory )
try container . encode ( federalLevelCategory , forKey : . _federalLevelCategory )
try container . encode ( federalAgeCategory , forKey : . _federalAgeCategory )
try container . encodeIfPresent ( groupStageCourtCount , forKey : . _groupStageCourtCount )
try container . encodeIfPresent ( closedRegistrationDate , forKey : . _closedRegistrationDate )
try container . encode ( groupStageAdditionalQualified , forKey : . _groupStageAdditionalQualified )
try container . encode ( courtCount , forKey : . _courtCount )
@ -234,7 +229,10 @@ class Tournament : ModelObject, Storable {
try container . encode ( additionalEstimationDuration , forKey : . _additionalEstimationDuration )
try container . encode ( isDeleted , forKey : . _isDeleted )
try self . _encodeIsCanceled ( container : & container )
try container . encode ( publishTeams , forKey : . _publishTeams )
try container . encode ( publishSummons , forKey : . _publishSummons )
try container . encode ( publishBrackets , forKey : . _publishBrackets )
try container . encode ( publishGroupStages , forKey : . _publishGroupStages )
}
fileprivate func _encodePayment ( container : inout KeyedEncodingContainer < CodingKeys > ) throws {
@ -295,6 +293,61 @@ class Tournament : ModelObject, Storable {
case canceled
}
func publishedTeamsDate ( ) -> Date {
startDate
}
func areTeamsPublished ( ) -> Bool {
Date ( ) >= startDate || publishTeams
}
func areSummonsPublished ( ) -> Bool {
Date ( ) >= startDate || publishSummons
}
func publishedGroupStagesDate ( ) -> Date ? {
if let first = groupStages ( ) . flatMap ( { $0 . playedMatches ( ) } ) . compactMap ( { $0 . startDate } ) . sorted ( ) . first ? . atNine ( ) {
if first . isEarlierThan ( startDate ) {
return startDate
} else {
return first
}
} else {
return nil
}
}
func areGroupStagesPublished ( ) -> Bool {
if publishGroupStages { return true }
if let publishedGroupStagesDate = publishedGroupStagesDate ( ) {
return Date ( ) >= publishedGroupStagesDate
} else {
return false
}
}
func publishedBracketsDate ( ) -> Date ? {
if let first = rounds ( ) . flatMap ( { $0 . playedMatches ( ) } ) . compactMap ( { $0 . startDate } ) . sorted ( ) . first ? . atNine ( ) {
if first . isEarlierThan ( startDate ) {
return startDate
} else {
return first
}
} else {
return nil
}
}
func areBracketsPublished ( ) -> Bool {
if publishBrackets { return true }
if let publishedBracketsDate = publishedBracketsDate ( ) {
return Date ( ) >= publishedBracketsDate
} else {
return false
}
}
func shareURL ( ) -> URL ? {
return URLs . main . url . appending ( path : " tournament/ \( id ) " )
}
@ -1096,7 +1149,7 @@ class Tournament : ModelObject, Storable {
let matches = ( 0. . < matchCount ) . map { // 0 i s f i n a l m a t c h
let roundIndex = RoundRule . roundIndex ( fromMatchIndex : $0 )
let round = rounds [ roundIndex ]
return Match ( round : round . id , index : $0 , matchFormat : matchFormat )
return Match ( round : round . id , index : $0 , matchFormat : matchFormat , name : Match . setServerTitle ( upperRound : round , matchIndex : RoundRule . matchIndexWithinRound ( fromMatchIndex : $0 ) ) )
}
print ( matches . map {
@ -1579,7 +1632,7 @@ extension Tournament {
}
static func fake ( ) -> Tournament {
return Tournament ( event : " Roland Garros " , name : " Magic P100 " , startDate : Date ( ) , endDate : Date ( ) , creationDate : Date ( ) , isPrivate : false , groupStageFormat : . nineGames , roundFormat : nil , loserRoundFormat : nil , groupStageSortMode : . snake , groupStageCount : 4 , rankSourceDate : nil , dayDuration : 2 , teamCount : 24 , teamSorting : . rank , federalCategory : . men , federalLevelCategory : . p100 , federalAgeCategory : . a45 , groupStageCourtCount : nil , closedRegistrationDate : nil , groupStageAdditionalQualified : 0 , courtCount : 4 , prioritizeClubMembers : false , qualifiedPerGroupStage : 2 , teamsPerGroupStage : 4 , entryFee : nil )
return Tournament ( event : " Roland Garros " , name : " Magic P100 " , startDate : Date ( ) , endDate : Date ( ) , creationDate : Date ( ) , isPrivate : false , groupStageFormat : . nineGames , roundFormat : nil , loserRoundFormat : nil , groupStageSortMode : . snake , groupStageCount : 4 , rankSourceDate : nil , dayDuration : 2 , teamCount : 24 , teamSorting : . rank , federalCategory : . men , federalLevelCategory : . p100 , federalAgeCategory : . a45 , closedRegistrationDate : nil , groupStageAdditionalQualified : 0 , courtCount : 4 , prioritizeClubMembers : false , qualifiedPerGroupStage : 2 , teamsPerGroupStage : 4 , entryFee : nil )
}
}