// Builds the curated CSVs and analysis-rows JSON for dataset us-election-day-gas-prices const fs=require('fs'),crypto=require('crypto'); const CPI_REF=336.940; const rows=fs.readFileSync('election-eve-gas.csv','utf8').trim().split('\n').slice(1).map(l=>{const c=l.split(',');return{year:+c[0],election_date:c[1],price_date:c[2],source:c[3],nominal:+c[4],cpi:+c[5],cpi_basis:c[6],real:+c[7],wage:c[8]?+c[8]:null,minutes:c[9]?+c[9]:null};}); // October-average robustness (EIA weekly, 1990+) const wk=JSON.parse(fs.readFileSync('gasregw.json','utf8')).observations.filter(o=>o.value!=='.'); const octAvg=rows.filter(r=>r.year>=1990).map(r=>{const w=wk.filter(o=>o.date.startsWith(r.year+'-10')).map(o=>+o.value);const a=w.reduce((x,y)=>x+y,0)/w.length;return{year:r.year,october_weeks:w.length,october_avg_nominal:+a.toFixed(3),october_avg_real_sep2026:+(a*CPI_REF/r.cpi).toFixed(2)};}).sort((a,b)=>b.october_avg_real_sep2026-a.october_avg_real_sep2026).map((r,i)=>({rank:i+1,...r})); // State comparison: EIA weekly 2026-10-26 price, EIA state taxes and fees July 1 2026 (and July 2022) const st=[['U.S. average',4.269,0.3376,0.3088],['California',5.888,0.7364,0.6510],['Washington',5.203,0.6017,0.5238],['Colorado',4.458,0.3018,null],['Ohio',4.380,0.3850,null],['New York',4.249,0.2418,null],['Minnesota',4.146,0.3270,null],['Massachusetts',4.145,0.2756,null],['Florida',4.017,0.4010,null],['Texas',3.632,0.2000,0.2000]]; const US=st[0]; const state=st.map(([s,p,t,t22])=>({area:s,price_2026_10_26:p,federal_tax:0.184,state_taxes_fees_2026_07:t,state_taxes_fees_2022_07:t22,price_less_all_taxes:+(p-t-0.184).toFixed(3),gap_vs_us:+(p-US[1]).toFixed(3),tax_gap_vs_us:+(t-US[2]).toFixed(3)})); const stCsv=['area,price_2026_10_26,federal_tax,state_taxes_fees_2026_07,state_taxes_fees_2022_07,price_less_all_taxes,gap_vs_us,state_tax_gap_vs_us',...state.map(r=>[r.area,r.price_2026_10_26.toFixed(3),r.federal_tax.toFixed(3),r.state_taxes_fees_2026_07.toFixed(4),r.state_taxes_fees_2022_07==null?'':r.state_taxes_fees_2022_07.toFixed(4),r.price_less_all_taxes.toFixed(3),r.gap_vs_us.toFixed(3),r.tax_gap_vs_us.toFixed(3)].join(','))].join('\n')+'\n'; fs.writeFileSync('state-taxes-prices.csv',stCsv); const comp=[];for(const r of state){comp.push({area:r.area,component:'Federal tax',dollars_per_gallon:0.184});comp.push({area:r.area,component:'State taxes and fees',dollars_per_gallon:r.state_taxes_fees_2026_07});comp.push({area:r.area,component:'Fuel, refining, delivery and other costs',dollars_per_gallon:r.price_less_all_taxes});} const series=[];for(const r of rows){series.push({year:r.year,measure:'Price at the time',dollars_per_gallon:r.nominal});series.push({year:r.year,measure:'In September 2026 dollars',dollars_per_gallon:r.real});} const minutes=rows.filter(r=>r.minutes!=null).map(r=>({year:r.year,minutes_of_work_per_gallon:r.minutes})); const realRank=[...rows].sort((a,b)=>b.real-a.real).map((r,i)=>({rank:i+1,year:r.year,nominal:r.nominal,real_sep2026:r.real,source:r.source})); const out={series,realRank,minutes,octAvg,state,components:comp}; fs.writeFileSync('analysis-rows.json',JSON.stringify(out,null,1)); for(const f of ['election-eve-gas.csv','state-taxes-prices.csv','analysis-rows.json']){const b=fs.readFileSync(f);console.log(f,b.length,'sha256:'+crypto.createHash('sha256').update(b).digest('hex'));} console.log(stCsv);console.log(JSON.stringify(octAvg.slice(0,8)));