fix: 加速间隔只决定发送频率,心跳仍按平台的一段学时申报

This commit is contained in:
2026-11-17 11:50:59 +08:00
parent 2cb6623ac4
commit 85e52b972c
2 changed files with 22 additions and 9 deletions
+15 -8
View File
@@ -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]:
+7 -1
View File
@@ -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: