"""Measure small task fixtures and compare two independent planning intervals."""
from dataclasses import dataclass
from statistics import mean
from lab_tools import run_exercise
@dataclass(frozen=True)
class Task:
title: str
input: str
baseline: object
changed: object
expected: object
def measured_tasks():
document={"counter":"North","hour":"09:00","limit":3}
inventory=[3,2,1]
kilos=1.25
raw_plan=["read","send"]
staged=["read","review","send"]
initial={"limit":3}
merged={**initial,"hours":"09:00"}
proposed=(3,0)
bounded=(min(proposed[0],2),proposed[1])
return [
Task("语言与资料","从固定记录读出柜台名称",document["counter"],document["counter"],"North"),
Task("数理检查","相加三条库存",sum(inventory),sum(inventory),6),
Task("跨任务迁移","输入 1.25 千克,输出克",kilos,round(kilos*1000),1250),
Task("长期规划","写入前需要有审核步骤",raw_plan,staged,staged),
Task("持续更新","新增营业时间,旧限制仍在",{"hours":"09:00"},merged,{"limit":3,"hours":"09:00"}),
Task("仿真动作","提出坐标 (3,0),活动区最大 x=2",list(proposed),list(bounded),[2,0]),
]
def report(tasks):
return [{"axis":row.title,"input":row.input,"baseline":row.baseline,
"changed":row.changed,"expected":row.expected,
"baseline_pass":int(row.baseline==row.expected),"changed_pass":int(row.changed==row.expected)} for row in tasks]
def intervals(project, generous):
phases=[("样本准备",1,2),("独立验证",2,4),("人工复核",1,3)]
start=project
result=[]
for label,low,high in phases:
if generous and label=="独立验证":
high+=2
result.append(dict(label=label,start=start,end=start+high,low=low,high=high))
start+=high
return result
def exercise(checks,_):
expect=checks.expect
tasks=measured_tasks()
rows=report(tasks)
expect("agi_task_baseline",[x.input for x in tasks],"Run six separate task fixtures against declared outcomes",
[1,1,0,0,0,0],[row["baseline_pass"] for row in rows])
expect("agi_task_controls",[x.input for x in tasks],"Apply explicit conversion, review, state merge and bounds",
["North",6,1250,["read","review","send"],{"limit":3,"hours":"09:00"},[2,0]],
[row["changed"] for row in rows])
expect("agi_scope_average","six binary fixtures","Compare actual aggregate and per-task failures",
[1/3,1,4],[mean(x["baseline_pass"] for x in rows),
mean(x["changed_pass"] for x in rows),sum(not x["baseline_pass"] for x in rows)])
expect("agi_task_report", "six independently evaluated axes", "Record actual input, result and expected values per axis",
rows, report(measured_tasks()))
standard=intervals(1,False); expanded=intervals(1,True)
expect("agi_intervals_standard",False,"Calculate end days from three explicit phase allowances",
[(1,3),(3,7),(7,10)],[(x["start"],x["end"]) for x in standard])
expect("agi_intervals_extended",True,"Add two validation days and propagate to the next phase",
[(1,3),(3,9),(9,12)],[(x["start"],x["end"]) for x in expanded])
expect("agi_interval_records",[False,True],"Return ordered synthetic project intervals with durations",
[standard,expanded],[intervals(1,value) for value in [False,True]])
if __name__=="__main__":
run_exercise(exercise)
本例需在 Python 3.12.14,固定任务与虚构日程,现代浏览器。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Python 3.12.14,固定任务与虚构日程,现代浏览器。
入口文件:projects/ai-agi/agi_scope.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
agi_scope.py,或下载右侧课程工程包。 - 确认本地已准备 Python 3.12.14,固定任务与虚构日程,现代浏览器。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联30章) · 含当前章节或实例 · mbskycom202612a5.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3.zip