How to access currentValue and previousValue from value change script

I have a dataset tag with two columns, t_stamp and weight. It is 120 rows long. I want to be able to determine if the current value, in this case row 120, is greater than the previous value, in this case row 119. I want to only compare the weights.

Here is the screenshot of the bottom of dataset. Again the last row is the latest data.

image

Here is the screenshot of my thoughts on accessing the current and previous value

Both values will be the entire dataset at that point in time, not a "delta". So you will have to explicitly ask for the last row (as in dataset.rowCount - 1) if your process in fact guarantees that the last row will be the most recently updated.

1 Like

He's presumably using my recorder, so yes, it is.

1 Like

Haha, you are correct

I recommend an expression tag (in event driven mode) in the folder adjacent to the recorder tag, with this:

transform(
	{[.]recordertag},
	transform(
		len(value()),
		if(
			value() > 1,
			value(1)[value()-1, 'weight'] - value(1)[value()-2, 'weight'],
			0.0
		)
	)
)

No script.

If you want to be really precise, use the inverse delta milliseconds of the t_stamp column to adjust for value delivery clock skew. (Probably not stable for adjacent samples, but should be really good across multiple samples.)

1 Like