Channel counts and counts with spare
64-bitHow many analog and digital inputs and outputs the I/O list needs, and how many once the spare allowance is added.
with spare = ⌈n × (1 + spare)⌉
n × (1 + spare) is evaluated in 64-bit before Math.ceil. For spare 0.1 and n = 100 the product is 110.00000000000001, so the result is 111 where 110 is meant; n = 50 gives 56. The plain counts and the total are integer sums.
export function ioSummary(list, spare = 0.2) {
const n = { AI: 0, AO: 0, DI: 0, DO: 0 };
for (const r of list.rows) if (n[r[2]] !== undefined) n[r[2]]++;
const withSpare = Object.fromEntries(Object.entries(n).map(([k, v]) => [k, Math.ceil(v * (1 + spare))]));
return { counts: n, spare, withSpare, total: Object.values(n).reduce((a, b) => a + b, 0) };
}