mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-18 04:51:59 +00:00
分析设置要求「集中」的合计占比不小于「主要来源」的占比(复核 R16):contract.settings_problem 加一条(没写的项按缺省补齐了比),说法用 LABELS 的叫法:「「集中」的合计占比不能小于「主要来源」的占比」——原来「主要来源」0.9 配「集中」0.5 能通过,一段占 60% 时判分散、判定语却说「没有哪一段占到 90%」。设置页写进来的、分析卡上的覆盖都按它挡;api/settings.analysis_values 读存着的一组时这一对对不上同样两项都按缺省(同另外两对)
This commit is contained in:
@@ -167,7 +167,8 @@ LABELS: dict[str, str] = {
|
||||
|
||||
def settings_problem(values: Mapping[str, Any]) -> str | None:
|
||||
"""一组分析设置(或分析卡上的覆盖)哪里不对:不认识的键、类型不对、超出范围、k_alert 不大于 k_warn、
|
||||
max_history 小于 min_history。都对返回 None。说法给人看。"""
|
||||
max_history 小于 min_history、concentration 小于 main_share(一段占了「主要」那么多还够不上「集中」,判定语会说「没有哪一段
|
||||
占到」一个比它小的数)。没写的项按缺省补齐了比。都对返回 None。说法给人看(键的叫法取 LABELS)。"""
|
||||
for key, value in values.items():
|
||||
if key not in RANGES:
|
||||
return f"不认识的分析设置:{key}"
|
||||
@@ -184,6 +185,8 @@ def settings_problem(values: Mapping[str, Any]) -> str | None:
|
||||
return f"{LABELS['k_alert']}要大于{LABELS['k_warn']}"
|
||||
if merged["max_history"] < merged["min_history"]:
|
||||
return f"{LABELS['max_history']}不能小于{LABELS['min_history']}"
|
||||
if merged["concentration"] < merged["main_share"]:
|
||||
return f"{LABELS['concentration']}不能小于{LABELS['main_share']}"
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -907,13 +907,14 @@ def _analysis_item_ok(key: str, value: Any) -> bool:
|
||||
|
||||
def analysis_values(stored: Any) -> dict[str, Any]:
|
||||
"""库里存的(或刚写进来的)analysis 一组 → 补齐缺省;存坏了的项按缺省。两两之间的大小对不上的(「明显超出」不大于
|
||||
「超出常规波动」、最多用几期历史小于至少几期)那一对都按缺省:只换掉一项,可能换出另一种对不上。"""
|
||||
「超出常规波动」、最多用几期历史小于至少几期、「集中」的合计占比小于「主要来源」的占比)那一对都按缺省:只换掉一项,可能
|
||||
换出另一种对不上。"""
|
||||
stored = stored if isinstance(stored, dict) else {}
|
||||
out = dict(analysis_contract.DEFAULTS)
|
||||
for key in analysis_contract.DEFAULTS:
|
||||
if key in stored and _analysis_item_ok(key, stored[key]):
|
||||
out[key] = float(stored[key]) if analysis_contract.RANGES[key][0] is float else stored[key]
|
||||
for pair in (("k_warn", "k_alert"), ("min_history", "max_history")):
|
||||
for pair in (("k_warn", "k_alert"), ("min_history", "max_history"), ("main_share", "concentration")):
|
||||
if analysis_contract.settings_problem({k: out[k] for k in pair}) is not None:
|
||||
out.update({k: analysis_contract.DEFAULTS[k] for k in pair})
|
||||
return out
|
||||
|
||||
@@ -19,6 +19,10 @@ def test_settings_problems_are_spoken_with_labels_not_keys():
|
||||
assert c.settings_problem({"main_share": True}) == "「主要来源」的占比要填数字"
|
||||
assert c.settings_problem({"main_share": 0.95}) == "「主要来源」的占比要在 0.3 到 0.9 之间"
|
||||
assert c.settings_problem({"max_history": 8, "min_history": 9}) == "最多用几期历史不能小于至少几期历史"
|
||||
# 「主要」要的占比比「集中」的合计还高:一段占 60% 会判成分散,判定语却说「没有哪一段占到 90%」
|
||||
assert c.settings_problem({"main_share": 0.9, "concentration": 0.5}) == "「集中」的合计占比不能小于「主要来源」的占比"
|
||||
assert c.settings_problem({"main_share": 0.85}) == "「集中」的合计占比不能小于「主要来源」的占比" # 缺省的 0.8 补齐了比
|
||||
assert c.settings_problem({"main_share": 0.8}) is None and c.settings_problem({"concentration": 0.5}) is None
|
||||
assert c.settings_problem({"nope": 1}) == "不认识的分析设置:nope"
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ def test_the_group_is_the_contract():
|
||||
broken = {"main_share": "一半", "max_calls": 3.5, "k_warn": 4, "k_alert": 3.5, "min_history": 20, "max_history": 10,
|
||||
"table_top_k": 5, "trend_alpha": True}
|
||||
assert analysis_values(broken) == {**contract.DEFAULTS, "table_top_k": 5}
|
||||
assert analysis_values({"main_share": 0.9, "concentration": 0.5}) == contract.DEFAULTS
|
||||
# 浮点的项存成浮点:发起时的快照、结论里记的阈值一个写法
|
||||
assert analysis_values({"k_warn": 3, "k_alert": 4})["k_warn"] == 3.0
|
||||
assert isinstance(analysis_values({"k_warn": 3, "k_alert": 4})["k_alert"], float)
|
||||
@@ -81,6 +82,8 @@ def test_the_group_is_the_contract():
|
||||
({"max_calls": 2.5}, f"{contract.LABELS['max_calls']}要填整数"),
|
||||
({"k_warn": 3.5}, f"{contract.LABELS['k_alert']}要大于{contract.LABELS['k_warn']}"),
|
||||
({"min_history": 60}, f"{contract.LABELS['max_history']}不能小于{contract.LABELS['min_history']}"),
|
||||
({"main_share": 0.9, "concentration": 0.5},
|
||||
f"{contract.LABELS['concentration']}不能小于{contract.LABELS['main_share']}"),
|
||||
])
|
||||
def test_problems_are_said_with_labels(value, why):
|
||||
assert why in (analysis_problem(value) or "")
|
||||
|
||||
Reference in New Issue
Block a user