Customizing tables, adjustable date

I wanted to sharre this here for 2 reasons.
1., incase someone else is looking for something similar (as i was)
2. incase there is room for improvement/optimization

i built this script as a table so i can poll the history of some tags from tag historian database based on the dates in a trend slider. this script is in the table of the data and drops it into a new table that is on the forefront.
I did this because grabbing the dataset directly from the trend was giving me min/max values not closest value like i wanted.
It allows converting data between metric/imperial values as well and then i can export it.
This is for Pressure and temperature. As you can see, the values in the database for history are saved as Metric.
Metric property is 0 for metric, 1 for imperial, comes from a dropdown list.

Also the Date and the time are separated in the formatting.

if event.propertyName == "data" or event.propertyName == "metric":
	# bring dataset from this table into script
	dats =
	# metric or imperial? if metric do this
	if event.source.metric == 0:	
		newhdr = ["yyyy-mm-dd", "hh:mm:ss", "Pressure (kPa)", "Temp. (degC)"]
		pconv = 1.0
		tcon1 = 1.0
		tcon2 = 0.0
	# metric or imperial? if imperial do this
	if event.source.metric == 1:	
		newhdr = ["yyyy-mm-dd", "hh:mm:ss", "Pressure (psi)", "Temp. (degF)"]
		pconv = 0.145033
		tcon1 = 1.8
		tcon2 = 32.0
	newdat = []
	# get the data from the old dataset, modify it, and then place it into the new dataset row by row
	for row in range(dats.rowCount):
		a =, 0), "yyyy-MM-dd")
		b =, 0), "hh:mm:ss")
		c = dats.getValueAt(row, 1)
		cc = (c * pconv)
		d = dats.getValueAt(row, 2)
		dd = ((d * tcon1) + tcon2)
		newdat.append([a, b, cc, dd])
	# build the new dataset with headers and data
	dataset = system.dataset.toDataSet(newhdr, newdat)
	# this sends the new modified dataset to the new table on top of the master table (this is the master table)
	event.source.parent.getComponent('Table2').data = dataset

You don’t have to use two tables. Just add a custom dataset property to one, where you bring in the raw data, then process it and write it to the table’s data property.

1 Like

Also if you have a property called ‘metric’, I think it is better to make this mean metric when it is true i.e. 1, not metric when it is 0.

yes i did change that, i should have called this imperial, as the data comes in as metric in the first place.

good point thank you