Report Script PySequence error

Hello,

I was wondering if you could help me with the below Script
> Header = [‘Time’,‘Fault’,‘Reason’]

statusdataset = []
rawDataset = data[‘Bay 1’].getCoreResults()
i=0

for row in range(4):
i=i+1
Chill = "chiller status " + str(i)
chiller = rawDataset.getValueAt(row,Chill)
time = rawDataset.getValueAt(row,‘t_stamp’)
reason = “Chiller Faulted”
rowLen= rawDataset.rowCount
for row in range(rowLen):
if chiller ==3:
statusdataset.append([time,chiller,reason])
statusdataset= system.dataset.toDataSet(Header,statusdataset)
data[‘Chiller’ + str(i)] = statusdataset

I get an error that states:
TypeError: toDataSet(): 2nd arg can’t be coerced to org.python.core.PySequence

However if I move the below lines to the first for loop, i no longer get the error, But I only get the data from the last iteration of the for loop
statusdataset= system.dataset.toDataSet(Header,statusdataset)

  	data['Chiller' + str(i)] = statusdataset

So I have 4 history tags in a Tag Historian Query , I than have the above script to try and only take the values from the tag history if it is = to 3 on all 4 history tags.

I have tried the script for just one tag without the for loop and it gave me all of the data from the 4 tags in one dataset, but I would like to filter them out into 4 different datatypes. For ref, the code that kinda worked is below

Header = [‘Time’,‘Fault’,‘Reason’]
statusdataset = []
rawDataset = data[‘Bay 1’].getCoreResults()

for row in range(rawDataset.rowCount):
chiller = rawDataset.getValueAt(row,‘Chiller Status’)
time = rawDataset.getValueAt(row,‘t_stamp’)
reason = “Chiller Faulted”
if chiller ==3:
statusdataset.append([time,chiller,reason])

statusdataset= system.dataset.toDataSet(Header,statusdataset)
data[‘newChiller’] = statusdataset

I think your statusdataset is throwing your logic off.
Ln1: statusdataset initialized as list
Ln14: statusdataset gets a list appended
Ln15: statusdataset turned into a dataset obj

On second pass Ln14 should fail as it’s no longer a list object

	
rawDataset = data['Bay 1'].getCoreResults()
i=0

for row in range(4):
		i=i+1
        statusdataset = [] #this needs to be reinitialized on each iteration
		Chill = "chiller status " + str(i)
		chiller = rawDataset.getValueAt(row,Chill)
		time = rawDataset.getValueAt(row,'t_stamp')
		reason = "Chiller Faulted"
		rowLen= rawDataset.rowCount
		for row in range(rowLen):	
				if chiller ==3:
						statusdataset.append([time,chiller,reason])
		statusdataset= system.dataset.toDataSet(Header,statusdataset)
		data['Chiller' + str(i)] = statusdataset
1 Like

Worked like a charm, Thank you