这条 ADR 完整吗

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

按 ADR 模型,一条 ADR 五段都填了,complete 交回什么?

贯穿本节的 ADR 模型:五段 SECTIONS=[标题, 状态, 背景, 决策, 后果],状态 STATUS=[提议, 接受, 废弃]。complete=五段都非空、missing=缺哪几段、next_status 沿 提议→接受→废弃 推一格;superseded_by(adrs, 名) 谁取代了它、accepted_count 有几个已接受、valid_transition(a,b) 状态流转合不合法。

SECTIONS = ["标题", "状态", "背景", "决策", "后果"]
STATUS = ["提议", "接受", "废弃"]


def complete(adr):
    # 五段都填了(非空)才算完整
    return all(adr.get(s) for s in SECTIONS)


def missing(adr):
    # 缺哪几段(按 SECTIONS 顺序)
    return [s for s in SECTIONS if not adr.get(s)]


def next_status(s):
    # 提议 -> 接受 -> 废弃;到头停在废弃
    i = STATUS.index(s)
    return STATUS[min(i + 1, len(STATUS) - 1)]


def superseded_by(adrs, name):
    # adrs: {ADR名: 它取代了谁};交回取代了 name 的那个 ADR(没有交回 "")
    for k, replaced in adrs.items():
        if replaced == name:
            return k
    return ""


def accepted_count(statuses):
    return sum(1 for s in statuses if s == "接受")


def valid_transition(a, b):
    # 只允许沿 提议->接受->废弃 往前一格
    ia, ib = STATUS.index(a), STATUS.index(b)
    return ib == ia + 1

adr = {"标题": "用消息队列", "状态": "接受", "背景": "b", "决策": "d", "后果": "c"}
print(complete(adr))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论