소스 검색

nutikodu-web: Varv — kalibratsiooni moistlikkuse kontroll + viimase mootmise nait

- POST /api/varv/calib: keeldub kui valge ~ tume (W-D<=0) voi mootmine null -> 422 selge sonumiga

- UI: kalibratsioonipaneelis juhend + viimase mootmise hex/heledus
ardo 1 주 전
부모
커밋
234d16782b
3개의 변경된 파일과 43개의 추가작업 그리고 2개의 파일을 삭제
  1. 19 0
      dev/nutikodu-web/app.py
  2. 19 2
      dev/nutikodu-web/static/app.js
  3. 5 0
      dev/nutikodu-web/static/index.html

+ 19 - 0
dev/nutikodu-web/app.py

@@ -645,6 +645,25 @@ async def varv_calib_set(payload: dict = Body(...)) -> dict:
     for f in VARV_CALIB_FIELDS:
         vals = [float(r[f]) for r in rows if r.get(f) is not None]
         ref[f] = round(sum(vals) / len(vals), 3) if vals else 0.0
+
+    # Mõistlikkuse kontroll: tume ja valge ei tohi olla sarnased (W-D > 0).
+    total_new = sum(ref.get(b, 0.0) for b in VARV_BANDS)
+    if total_new <= 0:
+        raise HTTPException(status_code=422, detail="Mõõtmine on null — andur on pime või andmed puuduvad.")
+    calib = varv_load_calib()
+    other = calib.get("white" if kind == "dark" else "dark")
+    if other:
+        total_other = sum(float(other.get(b) or 0.0) for b in VARV_BANDS)
+        if kind == "white" and total_new <= total_other * 1.05:
+            raise HTTPException(
+                status_code=422,
+                detail="Valge ja tume on liiga sarnased (valge pole tumedast heledam). Kontrolli: tume = andur kaetud; valge = valge pind valgustatud, sama geomeetria.",
+            )
+        if kind == "dark" and total_new >= total_other * 0.95:
+            raise HTTPException(
+                status_code=422,
+                detail="Tume ja valge on liiga sarnased (tume pole valgest tumedem). Kontrolli, et andur oli täiesti kaetud.",
+            )
     row = {"kind": kind, **ref}
     resp = requests.post(
         f"{CH_URL}/",

+ 19 - 2
dev/nutikodu-web/static/app.js

@@ -655,6 +655,7 @@ async function loadVarv() {
     renderVarvTimeline(history);
     renderVarvSpectrum();
     renderVarvChroma(varvLatest);
+    renderVarvCalibLive();
     const upd = document.getElementById("varv-updated");
     if (upd) upd.textContent = varvLatest.length ? "Viimane mõõtmine " + varvLatest[0].ts : "Andmeid pole";
     if (hint) hint.hidden = true;
@@ -915,6 +916,15 @@ async function loadVarvCalib() {
   } catch (e) { console.error(e); }
 }
 
+function renderVarvCalibLive() {
+  const el = document.getElementById("varv-calib-live");
+  if (!el) return;
+  if (!varvLatest.length) { el.textContent = ""; return; }
+  const c = varvLatest[0];
+  const sum = Object.values(c.bands || {}).reduce((a, v) => a + (Number(v) || 0), 0);
+  el.textContent = `Viimane mõõtmine: ${(c.rgb_hex || "").toUpperCase()} · heledus (kanalite summa) ${Math.round(sum)}`;
+}
+
 async function captureVarvCalib(kind) {
   if (!state.authed) return;
   const hint = document.getElementById("varv-calib-hint");
@@ -924,7 +934,14 @@ async function captureVarvCalib(kind) {
       headers: { "Content-Type": "application/json" },
       body: JSON.stringify({ kind, last: 5 }),
     });
-    if (!res.ok) throw new Error("HTTP " + res.status);
+    if (!res.ok) {
+      let msg = `Salvestamine ebaõnnestus (HTTP ${res.status}).`;
+      try {
+        const e = await res.json();
+        if (typeof e.detail === "string") msg = e.detail;
+      } catch (ignored) { /* ignore */ }
+      throw new Error(msg);
+    }
     const d = await res.json();
     if (hint) {
       hint.hidden = false;
@@ -935,7 +952,7 @@ async function captureVarvCalib(kind) {
     loadVarv();
   } catch (e) {
     console.error(e);
-    if (hint) { hint.hidden = false; hint.textContent = "Salvestamine ebaõnnestus."; }
+    if (hint) { hint.hidden = false; hint.textContent = e.message || "Salvestamine ebaõnnestus."; }
   }
 }
 

+ 5 - 0
dev/nutikodu-web/static/index.html

@@ -134,6 +134,11 @@
             <button type="button" id="varv-calib-white" class="btn">Salvesta valge</button>
           </div>
         </div>
+        <div class="varv-sub" style="margin-top:8px">
+          1) Kata andur → „Salvesta tume". 2) Pane valge pind sama valgustusega → „Salvesta valge".
+          Oota ~30 s, kuni mõõtmine stabiliseerub.
+        </div>
+        <div id="varv-calib-live" class="varv-sub" style="margin-top:4px"></div>
         <label class="chk" style="margin-top:10px;display:inline-flex">
           <input type="checkbox" id="varv-calib-view" /> <span>Kuva kalibreeritud värvi</span>
         </label>