const rows=require('./spm_rows.json'); const M=[['m1_es_sh_avg','M1 LOT ES+SH avg days','low'],['m1_es_sh_median','M1 LOT ES+SH median days','low'], ['m1_es_sh_th_avg','M1 LOT ES+SH+TH avg days','low'],['m1_es_sh_th_median','M1 LOT ES+SH+TH median days','low'], ['m2_pct6','M2 returns within 6 mo %','low'],['m2_pct12','M2 returns within 12 mo %','low'],['m2_pct24','M2 returns within 24 mo %','low'], ['m5_first_time_es_sh_th','M5 first-time homeless (ES+SH+TH), persons','low'],['m5_per10k_es_sh_th','M5 first-time (ES+SH+TH) per 10k residents','low'], ['m5_per10k_es_sh_th_ph','M5 first-time (ES+SH+TH+PH) per 10k residents','low'], ['m7a_pct','M7a SO successful exit %','high'],['m7b1_pct','M7b1 ES/SH/TH/RRH exit to PH %','high'],['m7b2_pct','M7b2 PSH retention/exit to PH %','high']]; const yrs=process.argv.slice(2).map(Number); const strictBad=r=>/bed_cov<85|bed_cov_missing|M2_returns_not_cumulative|M1_missing|pct>100|MO-604M/.test(r.dq_flags||""); for(const y of yrs){const ys=rows.filter(r=>r.fy===y);const wa=ys.find(r=>r.coc_code=='WA-500'); console.log(`\n### FY${y} — WA-500 rank among large CoCs (rank 1 = ${'lowest value for "lower is better", highest for "higher is better"'})\n`); console.log('| Measure | Better | WA-500 value | Rank (all reporting) | Median of large CoCs | Rank excl. DQ-flagged CoCs |');console.log('|---|---|---|---|---|---|'); for(const [k,lab,dir] of M){const v=ys.filter(r=>r[k]!=null);const s=[...v].sort((a,b)=>dir=='low'?a[k]-b[k]:b[k]-a[k]); const rk=s.findIndex(r=>r.coc_code=='WA-500')+1;const vals=v.map(r=>r[k]).sort((a,b)=>a-b);const med=vals.length?(vals[(vals.length-1)>>1]+vals[vals.length>>1])/2:null; const c=s.filter(r=>r.coc_code=='WA-500'||!strictBad(r));const rk2=c.findIndex(r=>r.coc_code=='WA-500')+1; console.log(`| ${lab} | ${dir=='low'?'lower':'higher'} | ${wa[k]??'n/a'} | ${rk?rk+' of '+s.length:'n/a'} | ${med==null?'':+med.toFixed(2)} | ${rk2?rk2+' of '+c.length:'n/a'} |`);} console.log(`\nWA-500 FY${y}: bed coverage ${wa.bed_coverage_pct}%, flags: ${wa.dq_flags||'none'}`); const fl=ys.filter(r=>r.dq_flags);console.log(`\nFY${y} CoCs with DQ flags (${fl.length} of ${ys.length}):`); console.log(fl.map(r=>`${r.coc_code} (${r.dq_flags})`).join('; ')); } console.log('\n### WA-500 time series\n'); const K=['fy','bed_coverage_pct','m1_es_sh_avg','m1_es_sh_median','m1_es_sh_th_avg','m1_es_sh_th_median','m2_exits_to_ph','m2_pct6','m2_pct12','m2_pct24','m5_first_time_es_sh_th','m5_first_time_es_sh_th_ph','m5_per10k_es_sh_th','m7a_so_exits','m7a_pct','m7b1_pct','m7b2_pct','dq_flags']; console.log('|'+K.join('|')+'|');console.log('|'+K.map(_=>'---').join('|')+'|'); rows.filter(r=>r.coc_code=='WA-500').forEach(r=>console.log('|'+K.map(k=>r[k]??'').join('|')+'|'));