Trend Start and End times could really only be dynamically set through code. You can use any valid PI timestamp in either the UI or via code. As you are performing an AF Analysis to get your peak usage timestamp, what type of data reference is the output being written to?
You could dynamically set the start and end time of the trend with a little bit of VBA code reading from a Value object that contains the output of your analysis. I tried this using a string tag to receive my analysis output, mapped that tag to a Value symbol on my display, and used the following bit of code:
Dim peak_time As Variant Dim trendStartTime As Date Dim trendEndTime As Date Dim vrdate As Variant Dim vrstatus As Variant peak_time = Value1.GetValue(vrdate, vrstatus) trendStartTime = Format(CDate(peak_time), "dd/mm/yyyy") trendEndTime = DateAdd("d", 1, trendStartTime) Trend1.SetStartAndEndTime CStr(trendStartTime), CStr(trendEndTime)
Initially I tried using a tag of type Timestamp for my analysis output, but couldn't properly read the value in ProcessBook VBA, hence the use of the string tag instead.
Thank you. This method ended up working.
I did get an error when I first tried it though. The Timestamp function returns both the date and the time, but only the date is needed. So, I extracted the month, day, and year from the timestamp and concatenated them into a string in order for this code to work.
I would do it in PI Coresight and use Event Frames. You can generate an Event Frame around the month peak usage, then you can simply select the Event Frame in PI Coresight to set the time range as you need.
You could have a script running to modify the start/end time of the Event Frame if the peak moves throughout the month. This way your logic isn't tied to a single display, it is accessible by multiple PI tools.
both options presented above sound like a good solution to me.
If you decide in favor for Processbook, please also have a look at the Processbook programmers reference (link below) for the syntax of the methods to set your timerange:
p.196 -- Display.Settimerange
p.393 -- trend.settimerange