URCE — Plant Intelligence

Universal Residual Closure Engine — live fleet intelligence
Loading fleet data…

Estimated Daily Cost Leakage

$0

Projected 30-Day Exposure

$0

Fleet Avg Residual %

0%

Fleet Health Index

0

Live Pump Intelligence

Click "Load Live Fleet Data" to see real pump status

🔥 URCE DECISION ENGINE

async function loadDecision() { const out = document.getElementById("decision-output"); out.innerHTML = "Analyzing..."; try { const res = await fetch("/decision"); if (!res.ok) { throw new Error("HTTP " + res.status); } const text = await res.text(); // 🔥 Safe JSON parse let data; try { data = JSON.parse(text); } catch (err) { console.error("Bad JSON:", text); throw new Error("Invalid JSON from /decision"); } if (!data.decisions || !Array.isArray(data.decisions)) { throw new Error("Missing or invalid decisions array"); } // Sort safely const sorted = [...data.decisions].sort((a, b) => { if (a.time_to_failure_hours == null) return 1; if (b.time_to_failure_hours == null) return -1; return a.time_to_failure_hours - b.time_to_failure_hours; }); let html = ""; sorted.slice(0, 3).forEach(d => { const borderColor = d.time_to_failure_hours < 5 ? "red" : d.time_to_failure_hours < 12 ? "orange" : "#444"; html += `

🚨 ${d.pump_id || "Unknown"}

Problem: ${d.issue || "N/A"}
Cause: ${d.cause || "N/A"}
Confidence: ${d.confidence ?? "N/A"}%

⏱ Time to Failure: ${d.time_to_failure_hours ?? "N/A"} hrs
Safe Window: ${d.safe_action_window_hours ?? "N/A"} hrs

💥 Risk if Ignored: $${d.risk_if_ignored ?? "N/A"}

🛠 Action: ${d.recommended_action || "N/A"}
Fix Cost: $${d.fix_cost ?? "N/A"}
`; }); out.innerHTML = html; } catch (e) { console.error("Decision engine error:", e); out.innerHTML = "❌ Decision engine failed
" + e.message; } } async function loadDecision() { const out = document.getElementById("decision-output"); out.innerHTML = "Analyzing..."; try { const res = await fetch("/decision"); if (!res.ok) { throw new Error("HTTP " + res.status); } const data = await res.json(); // Sort by urgency (fastest failure first) const sorted = data.decisions.sort((a, b) => { if (a.time_to_failure_hours == null) return 1; if (b.time_to_failure_hours == null) return -1; return a.time_to_failure_hours - b.time_to_failure_hours; }); let html = ""; sorted.slice(0, 3).forEach(d => { // 🔥 PRIORITY COLOR LOGIC const borderColor = d.time_to_failure_hours < 5 ? "red" : d.time_to_failure_hours < 12 ? "orange" : "#444"; html += `

🚨 ${d.pump_id}

Problem: ${d.issue}
Cause: ${d.cause}
Confidence: ${d.confidence}%

⏱ Time to Failure: ${d.time_to_failure_hours ?? "N/A"} hrs
Safe Window: ${d.safe_action_window_hours ?? "N/A"} hrs

💥 Risk if Ignored: $${d.risk_if_ignored}

🛠 Action: ${d.recommended_action}
Fix Cost: $${d.fix_cost}
Savings: $${d.savings}
ROI: ${d.roi}x

🔍 Verify:
${d.verify_steps.map(v => "• " + v).join("
")}
`; }); out.innerHTML = html; } catch (e) { out.innerHTML = "❌ Decision engine failed
" + e; console.error(e); } } ////////////////////////////////////////////////// // 🔥 AUTO RUN (THIS IS WHAT YOU ADD UNDER IT) ////////////////////////////////////////////////// loadDecision(); setInterval(loadDecision, 15000);