"""Reproduce the published draft-position counts with Python 3 (no dependencies).
Save beside draft-selection-audit.csv and run: python draft-selection-reproduce.py
The CSV includes all regular-draft QB selections, source links, and the frozen
editorial-cohort membership flag. This recomputes membership rates, not a neutral
league-wide franchise classification or future predictive probability.
"""
import csv, json
from pathlib import Path
rows = list(csv.DictReader((Path(__file__).parent / 'draft-selection-audit.csv').open()))
for row in rows:
    for field in ('year', 'round', 'overall'): row[field] = int(row[field])
    row['cohort_member'] = row['cohort_member'].lower() == 'true'
assert len(rows) == 335
assert len({(r['year'], r['overall']) for r in rows}) == 335
assert sum(r['cohort_member'] for r in rows) == 28

def count(sample):
    k = sum(r['cohort_member'] for r in sample)
    return {'members': k, 'all_qb_selections': len(sample),
            'percent': round(100 * k / len(sample), 2) if sample else None}

result = {}
for label, end in [('mature_1998_2016', 2016), ('all_1998_2025', 2025)]:
    sample = [r for r in rows if 1998 <= r['year'] <= end]
    result[label] = {
        'total': count(sample),
        'top10': count([r for r in sample if r['overall'] <= 10]),
        'after10': count([r for r in sample if r['overall'] > 10]),
        'first_round': count([r for r in sample if r['round'] == 1]),
        'later_rounds': count([r for r in sample if r['round'] > 1]),
        'overall_bins': {name: count([r for r in sample if lo <= r['overall'] <= hi])
            for name, lo, hi in [('1', 1, 1), ('2–5', 2, 5), ('6–10', 6, 10),
                                ('11–32', 11, 32), ('33–64', 33, 64),
                                ('65–100', 65, 100), ('101+', 101, 999)]}}
print(json.dumps(result, indent=2))
