from java.awt import Color
if event.propertyName == "componentRunning" and event.newValue:
if pastDueRL_res == None or pastDueSO_res == None or CPCP_res == None:
system.db.rollbackTransaction(transactionID)
print("Transaction Failed! Rolling back...")
system.db.commitTransaction(transactionID)
print("Transaction Succeeded!")
system.db.closeTransaction(transactionID)
print("Edning Transaction...")
print("========= rl ==========")
for row in pastDueRL_res:
print(' '.join(map(str, row)))
machines = event.source.Machines
pyMachines = system.dataset.toPyDataSet(machines)
# first accessor will be different per button, param4 = assetno
machinesLen = len(pyMachines)
tableData = []
# Preprocess results
pastDueRL_dict = {}
pastDueSO_dict = {}
CPCP_dict = {}
# Preprocess pastDueRL_res
for row in pastDueRL_res:
assetNo = row[4]
hours = row[3]
if assetNo not in pastDueRL_dict:
pastDueRL_dict[assetNo] = 0.0
pastDueRL_dict[assetNo] += hours/row[2]
# Preprocess pastDueSO_res
for row in pastDueSO_res:
assetNo = row[4]
hours = row[3]
if assetNo not in pastDueSO_dict:
pastDueSO_dict[assetNo] = 0.0
pastDueSO_dict[assetNo] += hours/row[2]
# Preprocess CPCP_res
for row in CPCP_res:
assetNo = row[4]
if assetNo not in CPCP_dict:
CPCP_dict[assetNo] = 0.0
CPCP_dict[assetNo] += row[3] / row[2]
# Main loop: Iterate through each machine
for i in range(machinesLen):
# currRow = ['', '', 0.0, 0.0, 0.0, 0.0] <- RCCIG-106
currRow = ['', '', 0.0, 0.0, 0.0]
name = pyMachines[i][1]
currRow[0] = name
assetNo = pyMachines[i][0]
currRow[1] = str(assetNo)
# Use precomputed dictionaries for constant-time lookups
currRow[2] = pastDueRL_dict.get(assetNo, 0.0) # Sum from pastDueRL_res
currRow[3] = pastDueSO_dict.get(assetNo, 0.0) # Sum from pastDueSO_res
currRow[4] = CPCP_dict.get(assetNo, 0.0) # Sum of ratios from CPCP_res <- RCCIG-106 used to be 5 instead of 4
# row now complete
tableData.append(currRow)
totalCPCP = sum(row[4] for row in tableData)
#print(totalCPCP)
yellowThreshold = 5100 * machinesLen
redThreshold = 7100 * machinesLen
CPCPLabel = event.source.getComponent('Row8').getComponent('Numeric Label 1')
print(event.source.getComponent('Row8').getComponent('Numeric Label 1').background)
if totalCPCP > redThreshold:
CPCPLabel.background= Color(255,0,0)
elif totalCPCP > yellowThreshold:
CPCPLabel.background= Color(255,255,0)
else:
CPCPLabel.background = Color(250,250,251)
# headers = ["Name", "Asset Number", "Past Due (RL)", "Past Due (SO)", "1 Year Forecast w/ Batching", "1 Year Forecast (CPCP)"] <- RCCIG-106
headers = ["Name", "Asset Number", "Past Due (RL)", "Past Due (SO)", "1 Year Forecast (CPCP)"]
dataset = system.dataset.toDataSet(headers, tableData)
event.source.getComponent('Power Table').data = dataset
event.source.getComponent('LoadingGraphic').visible = False
So I have a script for a template property change event and I am trying to set the background color for the numeric label based on the value of the "totalCPCP". I learned that the background color for Numeric Label returns java.awt.Color[r=222,g=223,b=222] from the console.
Currently, the power table in the template does not display data but the numeric label does display data but not the background color
Any ideas how to initialize the background colors?
