reqdiagram.py

clew/wiki/reqdiagram.py

A requirement's evidence as a diagram: implementers → tests → result (round 5, P5.4).

_summary_svg

str clew.wiki.reqdiagram._summary_svg(Any row, list[str] impls, list[tuple[str, str]] tests)

The summary form: each implementer to result buckets with counts.

clew/wiki/reqdiagram.py:86

Source · 49 lines
def _summary_svg(row: Any, impls: list[str], tests: list[tuple[str, str]]) -> str:
    """SAYS IT IS A SUMMARY and where the whole list is, so a reader is never shown a cut-down
    picture as if it were complete. An implementer → bucket edge means at least one test with
    that result reaches it, from the same `extent` the full form draws.

    @brief Summarised evidence.
    @return SVG.
    """
    reached = {test: set(names) for test, names in (row.extent or ())}
    uncovered = set(row.implementers_uncovered or ())
    counts: dict[str, int] = {}
    for _test, status in tests:
        counts[status] = counts.get(status, 0) + 1
    buckets = [f"{n} {s}" for s, n in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))]
    statuses = sorted(counts, key=lambda s: (-counts[s], s))
    widths = [_width(impls), _width(buckets)]
    xs = [0.0, widths[0] + 2 * _GAP]
    rows = max(len(impls), len(buckets), 1)
    height = _PITCH * rows + 2 * _PITCH
    parts = [
        f'<text class="head" x="0" y="12">implemented by</text>'
        f'<text class="head" x="{xs[1]:.0f}" y="12">results ({len(tests)} tests)</text>'
    ]
    for i, name in enumerate(impls):
        cls = "impl uncovered" if name in uncovered else "impl"
        parts.append(_label(xs[0], _PITCH * (i + 1), name, cls))
    for j, (label, status) in enumerate(zip(buckets, statuses, strict=True)):
        parts.append(_label(xs[1], _PITCH * (j + 1), label, f"result r-{status}"))
        for i, name in enumerate(impls):
            if any(s == status and name in reached.get(t, ()) for t, s in tests):
                parts.append(
                    f'<line class="edge" data-edge="{escape(name)}→{escape(status)}" '
                    f'x1="{widths[0] - _PAD + 6:.0f}" y1="{_PITCH * (i + 1)}" '
                    f'x2="{xs[1] - 6:.0f}" y2="{_PITCH * (j + 1)}"/>'
                )
    note = f"{len(tests)} tests, a summary by result: every test is in the tests table below"
    head = f"results ({len(tests)} tests)"
    parts.append(f'<text class="note" x="0" y="{height - 6}">{escape(note)}</text>')
    ## W-9 (owner review 2026-11-22): the width counts the header and the note too — both clipped.
    total = max(xs[1] + max(widths[1], _width([head])) + _PAD, _width([note]) + _PAD, 420)
    summary = f"{len(impls)} implementers, {len(tests)} tests: " + ", ".join(buckets)
    return (
        f'<svg class="req-evidence summary" role="img" aria-label="{escape(summary)}" '
        f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">'
        + "".join(parts)
        + "</svg>"
    )

