Thanks for the reply. I’ve gone a bit of a different approach in the end, trying to use as much in-built Ignition functionality as possible.
I used a standard history query to get the data for the desired timeframe, and made sure it is interval based. This is plotted on a Status Chart to show the change over time.
Then on a property change script for the Status Chart i extracted each state as a seperate list, and counted how many were in the list. Because i am only after a percentage, it didn’t matter to me if i was counting hours or minutes.
The scripting wasn’t too nasty in the end, all i really needed was the count() method.
if event.propertyName == "data":
# Get data from status chart
data = event.source.data
colData = []
for row in range(data.rowCount):
colData.append(data.getValueAt(row,"StateNum"))
# end for
# count states
offCount = colData.count(0)
availCount = colData.count(1)
prodCount = colData.count(2)
maintCount = colData.count(3)
notAvailCount = colData.count(4)
# Create dataset from counts
headers = ["Label","Value"]
rows = []
rows.append(["Off",offCount])
rows.append(["Available",availCount])
rows.append(["Producing",prodCount])
rows.append(["Maintenance",maintCount])
rows.append(["Not Available",notAvailCount])
pieData = system.dataset.toDataSet(headers,rows)
event.source.parent.getComponent('Pie Chart').data = pieData
This data is then put into the Pie Chart, allowing the user to choose to display the results in terms of seconds, minutes or hours, depending on how long they are querying over.