I have a dual column (t_stamp, value) dataset tag that is part of a UDT and I want another tag in the UDT to be the same data, but transposed so I can show it in a horizontal table, rather than a vertical one.
So, I have this script that works in the script console, but when called from the tag in the UDT with runScript
I get an error when it tries to convert the tag path to an int, for whatever reason. ("cannot convert path into type: class java.lang.Integer")
def transposeDualColumnDataset(path):
'''
Transpose a 2-column (t_stamp, value) dataset into a single-row dataset.
Args:
path (string) : path to the dataset to transpose
Returns:
dataset (dataset) : resulting single-row dataset. Headers are t_stamp, column values for the row are original dataset row values
'''
dataset = system.tag.readBlocking([path])[0].value
#initialize empty dataset headers and data lists
headers = []
data = []
#dataset given has exactly 2 columns
if dataset.columnCount == 2:
#get row count
rowCount = dataset.rowCount
#for each row
for row in range(rowCount):
#add the t_stamp as a header
headers.append([str(dataset.getValueAt(row,'t_stamp'))])
#add each value to the row
data.append([dataset.getValueAt(row,'value')])
return system.dataset.toDataSet(headers, [data])
Or, if there's a better way to do this (in Vision), please let me know.