I have following tag, I'd like to get start and end datetime for each interval has 0 and store in variables in AF analysis:
I don't really understand what you are trying to do, but it sounds like Event Frames could help. You could trigger Event Frames to trigger when 'attribute' = 0. You EF will track the period when the data stream is zero.
Why not use compression to avoid repeating 0 values ?
From the looks of it, those are likely interpolated values in DataLink, since they are shown in whole minutes.
I need interval start and end dates with 0 for further calculation, here is equation I use:
it sets periodend properly(when ValidRange AND RangeClosed are true) but sets the same periodstart for both interval, while for second interval periodstart should start from 10/30/2019 4:22:00 PM, see attachments from Preview Results:
sorry, edited, interval screenshots was vise versus.
Like Dan Fishman said, It looks like your calculation will become much easier if Event Frame is utilized.
With newer AF Analytics, you can create an Event Frame while outputting to an analysis attribute(and thus PI Point DR).
What is PI Event Frame? Please see this YouTube video for your information.
From what I can tell, you are getting the expected result based on your equations. You have selected a time range of the last hour for the TimeEq functions; I assume this is because you expect that these periods of zero values will never be longer than an hour. You have set up the PeriodEnd to give your desired result with the time arguments set so that the function starts at time now and searches backward for an hour to find the last zero value. The problem with PeriodStart is that you start at *-1h and search forward to * so if you have more that one of these zero-value interval events in the hour, then you return the timestamp of the first one rather than the most recent one. I think what you would want to do is find PeriodEnd first, then search backward from here to the previous non-zero time series event, and finally get the time stamp of the next event (presumably with value of zero).
I'm thinking of something like:
Can you try testing something like this and see if it gives the desired results?
Keep in mind that the FindXX functions can be quite resource intensive with long time ranges and dense data so keep an eye on performance as you scale this out. I like the approaches proposed by Jinmo Yi and Roger Palmen below to give a better history of the events and better performance. Another difference between Jinmo and Roger's methods and yours is that the end time of theirs would be the timestamp of the first non-zero-valued time series event after the last zero-valued time series event of the zero-valued interval of data (hopefully that makes sense). Yours will return the timestamp of the final, zero-valued time series event. It's up to you which you feel is more accurate. Using the time series data from your original post, the first interval would have start/end times like below using the two methods.
Jinmo/Roger: Start Time = 15:23, End Time = 15:28
Saken: Start Time = 15:23, End Time = 15:27
You can adjust their method with PrevEvent or yours with NextEvent to get the result of the other method.
Please keep us posted on your progress.
thanks for recommendations!!
I tested NextEvent('SO2', FindNE('SO2',PeriodEnd,'*-1h',0))
and this gives exact start date for each 0 interval - FindNE('SO2, processed',PeriodEnd,'*-1h',0) .
I also tested Roger's suggestions, below works for start date:
if PrevVal('SO2','*') <> 0 and TagVal('SO2','*') = 0 then Timestamp('SO2') else Exit()
but expression below to get end date doesn't give anything:
if PrevVal('SO2','*') = 0 and TagVal('SO2','*') <> 0 then Timestamp('SO2') else Exit()
Also I'm thinking to run it once a day for *-24h from 2AM till 2AM previous day so put schedule at 2:01 AM,
I hope it'll work and check 0 intervals for previous 24 hours.
I think the key question is how you want to use these values. While EventFrames could be an option, you stated you need the output in Analytics variables. I presume for further use in the same analysis?
I depends a bit on data density and scale, but the most performant and scaleable option would be to create two separate analysis writing these timestamps to a PI Point, and use those in subsequent analysis. Just check if value goes from <> 0 to 0 to find the start time; and from 0 to <> 0 to find end time.
PS: Be sure to use the Exit() function and not the NoOutput() function! https://customers.osisoft.com/s/knowledgearticle?knowledgeArticleUrl=KB01127
creating point is quite not convenient since I have 5 more elements I need to have such analysis so creating start and end dates point for each one I think is not efficient.
Hi Roger, Brent
I tested expression below:
this works for start date:
but for end date it doesn't give anything maybe there is something wrong here:
Retrieving data ...