Activity · 26 steps
lines 94–94reached = {test: set(names) for test, names in (row.extent or ())}lines 95–95uncovered = set(row.implementers_uncovered or ())lines 96–96counts: dict[str, int] = {}lines 97–97◇ for _test, status in testslines 98–98counts[status] = counts.get(status, 0) + 1lines 99–99buckets = [f"{n} {s}" for s, n in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))]lines 100–100statuses = sorted(counts, key=lambda s: (-counts[s], s))lines 101–101widths = [_width(impls), _width(buckets)]lines 102–102xs = [0.0, widths[0] + 2 * _GAP]lines 103–103rows = max(len(impls), len(buckets), 1)lines 104–104height = _PITCH * rows + 2 * _PITCHlines 105–108parts = [ f'<text class="head" x="0" y="12">implemented by</text>' f'<text class="head" x="{xs[1]:.0f}" y="12">results ({len(tests)} tests)</text>' ]lines 109–109◇ for i, name in enumerate(impls)lines 110–110cls = "impl uncovered" if name in uncovered else "impl"lines 111–111parts.append(_label(xs[0], _PITCH * (i + 1), name, cls))lines 112–112◇ for j, (label, status) in enumerate(zip(buckets, statuses, strict=True))lines 113–113parts.append(_label(xs[1], _PITCH * (j + 1), label, f"result r-{status}"))lines 114–114◇ for i, name in enumerate(impls)lines 115–115◇ if any(s == status and name in reached.get(t, ()) for t, s in tests)lines 116–120parts.append( f'<line class="edge" data-edge="{escape(name)}→{escape(status)}" ' f'x1="{widths[0] - _PAD + 6:.0f}" y1="{_PITCH * (i + 1)}" ' f'x2="{xs[1] - 6:.0f}" y2="{_PITCH * (j + 1)}"/>' )lines 121–121note = f"{len(tests)} tests, a summary by result: every test is in the tests table below"lines 122–122head = f"results ({len(tests)} tests)"lines 123–123parts.append(f'<text class="note" x="0" y="{height - 6}">{escape(note)}</text>')lines 125–125total = max(xs[1] + max(widths[1], _width([head])) + _PAD, _width([note]) + _PAD, 420)lines 126–126summary = f"{len(impls)} implementers, {len(tests)} tests: " + ", ".join(buckets)lines 127–132return ( f'<svg class="req-evidence summary" role="img" aria-label="{escape(summary)}" ' f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">' + "".join(parts) + "</svg>" )

Requirements

REQ-DDB-WIKI-022

evidence_svg

str clew.wiki.reqdiagram.evidence_svg(Any row)

The SVG for one requirement's evidence, or "" when it has neither implementer nor test.

clew/wiki/reqdiagram.py:40

Source · 38 lines
def evidence_svg(row: Any) -> str:
    """@brief Draw implementers, tests and results with the measured edges between them.
    @return SVG, or "".
    """
    impls = list(row.implementers)
    tests = list(row.tests)
    if not impls and not tests:
        return ""
    if len(tests) > SUMMARY_TESTS:
        return _summary_svg(row, impls, tests)
    reached = {test: set(names) for test, names in (row.extent or ())}
    uncovered = set(row.implementers_uncovered or ())
    widths = [_width(impls), _width([t for t, _s in tests]), _width([s for _t, s in tests])]
    xs = [0.0, widths[0] + _GAP, widths[0] + widths[1] + 2 * _GAP]
    height = _PITCH * max(len(impls), len(tests), 1) + _PITCH
    parts = [_heads(xs)]
    at = {name: _PITCH * (i + 1) for i, name in enumerate(impls)}
    for name, y in at.items():
        cls = "impl uncovered" if name in uncovered else "impl"
        parts.append(_label(xs[0], y, name, cls))
    for i, (test, status) in enumerate(tests):
        y = _PITCH * (i + 1)
        parts += [_label(xs[1], y, test, "test"), _label(xs[2], y, status, f"result r-{status}")]
        parts += [
            _edge(test, name, xs, widths, y, at[name])
            for name in impls
            if name in reached.get(test, ())
        ]
    total = xs[2] + widths[2] + _PAD
    summary = f"{len(impls)} implementers, {len(tests)} tests, {sum(1 for _t, s in tests if s == 'passed')} passed"
    return (
        f'<svg class="req-evidence" role="img" aria-label="{escape(summary)}" '
        f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">'
        + "".join(parts)
        + "</svg>"
    )

Activity · 23 steps
lines 44–44impls = list(row.implementers)lines 45–45tests = list(row.tests)lines 46–46◇ if not impls and not testslines 47–47return ""lines 48–48◇ if len(tests) > SUMMARY_TESTSlines 49–49return _summary_svg(row, impls, tests)lines 50–50reached = {test: set(names) for test, names in (row.extent or ())}lines 51–51uncovered = set(row.implementers_uncovered or ())lines 52–52widths = [_width(impls), _width([t for t, _s in tests]), _width([s for _t, s in tests])]lines 53–53xs = [0.0, widths[0] + _GAP, widths[0] + widths[1] + 2 * _GAP]lines 54–54height = _PITCH * max(len(impls), len(tests), 1) + _PITCHlines 55–55parts = [_heads(xs)]lines 56–56at = {name: _PITCH * (i + 1) for i, name in enumerate(impls)}lines 57–57◇ for name, y in at.items()lines 58–58cls = "impl uncovered" if name in uncovered else "impl"lines 59–59parts.append(_label(xs[0], y, name, cls))lines 60–60◇ for i, (test, status) in enumerate(tests)lines 61–61y = _PITCH * (i + 1)lines 62–62parts += [_label(xs[1], y, test, "test"), _label(xs[2], y, status, f"result r-{status}")]lines 63–67parts += [ _edge(test, name, xs, widths, y, at[name]) for name in impls if name in reached.get(test, ()) ]lines 68–68total = xs[2] + widths[2] + _PADlines 69–69summary = f"{len(impls)} implementers, {len(tests)} tests, {sum(1 for _t, s in tests if s == 'passed')} passed"lines 70–75return ( f'<svg class="req-evidence" role="img" aria-label="{escape(summary)}" ' f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">' + "".join(parts) + "</svg>" )

Requirements

REQ-DDB-WIKI-022