4 Replies Latest reply on May 14, 2010 5:40 AM by jnissisolutions

# Calculate without Spikes

I am trying to decide what the best strategy would be to use the Calculate function or some other SDK function to get a max value for an expression excluding spikes in the results of the expression.

So a simple example is to find the max of tag1+tag2 within a month’s date range ignoring any 2 second duration where the expression (tag1+tag2) has a radical negative AND positive slope.

It seems like FilteredSummaries should work but I am a little baffled about how to apply the appropriate summary expression and how to get the correct output.

Thanks, Dan

• ###### Re: Calculate without Spikes

FilteredSummaries would be useful if you are intending to get max, min value from a tag, with a filter expression to filter unwanted values to be used in the calculation. On the other hand, if you are looking for ways to find summary values from an expression, you should look at ExpressionSummaries (which calculates the summary results (max, min, total, etc) of an expression.

Dan Jablonski

So a simple example is to find the max of tag1+tag2 within a month’s date range ignoring any 2 second duration where the expression (tag1+tag2) has a radical negative AND positive slope.

I am not sure how exactly we can express the condition "2 seconds duration where expression has radical negative AND positive slope" as a PE expression. Assuming that you want to ignore a value that exceeds a certain limit instead, the expression can be like "IF ('tag1' + 'tag2' <2000) THEN 'tag1' + 'tag2' ELSE NoOutput()"

Using that in ExpressionSummaries, to get a max of tag1 + tag2 in 1 month will be something like

`PISDK mysdk = new PISDK();Server mySrv = mysdk.Servers["DevPI"];IPICalculation myCalc = (PISDK.IPICalculation)mySrv;PIValues values;PISDKCommon.NamedValues myVals;.....myVals = myCalc.ExpressionSummaries("*-30d",                            "*",                            "30d",                            "IF ('tag1' + 'tag2' <2000) THEN 'tag1' + 'tag2' ELSE NoOutput()",                            PISDK.ArchiveSummariesTypeConstants.asMaximum,                            PISDK.CalculationBasisConstants.cbEventWeighted,                            PISDK.SampleTypeConstants.stRecordedValues,                            null,                            null);String sumType = "Maximum";object sumTypeObj = sumtype;values = (PIValues)myVals.get_Item(ref sumtypeObj).Value;foreach (PIValue val in myVal){    ....}`

• ###### Re: Calculate without Spikes

Have you considered using "on-event PE tags" to filter the undesired values from your 2 source tags, and then have another PE tag calculate the sum? While that last part might be done programmatically, it seems to me like the filtering that takes place before the sum operation might be worth being archived (in PE tags) as opposed to being calculated on the fly within a PI SDK application. Other people/applications might see the need for the filtered version of these tags, and having them computed/stored directly on the PI Server might turn in handy...

• ###### Re: Calculate without Spikes

Michael,

It's been my experience with a larger base population of tags, that building a variety of calculated tags for stepwise application can really confuse things in the database.

Thanks for the response though, Dan

• ###### Re: Calculate without Spikes

Han,

I am using ExpressionSummaries to find the max, but qualifying the max based on the rule that I metioned (size of slope on either side of 2 seconds) is what I need to figure out.  I don't think I can do this in one expression.

What I have decided to do is use Calculate, sequences through the result set looking for the max, qualify the max by using the rule I mentioned and then reducing the result of that segment if it fails and reruning the search for the max in the modified set.  I think it will have good performance as there will be only a small number of spikes to exclude per set.

It would be nice to have a ExpressionSummaries command with a parameter of a filter similar to FilteredSummaries, but operating on an Expression instead of a single tag.

Thanks, Dan