fix(ad): 服务端强制不足一秒曝光收益为零 (#150)
## 改动 - eCPM 上报新增可选 exposure_ms,兼容旧客户端 - exposure_ms < 1000 时保留展示记录并强制有效 eCPM 为 0 - 失败领券任务允许保留短曝光零收益 trace,后台显示 0 而不是未填充 - 其他失败后的迟到曝光仍按原规则解绑 trace ## 验证 - 相关 pytest:10 passed - Ruff:通过 - compileall:通过 依赖:先合并 Server #149。 --------- Co-authored-by: unknown <798648091@qq.com> Reviewed-on: #150 Co-authored-by: linkeyu <linkeyu@wonderable.ai> Co-committed-by: linkeyu <linkeyu@wonderable.ai>
This commit was merged in pull request #150.
This commit is contained in:
@@ -58,6 +58,32 @@ def test_revenue_yuan_by_trace_empty() -> None:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_short_exposure_keeps_record_with_zero_revenue() -> None:
|
||||
"""不足一秒仍落展示记录,以便后台显示 0 而不是未填充。"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
rec = crud_ecpm.create_ecpm_record(
|
||||
db, 1, ad_type="draw", ecpm_raw="350",
|
||||
ad_session_id="sess-short-exposure", feed_scene="coupon",
|
||||
trace_id="trace-short-exposure", exposure_ms=999,
|
||||
)
|
||||
assert rec.ecpm_raw == "0"
|
||||
assert crud_ecpm.revenue_yuan_by_trace(db, ["trace-short-exposure"]) == {
|
||||
"trace-short-exposure": 0.0
|
||||
}
|
||||
finally:
|
||||
db.execute(delete(AdEcpmRecord).where(
|
||||
AdEcpmRecord.ad_session_id == "sess-short-exposure"
|
||||
))
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
|
||||
def test_one_second_exposure_keeps_original_ecpm() -> None:
|
||||
assert crud_ecpm.effective_ecpm_raw("350", 1000) == "350"
|
||||
assert crud_ecpm.effective_ecpm_raw("350", None) == "350"
|
||||
|
||||
|
||||
def test_terminal_coupon_trace_is_not_attributable_to_late_impression() -> None:
|
||||
"""领券失败或被放弃后才到达的广告展示保留收益记录,但不再关联死亡 trace。"""
|
||||
db = SessionLocal()
|
||||
@@ -80,6 +106,12 @@ def test_terminal_coupon_trace_is_not_attributable_to_late_impression() -> None:
|
||||
assert crud_ecpm.attributable_trace_id(
|
||||
db, feed_scene="coupon", trace_id="abandoned-before-ad"
|
||||
) is None
|
||||
assert crud_ecpm.attributable_trace_id(
|
||||
db, feed_scene="coupon", trace_id="failed-before-ad", exposure_ms=999
|
||||
) == "failed-before-ad"
|
||||
assert crud_ecpm.attributable_trace_id(
|
||||
db, feed_scene="coupon", trace_id="abandoned-before-ad", exposure_ms=999
|
||||
) == "abandoned-before-ad"
|
||||
assert crud_ecpm.attributable_trace_id(
|
||||
db, feed_scene="comparison", trace_id="failed-before-ad"
|
||||
) == "failed-before-ad"
|
||||
|
||||
Reference in New Issue
Block a user