Initial commit, 90% there
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import uuid
|
||||
|
||||
# Read flows.json
|
||||
with open('/home/mdares/.node-red/flows.json', 'r') as f:
|
||||
flows = json.load(f)
|
||||
|
||||
# Find the main flow tab ID (first tab)
|
||||
main_tab_id = None
|
||||
for node in flows:
|
||||
if node.get('type') == 'tab':
|
||||
main_tab_id = node['id']
|
||||
break
|
||||
|
||||
# Find the Machine cycles node to get its position
|
||||
machine_cycles_node = None
|
||||
work_order_buttons_node = None
|
||||
db_config_id = None
|
||||
|
||||
for node in flows:
|
||||
if node.get('id') == '0d023d87a13bf56f':
|
||||
machine_cycles_node = node
|
||||
elif node.get('id') == '9bbd4fade968036d':
|
||||
work_order_buttons_node = node
|
||||
elif node.get('type') == 'MySQLdatabase':
|
||||
db_config_id = node['id'] # Use existing DB config
|
||||
|
||||
print(f"Main tab ID: {main_tab_id}")
|
||||
print(f"Machine cycles position: x={machine_cycles_node['x']}, y={machine_cycles_node['y']}")
|
||||
print(f"Work Order buttons position: x={work_order_buttons_node['x']}, y={work_order_buttons_node['y']}")
|
||||
print(f"DB config ID: {db_config_id}")
|
||||
|
||||
# Generate unique IDs for new nodes
|
||||
state_backup_mysql_id = str(uuid.uuid4()).replace('-', '')[:16]
|
||||
anomaly_mysql_id = str(uuid.uuid4()).replace('-', '')[:16]
|
||||
session_mgmt_mysql_id = str(uuid.uuid4()).replace('-', '')[:16]
|
||||
|
||||
# Create new MySQL nodes for Machine cycles outputs
|
||||
state_backup_mysql = {
|
||||
"id": state_backup_mysql_id,
|
||||
"type": "mysql",
|
||||
"z": main_tab_id,
|
||||
"mydb": db_config_id,
|
||||
"name": "State Backup DB",
|
||||
"x": machine_cycles_node['x'] + 200,
|
||||
"y": machine_cycles_node['y'] + 60,
|
||||
"wires": [[]]
|
||||
}
|
||||
|
||||
anomaly_mysql = {
|
||||
"id": anomaly_mysql_id,
|
||||
"type": "mysql",
|
||||
"z": main_tab_id,
|
||||
"mydb": db_config_id,
|
||||
"name": "Anomaly Tracker DB",
|
||||
"x": machine_cycles_node['x'] + 200,
|
||||
"y": machine_cycles_node['y'] + 120,
|
||||
"wires": [[]]
|
||||
}
|
||||
|
||||
# Create new MySQL node for Work Order buttons session management
|
||||
session_mgmt_mysql = {
|
||||
"id": session_mgmt_mysql_id,
|
||||
"type": "mysql",
|
||||
"z": main_tab_id,
|
||||
"mydb": db_config_id,
|
||||
"name": "Session Manager DB",
|
||||
"x": work_order_buttons_node['x'] + 200,
|
||||
"y": work_order_buttons_node['y'] + 100,
|
||||
"wires": [[]]
|
||||
}
|
||||
|
||||
# Add new nodes to flows
|
||||
flows.append(state_backup_mysql)
|
||||
flows.append(anomaly_mysql)
|
||||
flows.append(session_mgmt_mysql)
|
||||
|
||||
# Update wiring for Machine cycles node (4 outputs)
|
||||
if machine_cycles_node:
|
||||
# Output 1: existing wire (work_orders update)
|
||||
# Output 2: existing wire (state messages)
|
||||
# Output 3: NEW - state backup
|
||||
# Output 4: NEW - anomaly detection
|
||||
|
||||
existing_wires = machine_cycles_node.get('wires', [])
|
||||
|
||||
# Ensure we have 4 output arrays
|
||||
while len(existing_wires) < 4:
|
||||
existing_wires.append([])
|
||||
|
||||
# Wire output 3 to state backup MySQL
|
||||
existing_wires[2] = [state_backup_mysql_id]
|
||||
|
||||
# Wire output 4 to anomaly MySQL
|
||||
existing_wires[3] = [anomaly_mysql_id]
|
||||
|
||||
machine_cycles_node['wires'] = existing_wires
|
||||
|
||||
# Update wiring for Work Order buttons node (5 outputs)
|
||||
if work_order_buttons_node:
|
||||
# Output 1-4: existing wires
|
||||
# Output 5: NEW - session management
|
||||
|
||||
existing_wires = work_order_buttons_node.get('wires', [])
|
||||
|
||||
# Ensure we have 5 output arrays
|
||||
while len(existing_wires) < 5:
|
||||
existing_wires.append([])
|
||||
|
||||
# Wire output 5 to session management MySQL
|
||||
existing_wires[4] = [session_mgmt_mysql_id]
|
||||
|
||||
work_order_buttons_node['wires'] = existing_wires
|
||||
|
||||
# Write updated flows
|
||||
with open('/home/mdares/.node-red/flows.json', 'w') as f:
|
||||
json.dump(flows, f, indent=4)
|
||||
|
||||
print("\n✅ Added 3 new MySQL nodes:")
|
||||
print(f" - State Backup DB (ID: {state_backup_mysql_id})")
|
||||
print(f" - Anomaly Tracker DB (ID: {anomaly_mysql_id})")
|
||||
print(f" - Session Manager DB (ID: {session_mgmt_mysql_id})")
|
||||
print("\n✅ Updated wiring:")
|
||||
print(" - Machine cycles output 3 → State Backup DB")
|
||||
print(" - Machine cycles output 4 → Anomaly Tracker DB")
|
||||
print(" - Work Order buttons output 5 → Session Manager DB")
|
||||
Reference in New Issue
Block a user