DOC-FULL-004:ActiveTimeTracker V2 #105

Open
opened 2026-06-10 21:18:32 +08:00 by wangdl · 0 comments
Owner

目标

实现 V2 有效学习时长计算器。iOS 每 15 秒调用 Rust heartbeat,Rust 根据 timestamp 计算 activeSecondsDelta。

核心规则

  1. Rust 不自己开 timer。
  2. iOS 控制 tick。
  3. Rust 接收 heartbeat timestampMs。
  4. Rust 根据上次 active timestamp 计算 delta。
  5. delta 必须是本次新增有效学习秒数。
  6. delta 不应是累计值。
  7. App pause / background 时不继续累加。
  8. 超长间隔需要 clamp 或标记 warning,避免一次 heartbeat 产生异常大时长。

建议配置

  • heartbeatIntervalSeconds = 15
  • maxDeltaSeconds = 60
  • idleThresholdSeconds = 60

需要支持

start(timestampMs)
heartbeat(timestampMs)
pause(timestampMs)
resume(timestampMs)
close(timestampMs)

warning 建议

  • heartbeat_gap_too_large
  • timestamp_reversed
  • session_not_active
  • delta_clamped

验收标准

  1. heartbeat 返回 activeSecondsDelta。
  2. delta 是增量,不是累计。
  3. timestamp 倒退时不产生负数。
  4. 超长间隔被 clamp 或 warning。
  5. pause 后 heartbeat 不继续计算有效学习时间。
  6. resume 后重新计算。
  7. close 时返回最后残余 delta。
  8. 有完整单元测试。
## 目标 实现 V2 有效学习时长计算器。iOS 每 15 秒调用 Rust heartbeat,Rust 根据 timestamp 计算 activeSecondsDelta。 ## 核心规则 1. Rust 不自己开 timer。 2. iOS 控制 tick。 3. Rust 接收 heartbeat timestampMs。 4. Rust 根据上次 active timestamp 计算 delta。 5. delta 必须是本次新增有效学习秒数。 6. delta 不应是累计值。 7. App pause / background 时不继续累加。 8. 超长间隔需要 clamp 或标记 warning,避免一次 heartbeat 产生异常大时长。 ## 建议配置 - heartbeatIntervalSeconds = 15 - maxDeltaSeconds = 60 - idleThresholdSeconds = 60 ## 需要支持 ``` start(timestampMs) heartbeat(timestampMs) pause(timestampMs) resume(timestampMs) close(timestampMs) ``` ## warning 建议 - heartbeat_gap_too_large - timestamp_reversed - session_not_active - delta_clamped ## 验收标准 1. heartbeat 返回 activeSecondsDelta。 2. delta 是增量,不是累计。 3. timestamp 倒退时不产生负数。 4. 超长间隔被 clamp 或 warning。 5. pause 后 heartbeat 不继续计算有效学习时间。 6. resume 后重新计算。 7. close 时返回最后残余 delta。 8. 有完整单元测试。
wangdl added this to the M-DOC-FULL:Document Runtime 完整阅读内核与学习事件协议 milestone 2026-06-10 21:18:32 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#105
No description provided.