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.

scripts/floor_subset.py:59

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
lines 67–67◇ if dest.exists()lines 68–68shutil.rmtree(dest)lines 69–69total = 0lines 70–70◇ for target in sorted(p.name for p in run.iterdir() if (p / "answers").is_dir())lines 71–71cands = eligible(run / target / "answers")lines 72–72chosen = sorted(cands[:per_target], key=lambda c: c[1])lines 73–73out = dest / target / "answers"lines 74–74out.mkdir(parents=True)lines 75–75◇ for _, stem, score in chosenlines 76–76shutil.copy(run / target / "answers" / f"{stem}.md", out / f"{stem}.md")lines 77–77print(f"{target:10} {stem:44} {score:5.1f}%")lines 78–78total += 1lines 81–84allc = [ json.loads(f.read_text())["score"] * 100 for f in (run / target / "answers").glob("*.grade.json") ]lines 85–85lo = sum(1 for s in allc if s < LOW)lines 86–86hi = sum(1 for s in allc if s > HIGH)lines 87–87print(f"{target:10} excluded {lo} cell(s) below {LOW:.0f}% and {hi} above {HIGH:.0f}%")lines 88–88return total

Flows

eligible

list[tuple[float, str, float]] floor_subset.eligible(Path answers)

The cells a run holds, with their first-pass score.

scripts/floor_subset.py:38

Show on the map →

Called by build

Calls none

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
lines 43–43out: list[tuple[float, str, float]] = []lines 44–44◇ for f in sorted(answers.glob("*.grade.json"))lines 45–45g = json.loads(f.read_text())lines 46–46score = g["score"] * 100lines 47–47◇ if LOW <= score <= HIGH and g["unmarked_pct"] < MAX_UNRULEDlines 48–48out.append((abs(score - 50.0), g["cell"], score))lines 49–49out.sort()lines 50–50return out

Flows

main

int floor_subset.main()

CLI entry point.

scripts/floor_subset.py:94

Show on the map →

Called by none

Calls build

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

Activity · 8 steps
lines 99–99ap = argparse.ArgumentParser(prog="floor_subset", description=__doc__)lines 100–100ap.add_argument("--run", type=Path, required=True)lines 101–101ap.add_argument("--dest", type=Path, required=True)lines 102–102ap.add_argument("--per-target", type=int, default=7)lines 103–103args = ap.parse_args()lines 104–104n = build(args.run, args.dest, args.per_target)lines 105–107print( f"\n{n} cell(s) copied. Grade each target's directory with the SAME rubric to get pass 2." )lines 108–108return 0

Flows