/**
 * Group done specs by the month of their completedAt date.
 * Returns periods sorted chronologically.
 * Specs without actuals or completedAt are ignored.
 */
export function computeVelocity(specs) {
    const counts = new Map();
    for (const spec of specs) {
        if (spec.status !== 'done' || !spec.actuals?.completedAt) {
            continue;
        }
        const period = toYearMonth(spec.actuals.completedAt);
        if (!period) {
            continue;
        }
        counts.set(period, (counts.get(period) ?? 0) + 1);
    }
    return Array.from(counts.entries())
        .sort(([a], [b]) => a.localeCompare(b))
        .map(([period, count]) => ({ period, count }));
}
function toYearMonth(dateStr) {
    const d = new Date(dateStr);
    if (isNaN(d.getTime())) {
        return null;
    }
    const y = d.getUTCFullYear();
    const m = String(d.getUTCMonth() + 1).padStart(2, '0');
    return `${y}-${m}`;
}
//# sourceMappingURL=velocity-aggregator.js.map