From f2d2a6c2e770efa66ae9839303fe6dbe05d549f3 Mon Sep 17 00:00:00 2001 From: Mia Wu Date: Thu, 23 Jul 2026 14:57:43 -0400 Subject: [PATCH] fix tc ordering --- backend/app.py | 4 +++- backend/db.py | 12 +++++------- backend/scheduler.py | 15 +++++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/backend/app.py b/backend/app.py index ed5d5c5..dffd470 100644 --- a/backend/app.py +++ b/backend/app.py @@ -387,6 +387,7 @@ def compile_schedule_endpoint(request: CompileScheduleRequest) -> dict[str, Any] except ValueError as exc: raise HTTPException(status_code=400, detail="start_date must be YYYY-MM-DD") from exc + all_tests = db.get_not_excluded_tests(DB_PATH, rule=request.rule) stored_tests = db.list_schedulable_tests(DB_PATH, rule=request.rule) if not stored_tests: version = db.create_schedule_version([], DB_PATH) @@ -437,7 +438,8 @@ def compile_schedule_endpoint(request: CompileScheduleRequest) -> dict[str, Any] top_priority_pairs.add((test_id, REF)) scheduler = Scheduler( - tests=scheduler_tests, + all_tests=all_tests, + schedulable_tests=scheduler_tests, top_priority_tests=top_priority_pairs, start_date=request.start_date, holiday_dates=holiday_dates, diff --git a/backend/db.py b/backend/db.py index 97960f0..83a2d07 100644 --- a/backend/db.py +++ b/backend/db.py @@ -399,8 +399,8 @@ def get_completed_dut_test_ids(db_path: str | Path = DB_PATH) -> set[str]: return {row["test_id"] for row in rows} # Get tests for device that are not excluded regardless of completion status. -def get_not_excluded_tests(device: str, db_path: str | Path = DB_PATH, rules: dict[str, Any] | None = None) -> list[TestRecord]: - tokens = _parse_rule_tokens(rules.get("rule") if rules else "") if rules else [] +def get_not_excluded_tests(db_path: str | Path = DB_PATH, rule: str = "") -> list[TestRecord]: + tokens = _parse_rule_tokens(rule) with get_connection(db_path) as conn: rows = conn.execute( """ @@ -411,12 +411,10 @@ def get_not_excluded_tests(device: str, db_path: str | Path = DB_PATH, rules: di excluded, status, raw_payload FROM tests WHERE excluded = 0 - AND device = ? - """, - (device,) + """ ).fetchall() - - results: list[TestRecord] = [] + + results: list[TestRecord] = [] for row in rows: results.append( TestRecord( diff --git a/backend/scheduler.py b/backend/scheduler.py index f3df0ae..80c391f 100644 --- a/backend/scheduler.py +++ b/backend/scheduler.py @@ -31,7 +31,8 @@ class ScheduleWindow: class Scheduler: def __init__( self, - tests: list[Test], + all_tests: list[Test], + schedulable_tests: list[Test], top_priority_tests: set[tuple[str, str]], start_date: str | None = None, holiday_dates: set[str] = set(), @@ -40,10 +41,11 @@ class Scheduler: dual_device_window_start_dates: set[str] | None = None, priority_weight: int = 1000, ): + self.all_tests = all_tests + self.schedulable_tests = schedulable_tests self.top_priority_tests = top_priority_tests - self.tests = tests - self.active_dut: dict[str, Test] = {test.test_id: test for test in tests if test.device == DUT} - self.active_ref: dict[str, Test] = {test.test_id: test for test in tests if test.device == REF} + self.active_dut: dict[str, Test] = {test.test_id: test for test in schedulable_tests if test.device == DUT} + self.active_ref: dict[str, Test] = {test.test_id: test for test in schedulable_tests if test.device == REF} self.start_date = date.fromisoformat(start_date) if start_date else date.today() self.holiday_dates = holiday_dates self.daytime_testing_today = daytime_testing_today @@ -75,13 +77,14 @@ class Scheduler: window_index = 0 cursor_date = self.start_date - tc_order = self.get_tc_order(self.tests) + tc_order = self.get_tc_order(self.all_tests) for tc in tc_order: tc_bundles = all_bundles_by_tc[tc] if tc_bundles is None or len(tc_bundles) == 0: + print(f"[scheduler] No bundles found for TC: {tc}. Skipping to next TC.") continue - + print(f"[scheduler] Scheduling bundles for TC: {tc} with {len(tc_bundles)} bundles.") window_device = DUT pending_dut: list[TestBundle] = [] pending_ref: list[TestBundle] = []