"""Stdlib-only frozen-input descriptive audit; no causal model or prediction fit."""
from pathlib import Path
import csv, json, hashlib, statistics
P=Path(__file__).resolve().parent
sources={
 'audience': {'url':'https://collegefootballplayoff.com/sports/2021/9/7/tv-viewership-history','locator':'TV VIEWERSHIP IN THE CFP FIRST ROUND, eight rows','accessed':'2026-10-22','definition':'Official CFP historical TOTAL; table does not document full per-row measurement/platform methodology or revision date. Preserve reported values, not an assertion of unique viewers or identical bases.'},
 'schedule2024': {'url':'https://collegefootballplayoff.com/news/2024/6/5/2425-schedule','locator':'First Round date/time/network paragraph','accessed':'2026-10-22'},
 'schedule2025': {'url':'https://collegefootballplayoff.com/news/2025/11/4/25-first-round','locator':'First Round date/time/network paragraph','accessed':'2026-10-22'},
 'nfl2024a': {'url':'https://www.nbcsports.com/pressbox/press-releases/nbc-sports-presents-two-nfl-games-with-playoff-implications-this-weekend-as-kansas-city-chiefs-host-houston-texans-on-saturday-afternoon-and-dallas-cowboys-host-tampa-bay-buccaneers-on-sunday-night-football-on-nbc-peacock-and-universo','fact':'Dec21 Texans-Chiefs kickoff 1pm ET; NBC.'},
 'nfl2024b': {'url':'https://www.baltimoreravens.com/news/ravens-steelers-watch-listen-live-stream-week-16-nfl','fact':'Dec21 Steelers-Ravens kickoff 4:30pm; FOX.'},
 'nfl2025': {'url':'https://www.nfl.com/news/nfl-announces-kickoff-times-for-eagles-commanders-packers-bears-week-16-saturday-doubleheader','fact':'Dec20: Eagles-Commanders 5pm ET; Packers-Bears 8:20pm ET; FOX.'},
 'measurement': {'url':'https://www.nielsen.com/news-center/2025/nielsen-begins-updated-era-of-tv-ratings-with-big-data-panel-for-this-falls-tv-season/','locator':'September 2 2025 updated press policy: September1 Big Data + Panel, preliminary single-day exception; out-of-home expansion mentioned','accessed':'2026-10-22'},
 'recapDateConflict': {'url':'https://collegefootballplayoff.com/sports/2025/12/20/R1-BAMA-OU-recap','locator':'Header date conflicts with history, annual schedule and Friday narrative'},
 'recapSlotConflict': {'url':'https://collegefootballplayoff.com/sports/2025/12/21/R1-JMU-ORE-recap','locator':'Header8pm conflicts with annual announced7:30pm; recorded kickoff4:40pm PT'},
 'matchupMap2024': {'url':'https://s3.us-east-2.amazonaws.com/sidearm.nextgen.sites/collegefootballplayoff.sidearmsports.com/documents/2024/12/22/CFP_2024-25_STANDARDIZED_BRACKET_12.22.24_KC-NEW.pdf','locator':'Official first-round bracket date/slot/team mapping, search-indexed'},
 'espn2026': {'url':'https://espnpressroom.com/press-release/espns-megacast-of-the-college-football-playoff-national-championship-presented-by-att-delivers-30-1-million-viewers-the-most-viewed-college-football-game-in-11-years/','locator':'January22 2026 game table Viewers(P2+); rounded 2025 First Round:14.9,14.8,6.2,4.4m; TNT/TBS/HBO Max footnote','accessed':'2026-10-22'}
}
# Every 2024/2025 first-round matchup is included. Dates/audiences: official history;
# scheduled slot/package: annual CFP releases; matchup-slot mapping cross-checks
# official game recap headers except conflicts logged below. IDs are pilot-local.
raw=[
('2024-ind-nd',2024,'2024-12-20','20:00','Indiana','Notre Dame',10,7,13386839,'ABC/ESPN',False,'',None),
('2024-smu-psu',2024,'2024-12-21','12:00','SMU','Penn State',11,6,6597016,'TNT Sports',True,'Texans-Chiefs','13:00'),
('2024-clem-tex',2024,'2024-12-21','16:00','Clemson','Texas',12,5,8900862,'TNT Sports',True,'Steelers-Ravens','16:30'),
('2024-tenn-osu',2024,'2024-12-21','20:00','Tennessee','Ohio State',9,8,14683831,'ABC/ESPN',False,'',None),
('2025-bama-ou',2025,'2025-12-19','20:00','Alabama','Oklahoma',9,8,14939775,'ABC/ESPN',False,'',None),
('2025-mia-tamu',2025,'2025-12-20','12:00','Miami','Texas A&M',10,7,14778965,'ABC/ESPN',False,'',None),
('2025-tu-miss',2025,'2025-12-20','15:30','Tulane','Ole Miss',11,6,6238431,'TNT Sports',True,'Eagles-Commanders','17:00'),
('2025-jmu-ore',2025,'2025-12-20','19:30','James Madison','Oregon',12,5,4357914,'TNT Sports',True,'Packers-Bears','20:20')]
cols=['game_id','season','date','scheduled_start_et','away','home','away_bracket_seed','home_bracket_seed','reported_viewers','package','nfl_start_next_180m','nfl_game','nfl_start_et']
rows=[dict(zip(cols,r)) for r in raw]
for r in rows:
 r.update(audience_source_id='audience',slot_source_id='schedule'+str(r['season']),pregame_spread=None,team_appeal_estimate=None,matched_displaced_bowl_id=None,per_row_measurement_reconciled=False)
