floor_subset.py¶
scripts/floor_subset.py
Select the noise-floor subset reproducibly, and say what the selection excludes.
build
int floor_subset.build(Path run, Path dest, int per_target)
Copy a deterministic subset into a clean directory for an independent pass.
Source · 32 lines
def build(run: Path, dest: Path, per_target: int) -> int:
"""SORTED BY DISTANCE FROM 50% AND THEN BY STEM, so ties break deterministically and two
people running this on one run directory select the same cells.
@brief Build the floor subset.
@return Cell count.
@version 1
"""
if dest.exists():
shutil.rmtree(dest)
total = 0
for target in sorted(p.name for p in run.iterdir() if (p / "answers").is_dir()):
cands = eligible(run / target / "answers")
chosen = sorted(cands[:per_target], key=lambda c: c[1])
out = dest / target / "answers"
out.mkdir(parents=True)
for _, stem, score in chosen:
shutil.copy(run / target / "answers" / f"{stem}.md", out / f"{stem}.md")
print(f"{target:10} {stem:44} {score:5.1f}%")
total += 1
## WHAT THE BAND EXCLUDED, reported rather than left implicit: the floor is quoted as a
## run-wide figure and it is not one.
allc = [
json.loads(f.read_text())["score"] * 100
for f in (run / target / "answers").glob("*.grade.json")
]
lo = sum(1 for s in allc if s < LOW)
hi = sum(1 for s in allc if s > HIGH)
print(f"{target:10} excluded {lo} cell(s) below {LOW:.0f}% and {hi} above {HIGH:.0f}%")
return total
Activity · 17 steps
Flows
eligible
list[tuple[float, str, float]] floor_subset.eligible(Path answers)
The cells a run holds, with their first-pass score.
Source · 15 lines
def eligible(answers: Path) -> list[tuple[float, str, float]]:
"""@brief Eligible cells, closest to 50% first.
@return Sortable candidate tuples.
@version 1
"""
out: list[tuple[float, str, float]] = []
for f in sorted(answers.glob("*.grade.json")):
g = json.loads(f.read_text())
score = g["score"] * 100
if LOW <= score <= HIGH and g["unmarked_pct"] < MAX_UNRULED:
out.append((abs(score - 50.0), g["cell"], score))
out.sort()
return out
Activity · 8 steps
Flows
main
int floor_subset.main()
CLI entry point.
Source · 17 lines
def main() -> int:
"""@brief Build a floor subset from a finished run.
@return Exit code.
@version 1
"""
ap = argparse.ArgumentParser(prog="floor_subset", description=__doc__)
ap.add_argument("--run", type=Path, required=True)
ap.add_argument("--dest", type=Path, required=True)
ap.add_argument("--per-target", type=int, default=7)
args = ap.parse_args()
n = build(args.run, args.dest, args.per_target)
print(
f"\n{n} cell(s) copied. Grade each target's directory with the SAME rubric to get pass 2."
)
return 0