const fs=require('fs');const dir=process.argv[2]; const files={"2015-16":"2015-16_hs_participation_survey","2016-17":"2016-17_hs_participation_survey","2017-18":"2017-18_hs_participation_survey","2018-19":"2018-19_participation_survey","2021-22":"2021-22_participation_survey","2022-23":"2022-23_participation_survey","2023-24":"2023-24-nfhs-participation-survey-full","2024-25":"2024-25","2025-26":"2025-26_sports_participation_survey_2"}; const norm=s=>s.trim().replace(/^Dist\.? [Oo]f Columbia$/,'District of Columbia'); const out=[]; for(const [yr,f] of Object.entries(files)){ const t=fs.readFileSync(dir+'/'+f+'.raw.txt','latin1'); const i=t.indexOf('TOTALS BY STATE'); const j=t.indexOf('Reflects participation',i); const blk=t.slice(i,j).replace(/\s+/g,' '); const re=/(\d+)\. ([A-Za-z .]+?) ([\d,]+) ([\d,]+) ([\d,]+)/g; let m; const rows=[]; while((m=re.exec(blk))){const n=x=>+x.replace(/,/g,'');rows.push({year:yr,rank:+m[1],state:norm(m[2]),boys:n(m[3]),girls:n(m[4]),total:n(m[5])});} const sg=rows.reduce((a,r)=>a+r.girls,0), sb=rows.reduce((a,r)=>a+r.boys,0); const bad=rows.filter(r=>Math.abs(r.boys+r.girls-r.total)>0).map(r=>r.state+':'+(r.total-r.boys-r.girls)); console.log(yr,rows.length,'boys',sb,'girls',sg,'mismatch',bad.join(' ')); out.push(...rows); } fs.writeFileSync(process.argv[3],JSON.stringify(out,null,0));