Show the size of the code each finished item names beside its S in score-outcomes
This commit is contained in:
@@ -6,15 +6,24 @@ from branch_chunks.cut import BranchChunk, Landing, NOT_WORK
|
||||
from review_rules.round_titles import Findings, round_findings, rounds_past_first
|
||||
from release_plan.todo_table import Item
|
||||
from records.markdown_text import listed
|
||||
from release_plan.named_code import named_files
|
||||
|
||||
# Fewest single-item chunks a score needs before its medians print: the 10 figures the reading-cost trend waits for; no published standard sets either.
|
||||
ENOUGH = 10
|
||||
|
||||
|
||||
# An item's size in lines, not an S: no published scale maps lines to S, and the report's S medians already set the S guessed beside the lines changed.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class NamedCode:
|
||||
"""The tracked files an item's tagline and detail name, folders by the files they hold, as the chunk that shipped it found them: how many, and their lines, a binary file holding none. They bound what the chunk's change could touch."""
|
||||
files: int
|
||||
lines: int
|
||||
|
||||
|
||||
# The tool's name and report call a Result an outcome, a word the code keeps for an entry of a `.outcomes.md` file: docs/decisions.md → `bin/: an outcome is an entry`.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Result:
|
||||
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, and how many of them a reviewer marked `[misread]`, None where a round title lacks the 🔴 and 🟡 counts or the branch has no round; its misread is None where a round title lacks that count. landing says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed. fixed_by names the later chunks that fixed code it shipped, newest first, as branch_chunks counts them."""
|
||||
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, and how many of them a reviewer marked `[misread]`, None where a round title lacks the 🔴 and 🟡 counts or the branch has no round; its misread is None where a round title lacks that count. landing says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed. fixed_by names the later chunks that fixed code it shipped, newest first, as branch_chunks counts them. named is None where the item names no tracked file."""
|
||||
item: Item
|
||||
merge: str
|
||||
merged: str
|
||||
@@ -25,6 +34,9 @@ class Result:
|
||||
findings: Findings | None
|
||||
landing: Landing
|
||||
fixed_by: tuple[str, ...]
|
||||
named: NamedCode | None
|
||||
|
||||
|
||||
|
||||
|
||||
# A measure's name and how to read it from a Result, None where the chunk did not record it.
|
||||
@@ -37,8 +49,8 @@ ORDERED = ("L", "E", "I")
|
||||
SHOWN = ("L", "E", "I", "R", "S", "C")
|
||||
|
||||
|
||||
def results_of(chunk: BranchChunk, numstat: str) -> list[Result]:
|
||||
"""What one chunk measured for each item it shipped, from `git diff --numstat` of its change; none where it changed nothing but the plan and the records."""
|
||||
def results_of(chunk: BranchChunk, numstat: str, details: dict[int, str], tree: dict[str, int]) -> list[Result]:
|
||||
"""What one chunk measured for each item it shipped, from `git diff --numstat` of its change; none where it changed nothing but the plan and the records. details holds each item's detail in the todo.md the chunk started from, and tree each file's lines before the chunk, as file_lines reads them."""
|
||||
changed = [row.split("\t", 2) for row in numstat.splitlines()]
|
||||
work = [row for row in changed if len(row) == 3 and row[2] not in NOT_WORK]
|
||||
if not work:
|
||||
@@ -47,7 +59,23 @@ def results_of(chunk: BranchChunk, numstat: str) -> list[Result]:
|
||||
lines = sum(int(count) for row in work for count in row[:2] if count.isdigit())
|
||||
titles = list(chunk.titles)
|
||||
ids = [item.id for item in chunk.shipped]
|
||||
return [Result(item, chunk.label, chunk.merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), rounds_past_first(titles), round_findings(titles), chunk.landing, chunk.fixed_by) for item in chunk.shipped]
|
||||
return [Result(item, chunk.label, chunk.merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), rounds_past_first(titles), round_findings(titles), chunk.landing, chunk.fixed_by, named_code(item_text(item, details), tree)) for item in chunk.shipped]
|
||||
|
||||
|
||||
def item_text(item: Item, details: dict[int, str]) -> str:
|
||||
"""The tagline and detail, where the item names the files it changes."""
|
||||
return f"{item.tagline}\n{details.get(item.id, '')}"
|
||||
|
||||
|
||||
def file_lines(numstat: str) -> dict[str, int]:
|
||||
"""Each file's lines from `git diff --numstat` against the empty tree, which counts every line as added; git counts a binary file's lines as "-", so it holds none."""
|
||||
rows = [row.split("\t", 2) for row in numstat.splitlines()]
|
||||
return {row[2]: int(row[0]) if row[0].isdigit() else 0 for row in rows if len(row) == 3}
|
||||
|
||||
|
||||
def named_code(text: str, tree: dict[str, int]) -> NamedCode | None:
|
||||
files = named_files(text, list(tree))
|
||||
return NamedCode(len(files), sum(tree[path] for path in files)) if files else None
|
||||
|
||||
|
||||
def nearest(results: list[Result], given: dict[str, int], count: int = 5) -> list[Result]:
|
||||
@@ -126,6 +154,8 @@ def ranks(values: list[int]) -> list[float]:
|
||||
|
||||
def render(result: Result) -> str:
|
||||
scores = ", ".join(f"{name} {result.item.scores[name]}" for name in SHOWN if name in result.item.scores)
|
||||
if result.named:
|
||||
scores += f", naming code of {plural(result.named.lines, 'line')} in {plural(result.named.files, 'file')}"
|
||||
merged = {"merge": f"merged {result.merged} in {result.merge}", "rebase": f"merged {result.merged} by rebase in {result.merge}", "push": f"committed {result.merged} in {result.merge}, never replayed, so perhaps part of a pull request"}[result.landing]
|
||||
others = result.shipped_with
|
||||
together = f", with item{'s' if len(others) > 1 else ''} {', '.join(map(str, others))}" if others else ""
|
||||
|
||||
Reference in New Issue
Block a user