Files
2026-11-27 14:43:37 +08:00

72 lines
4.5 KiB
Python

"""Schedule facts, distinct from semantic coverage and from delivery predictions."""
def assess_schedule(payload, workflow, alignment, *, goal_mode=False):
tasks = {t.id: t for t in payload.siblings}
if not goal_mode:
tasks[payload.task.id] = payload.task
today, parent = payload.as_of, payload.parent
rows = list(tasks.values())
completed = [t for t in rows if t.status == "1"]
pending = [t for t in rows if t.status != "1"]
overdue = [t for t in pending if t.end and t.end < today]
beyond = [t for t in pending if t.end and parent.end and t.end > parent.end]
unplanned = [t for t in pending if not t.start or not t.end]
risks = []
def risk(title, detail, ids=()):
risks.append({"title": title, "detail": detail, "task_ids": list(ids)})
if alignment and alignment["status"] == "unrelated":
risk("当前子任务不能支撑上级目标", "当前任务描述与上级目标的业务方向不符,完成它也不能据此认定上级目标取得相应进展。", [payload.task.id])
gaps = [s for s in workflow if s["coverage"] != "covered"]
if gaps:
explicit = [s["name"] for s in gaps if s["basis"] == "explicit"]
if explicit:
risk("目标要求尚未完整安排", "当前可见分解尚未完整体现:" + "、".join(explicit) + "。需补充分工和排期后再评估完成时间。")
risks[-1]["code"] = "planning_coverage"
if overdue:
risk("有子任务超过计划结束日且未登记完成", f"截至 {today},当前可见分解中有 {len(overdue)} 项超过计划结束日,需核对剩余工作和最新排期。", [t.id for t in overdue])
if beyond:
risk("子任务排期超过目标期限", f"有 {len(beyond)} 项未完成任务计划结束日晚于上级期限 {parent.end}。", [t.id for t in beyond])
if parent.end and parent.end < today and parent.status != "1":
risk("上级目标已超过计划期限", f"上级计划结束日为 {parent.end},截至 {today} 尚未登记完成。")
if parent.status == "1" and pending:
risk("上下级完成记录不一致", "上级已登记完成,但当前分解中仍有未登记完成的任务,需要核对。", [t.id for t in pending])
needs = []
if not parent.end:
needs.append("明确上级目标完成日期。")
if unplanned:
needs.append(f"补齐 {len(unplanned)} 项未完成任务的起止安排。")
if pending:
needs.extend(["明确剩余工作量和负责人可投入时间。", "确认关键任务的前后依赖及外部阻塞。"])
if any(t.progress is None for t in pending):
needs.append("补充未登记的任务当前进度。")
if payload.limitations:
needs.append("补齐本次未读取的目标或同级任务依据,才能评估整体安排。")
if not alignment and not goal_mode:
needs.append("完成目标关联和流程覆盖分析。")
if goal_mode and not rows:
needs.append("把目标拆成具体任务,再安排负责人和完成时间。")
# Completion here is only a registration fact, never independent acceptance.
registered_complete = (not pending and parent.status == "1" and not risks
and not needs and (goal_mode or (alignment and alignment["status"] == "related")))
status = "risk" if risks else "recorded_complete" if registered_complete else "insufficient"
summary = ("现有分解存在影响目标完成的风险,当前不能据此确认能按期完成。" if risks else
"上下级任务均已登记完成;这里反映登记状态,是否达到交付要求仍以实际成果为准。" if registered_complete else
"现有记录未显示明确的排期冲突,但还不足以确认能够按期完成。")
return {
"status": status, "summary": summary, "as_of": str(today),
"goal_deadline": str(parent.end) if parent.end else None,
"remaining_calendar_days": (parent.end - today).days if parent.end else None,
"goal_progress": parent.progress, "task_count": len(rows),
"completed_count": len(completed), "overdue_count": len(overdue),
"risks": risks, "needs": needs,
"tasks": [{"id": t.id, "name": t.name, "progress": t.progress,
"status": {"0": "进行中", "1": "已完成", "2": "待审核"}.get(t.status, "状态未明确"),
"start": str(t.start) if t.start else None,
"end": str(t.end) if t.end else None} for t in rows],
}