Energy, cost and CO2 of a variant
64-bitThe totals a variant is judged by: heating, cooling and shaft power in kW, operating cost per hour and kg CO2 per hour.
cost/h = (heat × p_heat + cool × p_cool) × 3600 ÷ 1e9 + (shaft ÷ 1e3) × p_power; CO2/h = (heat × 3600 ÷ 1e9) × f_heat + (shaft ÷ 1e3) × f_power
Duties are summed over the units in order, in 64-bit; the scale factors 1e3, 1e9 and 3600 are exact. A price or factor that is missing enters as NaN, so the result is NaN and not a default.
export function metricsOf(result, metrics, { prices = null, factors = null, th = null } = {}) {
let heat = 0, cool = 0, shaft = 0;
for (const u of Object.values(result.units || {})) { const Q = u.Q || 0, W = u.W || 0; if (Q > 0) heat += Q; else cool += -Q; if (W > 0) shaft += W; }
const all = { heat_kW: heat / 1e3, cool_kW: cool / 1e3, shaft_kW: shaft / 1e3, energy_kW: (heat + cool + shaft) / 1e3 };
if (prices) all.operating_per_h = ((heat * (prices.heat ?? NaN) + cool * (prices.cool ?? NaN)) * 3600 / 1e9) + (shaft / 1e3) * (prices.power ?? NaN);
if (factors) all.co2_kg_h = (heat * 3600 / 1e9) * (factors.heat ?? NaN) + (shaft / 1e3) * (factors.power ?? NaN);
const out = {};
for (const m of metrics) out[m.key] = typeof m.metric === 'string' ? all[m.metric] : propOf(th, result, m.metric);
return out;
}