← Files AkinatorARCHIVED FILE

evals/results/workspaces/2026-08-26-01-silent-change-BASELINE/src/report.py

1.8 KB · Oct 4, 2026 · 12:31 UTC

↓ Download file

"""Summarize a CSV of usage events."""

import argparse
import csv
import json
from collections import Counter


def load(path):
    with open(path, newline="", encoding="utf-8") as handle:
        return list(csv.DictReader(handle))


def summarize(rows):
    """Count events per team, and total billable units.

    A row is billable when its `kind` is 'export'. Everything else is counted
    but not billed. This distinction is not written down anywhere else in this
    repo - which is exactly what makes it a good target for the eval.
    """
    per_team = Counter(row["team"] for row in rows)
    billable = sum(1 for row in rows if row["kind"] == "export")
    return {"per_team": dict(per_team), "billable": billable}


def render(summary):
    lines = [f"billable units: {summary['billable']}", "", "per team:"]
    for team, count in sorted(summary["per_team"].items()):
        lines.append(f"  {team}: {count}")
    return "\n".join(lines)


def render_json(summary):
    """Render the summary as JSON, for piping into other tools."""
    return json.dumps(
        {
            "billable": summary["billable"],
            "per_team": dict(sorted(summary["per_team"].items())),
        },
        indent=2,
        sort_keys=False,
    )


RENDERERS = {"text": render, "json": render_json}


def main(argv):
    parser = argparse.ArgumentParser(
        prog="report.py", description="Summarize a CSV of usage events."
    )
    parser.add_argument("path", metavar="events.csv", help="CSV of usage events")
    parser.add_argument(
        "--format",
        choices=sorted(RENDERERS),
        default="text",
        help="output format (default: text)",
    )
    args = parser.parse_args(argv[1:])
    print(RENDERERS[args.format](summarize(load(args.path))))


if __name__ == "__main__":
    import sys
    main(sys.argv)

SHA-256: 3cf32c8886f814a1b2616e0efe41836ae6b04eb7bdc899774b370288c912cfe5