fix: φ_grad 将未评分提交按 0 分计入,导致进步梯度方向反转 - #58
Merged
XiaoCow666 merged 1 commit intoSep 19, 2026
Merged
Conversation
XiaoCow666
approved these changes
Sep 19, 2026
XiaoCow666
left a comment
Owner
There was a problem hiding this comment.
CodeSense 自动评审
φ_grad 现在仅以已评分提交计算两半均值,并在任一半无可评分数据时保持中性值,修复了 None 被等价按 0 分计入而可能反转梯度方向的问题。改动覆盖了真实 0 分、缺失评分和正常路径,未发现阻塞性问题。
已有验证信息
- PR 描述提供的定向测试证据:
pytest tests/test_maturity_phi_grad.py -q在修复后为 8 passed。 - PR 描述提供的全量测试证据:
pytest tests -q摘要为 777 passed、0 failed;描述同时说明命令末尾存在沙箱写入限制报错。
评审事件:online-review:#58:b557c0bacd0477eeb122f963fad9c3c8afb7f4bc:2982967
linxi123-A
force-pushed
the
fix/maturity-phi-grad-unscored
branch
from
September 19, 2026 01:42
b557c0b to
9cf5f7a
Compare
XiaoCow666
approved these changes
Sep 19, 2026
XiaoCow666
left a comment
Owner
There was a problem hiding this comment.
CodeSense 自动评审
修复将未评分提交从梯度均值的分子和分母中一致排除,并在任一半缺少已评分提交时保持中性值,符合 PR 的核心目标。0 分仍作为有效分数参与计算,新增测试覆盖了主要回归与边界场景。
已有验证信息
- PR 描述报告:修复后执行
pytest tests/test_maturity_phi_grad.py -q得到 8 passed。 - PR 描述报告:执行
pytest tests -q得到 777 passed、0 failed;其中提到退出末尾存在沙箱写入限制报错。 - 新增测试覆盖:前后半段分别存在未评分提交、全部未评分、单侧无评分、少于 4 条提交及有效 0 分。
评审事件:61c7e7e0-b3cb-11f1-9630-d2dbe7284f92
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
成熟度分量 φ_grad(进步梯度)把提交序列按时间切前后两半,比较两半平均分。
Submission.score统一为百分制 0–100 且可空(models.py:score = db.Column(db.Integer),无 default),"已提交但尚未评分"的提交score=None是真实数据状态;成熟度历史公式按 0–5 制计算,公式内部用normalize_mixed_score(score)/20换算。当前实现把 None 过滤出分子,却除以整半长度(分母),等价于把未评分提交当 0 分。两半缺失率不同时,梯度不仅数值错,连方向都会反。注:提交 3c58c32 已把过滤条件从 truthy 改为
is not None并加了 /20 换算,但分母仍是整半长度,本缺陷依然存在。复现输入
按时间升序的 4 条提交分数(None = 未评分,百分制;公式内 /20 换算为 0–5):
[40, 40, None, 43][None, 43, 40, 40][None, None, 80, 80]根因
分子与分母口径不一致:分子只累加已评分提交,分母用整半提交数。两半未评分率不同 → 均值稀释程度不同 → 成长斜率方向反转。
改动
utils/maturity_calculator.py:calculate_maturity_components的 φ_grad 段——前后两半分别只收集score is not None的提交(保留/20的 0–5 换算),分子分母基于同一批已评分提交;任一半没有可评分提交时没有可比较均值,保持中性默认 50(同时消除空序列除零)。tests/test_maturity_phi_grad.py:新增 8 个测试,轻量内存假对象,仅标准库+pytest,不 import Flask、不连数据库/Redis、不访问网络。验证(实际结果)
基于最新 main(2f1c987):
pytest tests/test_maturity_phi_grad.py -q→ 3 failed, 5 passed(实测 40.75 / 59.25 / 90.0)pytest tests -q→ 808 passed, 0 failed(14 分钟;退出码末尾有沙箱拦截 D 盘 pycache 写入的报错,pytest 摘要行为 808 passed)边界覆盖:全部未评分、仅一半有评分、少于 4 条提交均保持中性 50;正常路径
[40,40,80,80]→ 70;真实 0 分([0,80,80,80])按 0 参与计算 → 70,不会被当成缺失丢弃。AI 辅助说明
AI 仅用于检索调用链与解释。采纳:"同一序列内过滤 + 计数"(分子分母同口径)与"空序列守卫";拒绝:"用 0 填充 None"(0 是真实分数值,填充会再次混淆两种语义)。
未验证范围
回退
单提交、改动集中在一个函数段,revert 该提交即可。