make(Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); $start = $argv[1] ?? null; $end = $argv[2] ?? null; $rootId = $argv[3] ?? null; $childId = $argv[4] ?? null; if (!$start || !$rootId) { fwrite(STDERR, "Missing args. Example:\n php scripts/debug_homev2_overview.php 2022-01-01 '' 7 19\n"); exit(2); } $end = $end ?: date('Y-m-d', strtotime('+10 year')); $all = CourseType::where('is_chart', 1)->orderBy('sort', 'asc')->get(); $root = $all->firstWhere('id', (int)$rootId); $children = $all->where('overview_parent_id', (int)$rootId)->values(); $includedTypeIds = collect([(string)$rootId])->merge($children->pluck('id')->map(fn($id) => (string)$id))->unique()->values(); echo "range: {$start} .. {$end}\n"; echo "root: {$rootId} " . ($root ? $root->name : '(not found)') . "\n"; echo "children: " . $children->pluck('id')->implode(',') . "\n"; echo "includedTypeIds(strings): " . $includedTypeIds->implode(',') . "\n\n"; $allCoursesForTypes = Course::whereIn('type', $includedTypeIds->map(fn($id) => (int)$id)) ->where('is_chart', 1) ->get(['id', 'type', 'start_date', 'end_date']); $courses = Course::whereIn('type', $includedTypeIds->map(fn($id) => (int)$id)) ->where('is_chart', 1) ->where('start_date', '<=', $end) ->where('end_date', '>=', $start) ->get(['id', 'type', 'start_date', 'end_date']); echo "courses count (filtered overlap): " . $courses->count() . "\n"; echo "courses count (no date filter): " . $allCoursesForTypes->count() . "\n"; if ($allCoursesForTypes->count() !== $courses->count()) { $missing = $allCoursesForTypes->pluck('id')->diff($courses->pluck('id'))->values(); echo "courses missing due to date filter: " . $missing->implode(',') . "\n"; } if ($childId) { $coursesRoot = $courses->where('type', (int)$rootId)->count(); $coursesChild = $courses->where('type', (int)$childId)->count(); echo "courses root({$rootId}) count in range: {$coursesRoot}\n"; echo "courses child({$childId}) count in range: {$coursesChild}\n"; } $allHistoryForTypes = HistoryCourse::whereIn('type', $includedTypeIds)->get(['id', 'type', 'start_time', 'end_time']); $history = HistoryCourse::whereIn('type', $includedTypeIds) ->where('start_time', '<=', $end) ->where('end_time', '>=', $start) ->get(['id', 'type', 'start_time', 'end_time']); echo "history_courses count (filtered overlap): " . $history->count() . "\n"; echo "history_courses count (no date filter): " . $allHistoryForTypes->count() . "\n"; if ($allHistoryForTypes->count() !== $history->count()) { $missing = $allHistoryForTypes->pluck('id')->diff($history->pluck('id'))->values(); echo "history_courses missing due to date filter: " . $missing->implode(',') . "\n"; } if ($childId) { $historyRoot = $history->where('type', (string)$rootId)->count(); $historyChild = $history->where('type', (string)$childId)->count(); echo "history root({$rootId}) count in range: {$historyRoot}\n"; echo "history child({$childId}) count in range: {$historyChild}\n"; } echo "\nDone.\n";