Files
2025-12-02 16:27:21 +00:00

92 lines
4.2 KiB
Python

#!/usr/bin/env python3
import json
with open('/home/mdares/.node-red/flows.json', 'r') as f:
flows = json.load(f)
for node in flows:
if node.get('id') == 'f3a4b5c6d7e8f9a0' and node.get('name') == 'Graphs Template':
template = node.get('format', '')
# 1. Change chart titles in HTML
template = template.replace('<h2>Production</h2>', '<h2>OEE</h2>')
template = template.replace('<h2>Scrap</h2>', '<h2>Availability</h2>')
template = template.replace('<h2>Efficiency</h2>', '<h2>Performance</h2>')
# Quality stays the same
# 2. Change canvas IDs to be more semantic
template = template.replace('id="chart-production"', 'id="chart-oee"')
template = template.replace('id="chart-scrap"', 'id="chart-availability"')
template = template.replace('id="chart-efficiency"', 'id="chart-performance"')
# Quality ID stays the same
# 3. Update dataset lookups in JavaScript
template = template.replace(
"var goodData = datasets.find(function(d) { return d.label === 'Good Parts'; }) || { data: [] };",
"var oeeData = datasets.find(function(d) { return d.label === 'OEE %'; }) || { data: [] };"
)
template = template.replace(
"var scrapData = datasets.find(function(d) { return d.label === 'Scrap Parts'; }) || { data: [] };",
"var availData = datasets.find(function(d) { return d.label === 'Availability %'; }) || { data: [] };"
)
template = template.replace(
"var effData = datasets.find(function(d) { return d.label === 'Efficiency %'; }) || { data: [] };",
"var perfData = datasets.find(function(d) { return d.label === 'Performance %'; }) || { data: [] };"
)
template = template.replace(
"var qualData = datasets.find(function(d) { return d.label === 'Quality %'; }) || { data: [] };",
"var qualData = datasets.find(function(d) { return d.label === 'Quality %'; }) || { data: [] };"
)
# 4. Update chart variable names and data references
# Production chart → OEE chart
template = template.replace(
"var prodCtx = document.getElementById('chart-production');",
"var oeeCtx = document.getElementById('chart-oee');"
)
template = template.replace(
"if (prodCtx) {\n scope._charts.production = new Chart(prodCtx",
"if (oeeCtx) {\n scope._charts.oee = new Chart(oeeCtx"
)
template = template.replace(
"datasets: [{ label: 'Good Parts', data: goodData.data",
"datasets: [{ label: 'OEE %', data: oeeData.data"
)
# Scrap chart → Availability chart
template = template.replace(
"var scrapCtx = document.getElementById('chart-scrap');",
"var availCtx = document.getElementById('chart-availability');"
)
template = template.replace(
"if (scrapCtx) {\n scope._charts.scrap = new Chart(scrapCtx",
"if (availCtx) {\n scope._charts.availability = new Chart(availCtx"
)
template = template.replace(
"datasets: [{ label: 'Scrap Parts', data: scrapData.data",
"datasets: [{ label: 'Availability %', data: availData.data"
)
# Efficiency chart → Performance chart
template = template.replace(
"var effCtx = document.getElementById('chart-efficiency');",
"var perfCtx = document.getElementById('chart-performance');"
)
template = template.replace(
"if (effCtx) {\n scope._charts.efficiency = new Chart(effCtx",
"if (perfCtx) {\n scope._charts.performance = new Chart(perfCtx"
)
template = template.replace(
"datasets: [{ label: 'Efficiency %', data: effData.data",
"datasets: [{ label: 'Performance %', data: perfData.data"
)
node['format'] = template
print("✓ Updated Graphs Template to display OEE, Availability, Performance, Quality")
break
with open('/home/mdares/.node-red/flows.json', 'w') as f:
json.dump(flows, f, indent=4)
print("✓ flows.json updated")