Answer stability, product-owner and architecture round 3: resolve every place in order and count the dropped ones once, let a full path win, name unparsed files and unscored runs below the table, show chance and constant metrics, leave sweeps of more than 30 files out of change spread, count tuple and loop writes and self recursion, and say what a missing history or folder means

This commit is contained in:
2026-10-08 23:04:12 +02:00
parent 1fca6137c2
commit 527aef3495
6 changed files with 135 additions and 65 deletions
+12 -5
View File
@@ -14,10 +14,15 @@ METRICS: dict[str, Callable[[Unit, dict[str, int]], int]] = {
}
# Code Maat's default --max-changeset-size: a sweep across the tree couples every file to every other.
LARGEST_CHANGESET = 30
@dataclasses.dataclass(frozen=True)
class Score:
auc: float
top_k: float
constant: bool
@dataclasses.dataclass(frozen=True)
@@ -29,10 +34,12 @@ class RunScores:
def co_changed(log: str) -> dict[str, int]:
"""For each file, how many other files changed in a commit with it; log is `git log --format=format:@@ --name-only`."""
"""For each file, how many other files changed in a commit with it, commits of more than LARGEST_CHANGESET files left out; log is `git log --format=format:@@ --name-only`."""
partners: dict[str, set[str]] = collections.defaultdict(set)
for commit in log.split("@@"):
files = set(commit.split())
for commit in log.split("@@\n"):
files = set(filter(None, commit.split("\n")))
if len(files) > LARGEST_CHANGESET:
continue
for path in files:
partners[path] |= files - {path}
return {path: len(others) for path, others in partners.items()}
@@ -51,7 +58,7 @@ def bench(units: list[Unit], places: list[Place], unresolved: int, spread: dict[
for metric, value in METRICS.items():
named_values = [value(unit, spread) for unit in named]
rest_values = [value(unit, spread) for unit in rest]
scores[metric] = Score(auc(named_values, rest_values), top_k(named_values, rest_values))
scores[metric] = Score(auc(named_values, rest_values), top_k(named_values, rest_values), len(set(named_values + rest_values)) == 1)
return RunScores(len(units), len(named), unmeasured, scores)
@@ -73,4 +80,4 @@ def top_k(named: list[int], rest: list[int]) -> float:
def medians(runs: list[RunScores]) -> dict[str, Score]:
return {metric: Score(statistics.median(run.scores[metric].auc for run in runs), statistics.median(run.scores[metric].top_k for run in runs)) for metric in METRICS}
return {metric: Score(statistics.median(run.scores[metric].auc for run in runs), statistics.median(run.scores[metric].top_k for run in runs), all(run.scores[metric].constant for run in runs)) for metric in METRICS}