Get start and end date from easy chart in realtime mode

I’m trying to script a seamless transition from a realtime trend to a manual trend, i.e. have the manual trend initialise with whatever current values are shown on the realtime trend.

I can get the current start date using:

trend = event.source.parent.getComponent('Trend') startDate = trend.getZoomedStartDate()

And, if the realtime chart is paused, I can get the current end date using:

startDate = trend.getZoomedEndDate()

If the trend is not paused, though, the end date is “None”.

My two ideas are:

  1. If there’s a way to pause the chart using the script, I can pause it, then get the current end date, then switch modes. Is this possible?
  2. If there’s a way to detect within a script whether the chart is paused or not, I can use getZoomedEndDate() when it’s paused, and now() when it’s not paused. Is this possible? (side note - if I’m going to take this approach I need to work out how to convert the python “datetime.datetime.now()” into a java.util.date as I get an error when I try to do this currently. Advice on this one appreciated, although I suspect it’s more of a python/java question than an ignition question)

Open to any other ideas also.

Instead of trying to read the data from the chart, you should read it from the actual source. The realtime trend gets its value from the historical log and then appends the current value to the end. You should do the same by reading the correct period of historical data using system.tag.queryTagHistory and then if required append the current value.

As far as date manipulation goes, the functions in system.date usually allow you to do everything you need.

Thanks Al. I’ve had a look at the system.tag.queryTagHistory function but I’m not sure how I would use it to get what I want. If I read it right, I pass it a tag and a start date and end date, and it returns a dataset with the tag values within that timeframe. My problem is that I don’t know what my end date is.

That said, I had the idea that I can tell if the chart is paused or not, because if it is not, my end date that I read from the chart will be None. So, I read the endDate, if it’s anything other than None I use it as-is, and if it’s None, I set it to system.date.now(). So that’ll solve my problem, but interested to learn more about your suggestion with using system.tag.queryTagHistory in case there’s a more elegant solution to be had.

I think you’re there now. As you said all you need is the start and end date which you can work out as you’ve described. It would be interesting hearing what you’re trying to achieve by switching between trends in this way.

I come from a maintenance background, and at the plant I learnt how to troubleshoot properly, there was a Citect SCADA system in place. I’m not a huge fan of Citect, but this SCADA system was incredibly well developed and maintained. Probably because they had two full-time employees whose only role was SCADA development and improvement.

When something funny was going on with the process, it was quite easy to put together a trend to track some relevant values. I’d watch for the issue to occur, then pause the trend. At that point, I might want to scroll back and forth a little, to see what happened in the leadup to the issue actually presenting. All easy to do.

So I’m trying to develop the same functionality here. I want the user to be able to watch in realtime, then very quickly pause, and scroll back half a span or a full span at a time, then resume realtime monitoring. Right now, the only way to scroll back and forth through the data is to use the easy chart in manual mode. That’s fine, I can switch to manual mode automatically - but when I do, I want the chart to stay where it is. So, I need to get the current start and end date for the realtime data, and initialise my manual mode chart in the same place.

Well, when you’re in Realtime mode you know the endDate (now!) and you can work out the span of the chart by multiplying the chart’s unitCount and unit properties. You could put in a button with code like the following:

chart = event.source.parent.getComponent('Easy Chart')
endDate = system.date.now()
startDate = system.date.addSeconds(endDate, -(chart.unitCount * chart.unit))
chart.chartMode = 0
chart.endDate = endDate
chart.startDate = startDate

You should find this moves you from Realtime to Manual mode as smoothly as possible. Scrolling backwards and forwards is done in a similar manner using appropriate values for startDate and endDate.

2 Likes

Yep, that’s pretty similar to what I ended up doing. I’m still using the getZoomedEndDate() function because if the user pauses a realtime trend before switching to manual mode, I’d like to pick it up from the paused spot. If an end date is returned, I use that, if not, I use system.date.now().

Thanks for the tips!