diff --git a/backend/euniv/autostudy.py b/backend/euniv/autostudy.py index 9e45f26..472ff90 100644 --- a/backend/euniv/autostudy.py +++ b/backend/euniv/autostudy.py @@ -269,21 +269,28 @@ def _completed(payload: dict) -> bool: return str(payload.get("status") or "").strip().lower() == "completed" -def _payload_time(wait: int, fallback: int) -> int: - if wait > 0: - return int(wait) - return max(1, int(fallback or 1)) +def _declared_study_time(ctype: str, params: dict | None) -> int: + """平台入账只认播放页上的一段时长。手动间隔只决定隔多久发一次,不改这一段报多少秒。""" + video = ctype == "video" + raw = (params or {}).get("submitProTimes" if video else "validtimeSpan") + try: + value = int(raw or 0) + except (TypeError, ValueError): + value = 0 + if value <= 0: + value = 30 if video else 120 + return value def _interval_plan(ctype: str, intervals: dict, auto_mode: bool, params: dict) -> tuple[int, int, int]: - """返回 (等待秒, 心跳 studyTime, pageSize)。等待 0 表示连续发送,studyTime 仍用播放页间隔。""" + """返回 (等待秒, 心跳 studyTime, pageSize)。studyTime 始终是播放页的 30 或 120。""" video = ctype == "video" wait = int(intervals.get(ctype, 30 if video else 120) or 0) - fallback = int((params or {}).get("submitProTimes" if video else "validtimeSpan") or (30 if video else 120)) + declared = _declared_study_time(ctype, params) if auto_mode: - wait = max(1, fallback) + wait = max(1, declared) page_size = max(1, int((params or {}).get("pageSize") or 1)) - return wait, _payload_time(wait, fallback), page_size + return wait, declared, page_size def _current_intervals() -> tuple[dict, bool]: diff --git a/backend/tests/test_autostudy.py b/backend/tests/test_autostudy.py index 2c6b164..6adb5ce 100644 --- a/backend/tests/test_autostudy.py +++ b/backend/tests/test_autostudy.py @@ -539,8 +539,14 @@ def test_interval_plan_manual_one_second_uses_admin_wait() -> None: "video", {"video": 1, "document": 1, "scorm": 1}, False, {"submitProTimes": 30, "pageSize": 1}, ) assert wait == 1 - assert step == 1 + assert step == 30 assert page == 1 + wait, step, page = _interval_plan( + "document", {"document": 1}, False, {"validtimeSpan": 120, "pageSize": 12}, + ) + assert wait == 1 + assert step == 120 + assert page == 12 def test_wanted_account_without_credential_is_dropped() -> None: