Learning to use the queries

I don’t know how to use system.tag.queryTagHistory in the reporting.

I don’t remember this function. I will look it up.

True, you could use the queryTagHistory function to pull in the tag history data which you could then process in script to pull out the highest / latest value for each day within the shift times. I guess my go to for sql stuff is using a query to solve it, but this would certainly work. You’ll need to make sure you’re returning the raw in aggregated data and you need to make sure that the history settings on your counter tags is set to discrete mode in order to ensure the analogue algorithm for removing unnecessary data points is turned off and you’re capturing every change in value.

1 Like

where do you do it? and how?

I don’t understand

edit:
I will look it up later actually
I remember I was going to look up the function in the manual later.

You would need to use a script data source in your report which then calls this function and the code to do the other stuff mentioned, and finally create a dataset from it to then return to the report. If you check out the user manual or IA uni for the reporting module and using a script data source that should help

https://docs.inductiveautomation.com/display/DOC81/Scripting+Data+Source

1 Like

thanks

that makes sense

The function has several parameters that might be useful to you, but looking at the ReturnSize, IntervalHours, IntervalMinutes and AggregationMode is what I think I’d be looking at.

When querying a time period (8am - 5pm), you could say return 1 value, and the aggregation mode would dictate some sort of calculation (i.e. Min/Max, Average, Sum, etc…) for each tag path if the historian captured more than 1 value during the period. In your script, you may have to call this multiple times to get the system to calculate all the different things you needed, but it sounds like you want gross count (is this in a tag - meaning you want Max during period?).

You could do all of this in a script, as is referred, or create more tags that do these queries that reference the date range set. The values would update live as things are occurring, and then the report simply references the tags. Not quite as efficient, as getting a dataset for table display, but you might even consider taking this data from the tags and writing that data to a SQL table and then referencing the table. Then, if you wanted to have a history of each period (shift/day), you could run a report that shows the past week/month/year or whatever to trend it. Or you write all the raw values to a table as was originally discussed and you develop more queries to achieve it.

1 Like

Opps, sorry, didn’t mean to reply to your message @nminchin.

I ended up using tag historian for counts during a shift.

I have tags that keep accumulating as events happen.

Then on an object on the page, I made some parameters with tag historian binding.

They are set for last value.
One has an end range at the start of the shift
One has a realtime of now(30000)
The values for now minus the values for back at the start give me the accumulation in the between time.

I am not sure when I should reset the values or if I let them rollover.
I am going to work with someone to find out what their experience says or hope for a post.

This topic came up just today. See this post, @JordanCClark shows a script that will handle resets or rollovers.

I do that for a tag.
if new minus old is negative, add value max at roll over

My current question is what is the default max roll over?
Ignition integers are 32 bit, so 2,147,483,647 ?
Or should I reset at 1 billion?

It doesn’t matter when you rollover as long as the datatype you use can handle the number you currently have. But, the code will handle a reset or rollover at any time. That’s why I prefer using that script.