[Tag History Binding] Filtering out certain data

I would like to excludr any "F000 - No Fault" rows from this table. Any tips for a newb? Thanks in advance. Using a tag history binding for the data.


Add a script transform to filter out the data that you don't want to display in the table.

Something like this:

dsData = []
headers = system.dataset.getColumnHeaders(value)


dsData = [[value.getValueAt(row,"Description"),value.getValueAt(row,"Time Stamp")] for row in range(value.getRowCount()) if value.getValueAt(row,"Description") != "F000 - No Fault"]

filteredDs = system.dataset.toDataSet(headers,dsData)

Thanks, It sort of worked. It filtered out the rows containing the unwanted string ("F000 - No Fault") but it swapped the data between columns. All of the "Time Stamp" data is now under "Description" and vice versa. I can easily mask that by changing the column's alias in the table's column properties. But would still like to understand how that happened.

Here is what the script looks like now:

def transform(self, value, quality, timestamp):
	dsData = []
	headers = system.dataset.getColumnHeaders(value)
	
	
	dsData =[[value.getValueAt(row,"Description"),value.getValueAt(row,"t_stamp")] 
	for row in range(value.getRowCount()) 
	if value.getValueAt(row,"Description") != "  F000 - No Fault"]
#	
	filteredDs = system.dataset.toDataSet(headers,dsData)
#	
	
	return filteredDs

image

Nevermind, changed the order of the rows in the script and it fixed it.

def transform(self, value, quality, timestamp):
	dsData = []
	headers = system.dataset.getColumnHeaders(value)
	
	
	dsData = [[value.getValueAt(row,"t_stamp"),value.getValueAt(row,"Description")] 
	for row in range(value.getRowCount()) 
	if value.getValueAt(row,"Description") != "  F000 - No Fault"]
	
	filteredDs = system.dataset.toDataSet(headers,dsData)
	
	
	return filteredDs

That would have been because that's the order that the system.dataset.getColumnHeaders function returned the headers in - you could always manually make a list of headers to be sure of the order.

Your script, as posted, seems to have multiple syntax errors--indentation and missing colons, in particular. It cannot possibly be what you are running. If you are running some other script for which you want help, post that instead.

def transform(self, value, quality, timestamp):
	dsData = []
	headers = system.dataset.getColumnHeaders(value)
	
	
	dsData = [[value.getValueAt(row,"t_stamp"),value.getValueAt(row,"Description")] 
	
	for row in range(value.getRowCount()) 
	if value.getValueAt(row,"Description") != "  F000 - No Fault" ]
	
	filteredDs = system.dataset.toDataSet(headers,dsData)
	
	return filteredDs	

The example that I gave you used python list comprehension structure which is designed to be a single line of code. It cannot just be broken up across multiple lines.

If you want it spaced out for readability, the syntax will be different.

for row in range(value.getRowCount()):
	if value.getValueAt(row,"Description") != "F000 - No Fault":
		dsData.append([value.getValueAt(row,"t_stamp"),value.getValueAt(row,"Description")])