aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis <louis@dnge.de>2026-11-06 17:06:46 +0100
committerLouis <louis@dnge.de>2026-11-06 17:06:46 +0100
commit618b26b81fe2bb6fb33cb9a1924c16e44bf45399 (patch)
tree34a2c5bd0d0a948eda47e7c215f89e60524e1534
parentbcfbc9630d5c052a23b8bfe205d11d0ba3feac41 (diff)
downloaddeckungsanteil-618b26b81fe2bb6fb33cb9a1924c16e44bf45399.tar.gz
Fix stuck results while editing inputs
Allow bivalence/switching temperatures below the design outdoor temperature instead of blocking the calculation, treat empty or partial numbers as invalid rather than 0, grey out stale results while an input is invalid, coalesce bursts of input events and evaluate the model once per temperature value (about 3.5x faster). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--web/app.js73
-rw-r--r--web/style.css1
2 files changed, 53 insertions, 21 deletions
diff --git a/web/app.js b/web/app.js
index d0e45f5..3f70176 100644
--- a/web/app.js
+++ b/web/app.js
@@ -174,19 +174,27 @@ function simulate(series, years, p) {
backs: new Float32Array(n * 8760),
temps: [],
};
+ // temperatures repeat a lot (0.1 K resolution), so evaluate the model once per value
+ const cache = new Map();
+ const evaluate = (t) => {
+ let v = cache.get(t);
+ if (!v) {
+ const q = m.load(t), hp = m.heatPump(t);
+ const backup = m.backupAllowed(t) ? q - hp : 0;
+ v = { q, hp, backup, uncovered: q - hp - backup, el: hp > 0 ? hp / m.cop(t) : 0 };
+ cache.set(t, v);
+ }
+ return v;
+ };
years.forEach((year, y) => {
const t = temperatures(series.get(year), p.resolution);
r.temps.push(t);
for (let i = 0; i < t.length; i++) {
- const q = m.load(t[i]);
- const hp = m.heatPump(t[i]);
- const backup = m.backupAllowed(t[i]) ? q - hp : 0;
- const uncovered = q - hp - backup;
+ const { q, hp, backup, uncovered, el } = evaluate(t[i]);
r.loads[y * 8760 + i] = q;
r.hps[y * 8760 + i] = hp;
r.backs[y * 8760 + i] = backup;
if (q <= 0) continue;
- const el = hp > 0 ? hp / m.cop(t[i]) : 0;
r.els[y * 8760 + i] = el;
r.q += q; r.hp += hp; r.backup += backup; r.uncovered += uncovered; r.el += el;
r.heatingHours++;
@@ -222,36 +230,51 @@ function simulate(series, years, p) {
// ---------- form ----------
+/** Number from an input; NaN when it is empty or not a valid number (e.g. while typing "-"). */
+function num(id) {
+ const v = $(id).value.trim();
+ return v === "" ? NaN : +v;
+}
+
function params() {
const cutoff = $("cutoff").value.trim();
return {
- qn: +$("qn").value,
- tn: +$("tn").value,
- thg: +$("thg").value,
+ qn: num("qn"),
+ tn: num("tn"),
+ thg: num("thg"),
mode: $("mode").value,
- tbiv: +$("tbiv").value,
+ tbiv: num("tbiv"),
cutoff: cutoff === "" ? NaN : +cutoff,
- slope: +$("slope").value / 100,
+ slope: num("slope") / 100,
resolution: $("resolution").value,
type: $("type").value,
device: $("device").value,
- flowN: +$("flowN").value,
+ flowN: num("flowN"),
flowCurve: $("flowCurve").checked,
- priceEl: +$("priceEl").value,
+ priceEl: num("priceEl"),
fuel: $("fuel").value,
- priceBackup: +$("priceBackup").value,
- effBackup: +$("effBackup").value / 100,
+ priceBackup: num("priceBackup"),
+ effBackup: num("effBackup") / 100,
};
}
function validate(p) {
+ const manualTbiv = p.mode === "alternative" || p.type !== "air" || p.device === "generic";
+ const generic = p.type !== "air" || p.device === "generic";
+ const required = [
+ ["qn", "Norm-Heizlast"], ["tn", "Norm-Außentemperatur"], ["flowN", "Vorlauftemperatur"],
+ ["priceEl", "Strompreis"], ["priceBackup", "Preis Zusatzheizung"], ["effBackup", "Wirkungsgrad Zusatzheizung"],
+ ];
+ if (p.mode !== "mono" && manualTbiv) required.push(["tbiv", $("tbivLabel").textContent]);
+ if (generic) required.push(["slope", "Leistungsänderung der WP"]);
+ for (const [key, label] of required) {
+ if (!Number.isFinite(p[key])) return `Bitte eine gültige Zahl für „${label}“ eingeben.`;
+ }
if (!(p.qn > 0)) return "Norm-Heizlast muss größer als 0 sein.";
if (!(p.flowN >= 25 && p.flowN <= 65)) return "Vorlauftemperatur muss zwischen 25 und 65 °C liegen.";
if (!(p.effBackup > 0)) return "Wirkungsgrad der Zusatzheizung muss größer als 0 sein.";
if (!(p.tn < p.thg)) return "Norm-Außentemperatur muss unter der Heizgrenztemperatur liegen.";
- const manualTbiv = p.mode === "alternative" || p.type !== "air" || p.device === "generic";
- if (p.mode !== "mono" && manualTbiv && !(p.tbiv < p.thg)) return "Bivalenzpunkt muss unter der Heizgrenztemperatur liegen.";
- if (p.mode !== "mono" && manualTbiv && p.tbiv < p.tn) return "Bivalenzpunkt unter der Norm-Außentemperatur: dann ist die Anlage praktisch monovalent.";
+ if (p.mode !== "mono" && manualTbiv && !(p.tbiv < p.thg)) return `${$("tbivLabel").textContent} muss unter der Heizgrenztemperatur liegen.`;
return null;
}
@@ -312,6 +335,12 @@ function onTypeChange() {
$("slope").value = $("type").value === "air" ? 3 : 0;
}
+let scheduled = null;
+function scheduleRun() {
+ clearTimeout(scheduled);
+ scheduled = setTimeout(run, 60);
+}
+
let runToken = 0;
async function run() {
updateFieldVisibility();
@@ -321,7 +350,9 @@ async function run() {
}
const p = params();
const error = validate(p);
- if (error) { $("status").textContent = error; return; }
+ // keep the last results visible but greyed out until the input is valid again
+ $("results").classList.toggle("stale", !!error);
+ if (error) { $("status").innerHTML = `<span class="warn">${error}</span>`; return; }
const token = ++runToken;
const series = await loadSeries(station.id);
if (token !== runToken) return;
@@ -562,7 +593,7 @@ async function init() {
]);
stationById = Object.fromEntries(meta.stations.map((s) => [s.id, s]));
- $("plz").addEventListener("input", () => { showLocation(); run(); });
+ $("plz").addEventListener("input", () => { showLocation(); scheduleRun(); });
$("tn").addEventListener("input", () => { tnEdited = true; });
$("tnReset").addEventListener("click", () => {
tnEdited = false;
@@ -577,8 +608,8 @@ async function init() {
run();
});
onFuelChange(false);
- $("form").addEventListener("input", run);
- $("form").addEventListener("change", run);
+ $("form").addEventListener("input", scheduleRun);
+ $("form").addEventListener("change", scheduleRun);
$("form").addEventListener("submit", (e) => e.preventDefault());
$("exportBins").addEventListener("click", exportBins);
$("exportHours").addEventListener("click", exportHours);
diff --git a/web/style.css b/web/style.css
index d6788b5..20d6574 100644
--- a/web/style.css
+++ b/web/style.css
@@ -117,3 +117,4 @@ figcaption { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--panel); }
+#results.stale > :not(#status) { opacity: 0.35; pointer-events: none; }