Release-Estimator / forecast-utils.js
Banaxi-Tech's picture
Upload 6 files
4929495 verified
Raw History Blame Contribute Delete
986 Bytes
export function dateLabel(date) {
return new Intl.DateTimeFormat('en-US', {month:'long',day:'numeric',timeZone:'UTC'}).format(new Date(`${date}T12:00:00Z`));
}
export function outcomes(model, mode, finalDate) {
const rows=model[mode].map(row=>({...row,label:row.date==='later'?`No release by ${dateLabel(finalDate)}`:`${mode==='by'?'By ':''}${dateLabel(row.date)}`}));
if(mode==='by') rows.push({date:'later',chance:Math.round((100-model.by.at(-1).chance)*10)/10,label:`No release by ${dateLabel(finalDate)}`});
return rows;
}
export function topFive(model,mode,finalDate) {return outcomes(model,mode,finalDate).sort((a,b)=>b.chance-a.chance).slice(0,5)}
export function validateChances(rows,mode) {
if(rows.some(r=>!Number.isFinite(r.chance)||r.chance<0||r.chance>100))return 'Every chance must be a number between 0 and 100.';
if(mode==='by'&&rows.some((r,i)=>i>0&&r.chance<rows[i-1].chance))return 'Later deadlines must have the same or a higher chance.';
return '';
}