Taghistory Question

I feel dumb here…

I am trying to use system.tag.queryTagHistory() to get a tag value 5 minutes ago, and the value now, so that I can calculate rate of change.

I feel like I have tried everything under the sun and cant get those values no matter how hard I try

This is what I currently have, but who knows how close it is…
system.tag.queryTagHistory(paths=[tagPath], rangeMinutes=-5, returnSize=2, aggregationMode='LastValue')

Or, even easier, if there is a way to just query the rate of change of the last 5 minutes, I tried using Variance for that but it just returns the current value

Thanks for any help, I always seem to have issues with the right parameters for tagHistory…

For range values I use MinMax for aggregation. the return will be 2 rows (if a change in value) and subtract row1 - row0. If the return rowcount is < 2 then handle no data accordingly.

See I am trying to return the beginning value in this list EVEN if it didnt change.

i.e. if it was 95 at the beginning and is still 95, I want [95,95]

In that case if rowCount < 2 then just show the value in row0.

Try this:

ds = system.tag.queryTagHistory(
	[tagPath],
	startDate=startDate,
	endDate=endDate,
	returnSize=1,
	aggregationMode="MinMax",
	returnFormat='Wide',
	columnNames=columnNames,
	noIterpolation=True,)

So this is only showing me my second to last value (if that makes sense?)

With this as my script:

startDate = system.date.addMinutes(system.date.now(), -5)
endDate = system.date.now()

ds = system.tag.queryTagHistory( [tagPath], start=startDate, end=endDate, returnSize=1, aggregationMode="MinMax", returnFormat='Wide', noIterpolation=True)

For instance if my data did this:

Wed Sep 23 04:45:00 PDT 2020 - 100.0
Wed Sep 23 04:47:00 PDT 2020 - 95.0
Wed Sep 23 04:49:00 PDT 2020 - 90.0

And i ran my call with a startdate and end date of

Start = 'Wed Sep 23 04:45:00 PDT 2020'
End = 'Wed Sep 23 04:50:00 PDT 2020'

It returns

Wed Sep 23 04:45:00 PDT 2020 - 100.0
MY TIMESTAMP NOW - 95.0

Is it any different if you use system.tag.queryTagCalculations() instead? I’ve never had any luck getting the calculations to do what I want using queryTagHistory but queryTagCalculations normally works for me. Try:

ds = system.tag.queryTagCalculations(paths=[tagPath],calculations=['MinMax'],rangeMinutes=5,noIterpolation=True)

Similar weird results

With this as my script:

ds = system.tag.queryTagCalculations(paths=[tagPath],calculations=['MinMax'],rangeMinutes=5,noIterpolation=True)

For instance if my data did this:

Wed Sep 23 04:45:00 PDT 2020 - 90.0
Wed Sep 23 04:47:00 PDT 2020 - 50.0
Wed Sep 23 04:49:00 PDT 2020 - 25.0
Wed Sep 23 04:53:00 PDT 2020 - 18.0

If I execute it at Wed Sep 23 04:55:00 PDT 2020

MyTagName - 25.0

It should return 2 rows of data, the first being your minimum and second max. Are you looping through both or calling them both out?

I am printing both columns with, but looping through still only shows one

print ds.getColumnAsList(0)
print ds.getColumnAsList(1)

Thats odd, if I run

data = system.tag.queryTagCalculations(paths=path,calculations=['MinMax'],rangeMinutes=5)

print data.getColumnAsList(0)
print data.getColumnAsList(1)

data = system.dataset.toPyDataSet(data)
for x in data:
	print x[1]

I get:

[MyTagName, MyTagName]
[46.36785125732422, 0.0]
46.3678512573
0.0

What is your sample mode? Mine is On Change

That could be the difference. With the tag I used it has a 10 second rate.

I’d be willing to bet thats it. I just tried it again using a tag that is on change and got back:

[MyTagName]
[50]
50

But just tried it out on another tag that is on a 10 second rate but hasn’t been running and got the same results. If the value doesn’t change MinMax only returns 1 value.