fix match ordering

sync3^2
Razmig Sarkissian 1 month ago
parent a796902da5
commit b8407cb5c3
  1. 10
      PadelClubData/Data/Match.swift
  2. 6
      PadelClubData/Data/MatchScheduler.swift

@ -478,7 +478,15 @@ defer {
return (groupStageObject.index + 1) * 100 + groupStageObject.indexOf(index) return (groupStageObject.index + 1) * 100 + groupStageObject.indexOf(index)
} }
guard let roundObject else { return index } guard let roundObject else { return index }
return (300 - (roundObject.theoryCumulativeMatchCount * 10 + roundObject.index * 22)) * 10 + RoundRule.matchIndexWithinRound(fromMatchIndex: index)
// primary: theoryCumulativeMatchCount (final = 1, semis = 3, quarters = 7, ...)
// multiply by a factor big enough to separate match indexes
let primary = roundObject.theoryCumulativeMatchCount * 1_000
// tie-breaker: match position inside the round (0..N-1)
let secondary = RoundRule.matchIndexWithinRound(fromMatchIndex: index)
return primary + secondary
} }
public func previousMatches() -> [Match] { public func previousMatches() -> [Match] {

@ -420,7 +420,7 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable {
rotationIndex += 1 rotationIndex += 1
} }
let timeMatch = TimeMatch(matchID: match.id, rotationIndex: rotationIndex, courtIndex: match.courtIndex ?? 0, startDate: match.startDate!, durationLeft: match.matchFormat.getEstimatedDuration(additionalEstimationDuration), minimumBreakTime: match.matchFormat.breakTime.breakTime) let timeMatch = TimeMatch(matchID: match.id, rotationIndex: rotationIndex, matchRank: match.computedOrder, courtIndex: match.courtIndex ?? 0, startDate: match.startDate!, durationLeft: match.matchFormat.getEstimatedDuration(additionalEstimationDuration), minimumBreakTime: match.matchFormat.breakTime.breakTime)
slots.append(timeMatch) slots.append(timeMatch)
} }
@ -534,7 +534,7 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable {
for i in 0..<rotationIndex { for i in 0..<rotationIndex {
let courtsSorted = slots.filter { $0.rotationIndex == i }.map { $0.courtIndex }.sorted() let courtsSorted = slots.filter { $0.rotationIndex == i }.map { $0.courtIndex }.sorted()
let courts = randomizeCourts ? courtsSorted.shuffled() : courtsSorted let courts = randomizeCourts ? courtsSorted.shuffled() : courtsSorted
var matches = slots.filter { $0.rotationIndex == i }.sorted(using: .keyPath(\.courtIndex)) var matches = slots.filter { $0.rotationIndex == i }.sorted(using: .keyPath(\.matchRank))
for j in 0..<matches.count { for j in 0..<matches.count {
matches[j].courtIndex = courts[j] matches[j].courtIndex = courts[j]
@ -621,6 +621,7 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable {
let timeMatch = TimeMatch( let timeMatch = TimeMatch(
matchID: firstMatch.id, matchID: firstMatch.id,
rotationIndex: rotationIndex, rotationIndex: rotationIndex,
matchRank: firstMatch.computedOrder,
courtIndex: courtIndex, courtIndex: courtIndex,
startDate: rotationStartDate, startDate: rotationStartDate,
durationLeft: firstMatch.matchFormat.getEstimatedDuration(additionalEstimationDuration), durationLeft: firstMatch.matchFormat.getEstimatedDuration(additionalEstimationDuration),
@ -858,6 +859,7 @@ struct GroupStageTimeMatch {
public struct TimeMatch { public struct TimeMatch {
let matchID: String let matchID: String
let rotationIndex: Int let rotationIndex: Int
let matchRank: Int
var courtIndex: Int var courtIndex: Int
var startDate: Date var startDate: Date
var durationLeft: Int //in minutes var durationLeft: Int //in minutes

Loading…
Cancel
Save