with (P/'first_round_sample.csv').open('w',newline='') as f:
 w=csv.DictWriter(f,fieldnames=rows[0]);w.writeheader();w.writerows(rows)
protocol={
 'id':'cfp-first-round-descriptive-intake-v1','frozenOn':'2026-10-22',
 'status':'DESCRIPTIVE_INPUT_PILOT_ONLY_NO_EFFECT_ESTIMATE',
 'relationshipToExistingProtocol':'Supplementary secondary-audience input audit. Does not replace Demand_study_protocol_v1.json primary late-regular-season attendance/stakes target or mark its gates passed.',
 'timingDisclosure':'Scope and summary rules written before script computation but after source outcomes were visible; not prospective preregistration or blinded/held-out validation.',
 'frame':'All eight completed first-round CFP games from 2024 and2025. This is a complete two-season first-round frame, not a representative regular-season/bowl comparison sample.',
 'outcome':'Official CFP historical TOTAL as reported on access date; platform and measurement comparability unverified.',
 'descriptiveEstimand':'Unweighted mean reported game audience in each season and package, plus pooled difference by scheduled NFL exposure proxy. Not a population causal effect or unique-viewer reach.',
 'exposure':'NFL game kickoff within [CFP scheduled kickoff, CFP scheduled kickoff+180 minutes), same local Eastern date. This is a prespecified schedule proxy, not verified overlapping broadcast minutes. Actual program start/end timestamps are not fully collected.',
 'futureCausalTarget':'Difference in comparable average game audience attributable to playoff stakes for selected 5–12-type teams, relative to their counterfactual nonplayoff bowl, conditional on past-only team appeal, expected competitiveness, slot/package and competing broadcasts. No estimate in this pilot.',
 'goGate':['Comparable per-row measurement/platform definitions and revisions','Multi-season pre-expansion outcomes and candidate control teams/bowls, complete classified sample','Archived pregame expectations, team appeal covariates, selection rules and exact conference/playoff seed distinction','Usable within-package/slot exposure variation and overlap; assess parallel trends and simultaneous format changes','Matched displaced bowl accounting without treating repeated game audiences as unique people'],
 'stop':'No causal playoff premium, NFL penalty, campus venue effect, 18-team optimality, rights-price conversion or net incremental audience projection; eight playoff-only rows cannot identify these.'}
assert len({r['game_id'] for r in rows})==8
assert all(r['nfl_start_next_180m']==(r['package']=='TNT Sports') for r in rows)
def group(v):
 return {'games':len(v),'mean_reported_viewers':statistics.mean(r['reported_viewers'] for r in v),'min_reported_viewers':min(r['reported_viewers'] for r in v),'max_reported_viewers':max(r['reported_viewers'] for r in v)}
byseason={str(s):group([r for r in rows if r['season']==s]) for s in (2024,2025)}
byexposure={str(x).lower():group([r for r in rows if r['nfl_start_next_180m']==x]) for x in (False,True)}
summary={'id':protocol['id'],'rowCount':8,'bySeason':byseason,'byNFLStartProxy':byexposure,
 'pooledMeanDifferenceNoNFLStartMinusNFLStart':byexposure['false']['mean_reported_viewers']-byexposure['true']['mean_reported_viewers'],
 'networkExposurePerfectlyConfounded':True,
 'missingness':{'pregame_spread':8,'team_appeal_estimate':8,'matched_displaced_bowl_id':8,'per_row_measurement_reconciliation':8,'exact_broadcast_overlap_minutes':8},
 'conclusion':'Verified descriptive intake, NO_GO for effect estimation. Network/package and scheduled NFL exposure cannot be separated in these eight rows. Team selection and measurement comparability remain unresolved.',
 'sourceConflicts':[
 'CFP Alabama/Oklahoma recap header incorrectly says Saturday December21 2024 although history/schedule say Dec19 2025 and recap narrative says Friday; use history plus annual schedule.',
 'CFP JMU/Oregon recap header says8pm ET, annual schedule says7:30pm ET and actual kickoff4:40pm PT supports7:40pm ET. Pilot uses announced7:30pm, not erroneous recapheader.',
 'Official history current2024 row totals imply a mean distinct from initial10.6m headline; do not combine current totals with preliminary releases without version reconciliation.'
 ],
 'sample_sha256':hashlib.sha256((P/'first_round_sample.csv').read_bytes()).hexdigest()}
for name,value in [('source_register.json',sources),('protocol.json',protocol),('summary.json',summary)]:
 (P/name).write_text(json.dumps(value,indent=2)+'\n')
print(json.dumps(summary,indent=2))
