Fix team-first future window selection

This commit is contained in:
Trey t
2026-04-03 15:31:52 -05:00
parent 0fa3db5401
commit 188076717b
3 changed files with 169 additions and 11 deletions

View File

@@ -59,6 +59,13 @@ final class ScenarioEPlanner: ScenarioPlanner {
/// Maximum number of results to return
private let maxResultsToReturn = 10
/// Current date used to filter out past windows. Injectable for testing.
private let currentDate: Date
init(currentDate: Date = Date()) {
self.currentDate = currentDate
}
// MARK: - ScenarioPlanner Protocol
func plan(request: PlanningRequest) -> ItineraryResult {
@@ -181,7 +188,7 @@ final class ScenarioEPlanner: ScenarioPlanner {
//
var allItineraryOptions: [ItineraryOption] = []
for (windowIndex, window) in windowsToEvaluate.enumerated() {
for window in windowsToEvaluate {
// Collect games in this window
var gamesByTeamInWindow: [String: [Game]] = [:]
var hasAllTeamsInWindow = true
@@ -296,13 +303,10 @@ final class ScenarioEPlanner: ScenarioPlanner {
allItineraryOptions.append(option)
}
// Early exit if we have enough options
if allItineraryOptions.count >= maxResultsToReturn * 5 {
#if DEBUG
print("🔍 ScenarioE: Early exit at window \(windowIndex + 1) with \(allItineraryOptions.count) options")
#endif
break
}
// No early exit evaluate all sampled windows so results
// span the full season instead of clustering around early dates.
// The 50-window sample cap + final dedup + top-10 ranking are
// sufficient throttles (beam search on ~10 games/window is fast).
}
//
@@ -384,9 +388,12 @@ final class ScenarioEPlanner: ScenarioPlanner {
let earliestDay = calendar.startOfDay(for: earliest)
let latestDay = calendar.startOfDay(for: latest)
// Skip past windows users only want future trips
let today = calendar.startOfDay(for: currentDate)
// Generate sliding windows
var validWindows: [DateInterval] = []
var currentStart = earliestDay
var currentStart = max(earliestDay, today)
while let windowEnd = calendar.date(byAdding: .day, value: windowDurationDays, to: currentStart),
windowEnd <= calendar.date(byAdding: .day, value: 1, to: latestDay)! {