Compare Tag values

Hi,

I am getting data from postgreSql. basically i have created one query tag and getting the values.
query is :
SELECT "Sample"
FROM "Samples"
ORDER BY "Timestamp" desc LIMIT 6

image

Now i want to compare these values in such a way six points in a row are continuously increasing(or decreasing).

so i am writing the tag events script into this nelson rule tag :

but it didn't work.

Please guide me the steps how to do that or another way how to compare the value and writing into the tag.

Your doing a script but your trying to reference tags directly without reading them which will cause all of your "if" statements to fail. I'm also assuming you would want to write a 1 or another value to the "Comparison" tag if the if statement isn't true. My quick take on what I'm assuming your looking for based on the script you typed up is:

tr = ['[~]Nelson rule 3[%d]' % (x) for x in range(6)]
rv = system.tag.readBlocking(tr)
tw = ['[TAGPROVIDER]Comparison[%d]' % (x) for x in range(5)]
wv = []
for x in range(5):
	if rv[x] > rv[x+1]:
		wv.append(0)
	else:
		wv.append(1)
system.tag.writeBlocking(tw,wv)

I sounds as though you are trying to use Nelson rules - Wikipedia number 3.

Paste this script into Script Console and play around with it. It looks like you could do the job in two lines.

arr1 = [1, 2, 3, 4, 5, 6]
arr2 = [1, 2, 4, 3, 5, 6]
arr3 = [1, 2, 3, 3, 5, 6]

print "Is the series strictly increasing?"
print all(x < y for x, y in zip(arr1, arr1[1:]))
print all(x < y for x, y in zip(arr2, arr2[1:]))
print all(x < y for x, y in zip(arr3, arr3[1:]))

print "Is the series strictly decreasing?"
print all(x > y for x, y in zip(arr1, arr1[1:]))
print all(x > y for x, y in zip(arr2, arr2[1:]))
print all(x > y for x, y in zip(arr3, arr3[1:]))

print "Is the series strictly non-increasing?"
print all(x >= y for x, y in zip(arr1, arr1[1:]))
print all(x >= y for x, y in zip(arr2, arr2[1:]))
print all(x >= y for x, y in zip(arr3, arr3[1:]))

print "Is the series strictly non-decreasing?"
print all(x <= y for x, y in zip(arr1, arr1[1:]))
print all(x <= y for x, y in zip(arr2, arr2[1:]))
print all(x <= y for x, y in zip(arr3, arr3[1:]))

For more on this see Python - How to check list monotonicity - Stack Overflow.

Note that you should paste code and not pictures of code in your question. Use the </> button to format it as code.

3 Likes

thanks its working