Show Only "True" Rows in Perspective Table

Hello! I have 2 questions for the same perspective table.

  1. How can I only show ONLY "True" rows in my perspective table? I wrote a script to add a new column that's shows which values are within a specific range here by Add Transform+:
def transform(self, value, quality, timestamp):
inrangelist = []
	colCount = value.getColumnCount()
	for row in range(value.getRowCount()):
		if 16 < value.getValueAt(row,1) < 27:
			inrangelist.append(True)
		else:	
			inrangelist.append(False)
	newDataset = system.dataset.addColumn(value, colCount, inrangelist, "results", bool)	
	return newDataset

But I only want to show which rows are "True". If I remove the else: statement I get a Error_ScriptEval numbers of values does not match number of rows.

  1. In the same Table how can I convert my "t_stamp" column to a date and time that's readable in Python. Existing t_stamp:1680700299058
    I need the time readable to reflect: Wed Apr 05 2023 09:11:39 GMT-0400 (Eastern Daylight Time)
    Thanks

Tip: edit your question, select the code block and click the </> code formatting button. It will preserve indentation and apply syntax highlighting.
Use 2. rather than 2) for numbered list.

One of many options:

def transform(self, value, quality, timestamp):
	in_range_values = 0
	out_of_range_indices = []
	colCount = value.getColumnCount()
	for row in range(value.getRowCount()):
		if 16 < value.getValueAt(row,1) < 27:
			in_range_values += 1
		else:	
			out_of_range_indices.append(row)
	rowsRemoved = system.dataset.deleteRows(value, out_of_range_indices)
	newDataset = system.dataset.addColumn(rowsRemoved, colCount, in_range_values, "results", bool)	
	return newDataset

Ignition Extensions, my free convenience function module, also adds a system.dataset.filter function, so you could rewrite your code as:

def transform(self, value, quality, timestamp):
	in_range_values = []
	colCount = value.getColumnCount()
	for row in range(value.getRowCount()):
		in_range_values.append(16 < value.getValueAt(row,1) < 27)
	addedColumn = system.dataset.addColumn(rowsRemoved, colCount, in_range_values, "results", bool)
	newDataset = system.dataset.filter(addedColumn, lambda **columns: columns["results"])
	return newDataset
1 Like

Assuming you don't need to add the results column anymore, since it's all gonna be True anyway:

def transform(self, value, quality, timestamp):
    return [row for row in system.dataset.toPyDataSet(value) if 16 < row[1] < 27]

Maybe not the most efficient, but it's simple and clear, which unless you notice a difference is probably more important than performances.

edit: You may or may not need to re-transform things back to a dataset. In which case:

def transform(self, value, quality, timestamp):
    headers = value.getColumnNames()
    data = [row for row in system.dataset.toPyDataSet(value) if 16 < row[1] < 27] 
    return system.dataset.toDataSet(headers, data)
2 Likes