Files
Projects-plastic/issue.txt
Marcelo b66cb97f16 MVP
2025-11-28 09:11:59 -06:00

82 lines
2.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

4) Machine cycles: fix cavities read
You currently have:
const cavities = Number(global.get("moldActive") || 0);
If moldActive is an object, Number(obj) → NaN.
✔️ Use the property:
const cavities = Number((global.get("moldActive") || {}).cavities) || 1;
Also guard negative produced:
const produced = Math.max(0, totalProduced - scrapTotal);
🧱 5) ID consistency in SQL
In your flow, SQL uses work_order_id. In your start-tracking example inside “Work Order buttons”, you used WHERE id = ....
✔️ Make them consistent (use work_order_id):
topic: `UPDATE work_orders SET production_start_time = ${now}, is_tracking = 1 WHERE work_order_id = '${activeOrder.id}'`
Same consistency in resume/restart and persist queries.
🧰 6) Format Graph Data: keep messages clean to UI
Before returning to the template, strip SQL fields so nothing accidentally loops into DB:
delete msg.topic;
delete msg.payload;
return msg;
🧯 7) MariaDB guard
You already create two Switch nodes. Keep the rule:
Property: msg.topic
Rule: is type → string
And wire every DB path through it (graphs fetch + cycles persist). That eliminates the “query is not defined as a string” spam.
✂️ Minimal diffs youll likely want
Machine cycles (core lines)
const cavities = Number((global.get("moldActive") || {}).cavities) || 1;
// ...
const produced = Math.max(0, totalProduced - scrapTotal);
// ...
const persistCycleCount = {
topic: "UPDATE work_orders SET cycle_count = ?, good_parts = ? WHERE work_order_id = ?",
payload: [cycles, produced, activeOrder.id]
};
Fetch Graph Data (SELECT list)
msg.topic = `
SELECT work_order_id, status, good_parts, scrap_parts, progress_percent,
target_quantity, updated_at, cycle_count
FROM work_orders
WHERE updated_at >= NOW() - ${interval}
ORDER BY updated_at ASC
`;
Format Graph Data (efficiency + cleanup)
const good = Number(row.good_parts) || 0;
const target = Number(row.target_quantity) || 0;
let eff = (row.progress_percent != null)
? Number(row.progress_percent)
: (target > 0 ? (good / target) * 100 : 0);
eff = Math.min(100, Math.max(0, eff));
efficiencyData.push(eff);
// before return:
delete msg.topic;
delete msg.payload;
return msg;
Work Order buttons (“start-tracking” WHERE clause)
topic: `UPDATE work_orders SET production_start_time = ${now}, is_tracking = 1
WHERE work_order_id = '${activeOrder.id}'`,