This data source script looks at a nested query I have and generates a table that shows each step's name, start, end, and duration
from system.report import QueryResults
res = data["BatchInfo"].getCoreResults()
data["BatchDuration"] = utils.prettifyMillis(system.date.millisBetween(res.getValueAt(0,"starttime"),res.getValueAt(0,"endtime")))
steps = data["BatchInfo"].getNestedQueryResults().get("BatchSteps")[0].getCoreResults()
for row in range(steps.getRowCount()):
duration = utils.prettifyMillis(system.date.millisBetween(steps.getValueAt(row,"starttime"),steps.getValueAt(row,"endtime")))
steps = system.dataset.setValue(steps, row, "duration", duration)
data["BatchStepOverview"] = steps
(upload://8101yt0nU8M3E0SAKpQqn6HUuI0.png)
I need it to also return the following for each step:
the max temperature of the history tag "tt03 return temperature",
the min temperature of the history tag "tt03 return temperature",
The latest value of the final conductivity history tag "ae02 return conductivity"
Here are the Queries in the nested query group
Additionally, here are the names of the data sources I currently have
Here is my version of the script I have modified to attemp this. I think there are several issues, but I can't seem to pinpoint them.
from system.report import QueryResults
# Extract BatchInfo results
res = data["BatchInfo"].getCoreResults()
data["BatchDuration"] = utils.prettifyMillis(system.date.millisBetween(res.getValueAt(0, "starttime"), res.getValueAt(0, "endtime")))
# Get BatchSteps data
steps = data["BatchInfo"].getNestedQueryResults().get("BatchSteps")[0].getCoreResults()
# Iterate through steps
for stepRow in range(steps.getRowCount()):
stepId = steps.getValueAt(stepRow, "stepid") # Step ID for filtering phases
# Get BatchPhases for the current step
phases = data["BatchInfo"].getNestedQueryResults().get("BatchSteps")[0].getNestedQueryResults().get("BatchPhases")[stepRow].getCoreResults()
# Initialize variables for HiTemperature, LoTemperature, and FinalConductivity
hiTemp = None
loTemp = None
finalConductivity = None
# Iterate through phases
for phaseRow in range(phases.getRowCount()):
phaseId = phases.getValueAt(phaseRow, "phasenumber") # Phase ID for filtering parameters
# Get BatchParams for the current phase
batchParams = phases.getNestedQueryResults().get("BatchParams")[phaseRow].getCoreResults()
# Process BatchParams to find HiTemperature, LoTemperature, and FinalConductivity
for paramRow in range(batchParams.getRowCount()):
tagAlias = batchParams.getValueAt(paramRow, "Data Key Alias")
value = batchParams.getValueAt(paramRow, "value") # Assuming the 'value' column holds tag values
if tagAlias == "tt03 return temperature":
if hiTemp is None or value > hiTemp:
hiTemp = value
if loTemp is None or value < loTemp:
loTemp = value
elif tagAlias == "ae02 return conductivity":
finalConductivity = value # Latest conductivity is the last value in this dataset
# Calculate step duration
duration = utils.prettifyMillis(system.date.millisBetween(steps.getValueAt(stepRow, "starttime"), steps.getValueAt(stepRow, "endtime")))
# Update step data with calculated values
steps = system.dataset.setValue(steps, stepRow, "duration", duration)
steps = system.dataset.setValue(steps, stepRow, "HiTemperature", hiTemp)
steps = system.dataset.setValue(steps, stepRow, "LoTemperature", loTemp)
steps = system.dataset.setValue(steps, stepRow, "FinalConductivity", finalConductivity)
# Assign the processed steps dataset to BatchStepOverview
data["BatchStepOverview"] = steps
This returns the error
Feel free to follow up with any clarification that is needed.
Any help is greatly appreciated thanks