>I would like to calculate these statistics for only the time range of the trend. This time range is dynamic and can be set by the user.
You can get Trend's start time and end time by following. (If your display contains Trend1 object)
Thank you very much for your response. Yes, I have been able to change the Trend's start and end time (that's how I was able to get the user to specify the time range), however, how do I calculate the average, min, max, st. dev for the data set within this particular time range?
2 of 2 people found this helpful
One possible way is using PISDK 1.3 Type Library.
Open Microsoft Visual Basic editor > Tools > references > Check PISDK 1.3 Type Library.
You can call pisdk functions by this reference.
There is IPICalculation Interface and you can get the results of PE syntax by this method.
For example getting Maximum
Sub test() Dim srv As Server Dim ipiCalc As IPICalculation Dim vals1 As PIValues Dim expr1 As String, startTime As String, endTime As String Dim testTimes As Variant Dim time As String Dim val As Double startTime = "t+30m" endTime = "t+1h" expr1 = "'cdt158' - 'sinusoid'" Set srv = Servers("localhost") Set ipiCalc = srv ' Get pointer to IPICalculation Interface ' note that the SampleInterval argument is ignored if stRecordedValues is the SampleType Set vals1 = ipiCalc.Calculate(startTime, endTime, expr1, stRecordedValues, "") val = vals1.Summary(startTime, endTime, ArchiveSummaryTypeConstants.astMaximum) MsgBox ("Maximum : " & val) End Sub
I would have really liked to do that (it would have saved me a lot of hassle). Unfortunately, the calculation interval and the overall time interval for this is dynamic, based on how the user resizes the chart, and hence, I don't think it is possible using the method you described. I think I will be using Kenji's method, above, after I fix a small hitch I'm having with the code.
Thank you very much for your time!
This was exactly what I was looking for. Thank you! I was unaware that an iPiCalculation interface existed. My code now looks like this (well, part of it at least!):
Dim ipiCalc As IPICalculation Dim vals1 As PIValues Dim val As Double Set ipiCalc = PISDK.Servers("servernamehere") Set vals1 = ipiCalc.Calculate(TextBox1.Text, TextBox2.Text, "'PreTagHere" & Text1.Contents & "Suffix1' - 'PreTagHere" & Text1.Contents & "Suffix2'", stInterval, "1m") val = vals1.Summary(TextBox1.Text, TextBox2.Text, astAverage, cbTimeWeighted)
This seems to work fine when the chart is set at its default time range. However, when the time range is changed via the user (through a regular resize by selecting a region), I get the following error:
Requested summary range outside PIvalues time range by: x micro seconds
where x is just a number that keeps changing based on the chart range selected.
Any ideas what could be causing this? Just some extra information: The textbox1 and textbox2 contain text strings, either in the form of "*-1 day", for example, or a date and time, eg. "29-Mar-16 9:31:27.846 AM".
Edit: It looks like this error is only thrown if the end date is not set to "*". Any ideas why this would happen?
Thank you for all your help!
1 of 1 people found this helpful
if you set timestamp with seconds for start time or end time, it cause an error.
This is because you have set "1m" for interval. So if there is seconds for start time or end time, there will be no events at that time.
For avoiding it, I think following syntax works.
val = vals1.Summary(vals1.Item(1).TimeStamp, vals1.Item(vals1.Count).TimeStamp, astAverage, cbTimeWeighted)
Absolutely brilliant. It works perfectly now. Thank you!