tinklerj

Most efficient way to get latest good value for a tag

Discussion created by tinklerj on Oct 2, 2014
Latest reply on Oct 2, 2014 by kilgored

What is the most efficient way, using PI-SDK, to get the latest GOOD archive event for a tag at or before a specified time?

 

Bearing in mind that (a) there may not be any good event, but lots of bad ones, going back for weeks or years; (b) there may be no good events at all for the tag right back to the earliest event (presumably a Pt Created digital state).

 

Alternatives I have looked at are:

 

1. In a loop, keep calling PIPoint.Data.ArcValue with mode rtAtOrBefore.  If bad event (and not Pt Created) switch to mode rtBefore and keep calling ArcValue until a good event is found.

 

2. In a loop, call PIPoint.Data.RecordedValues for some arbitrary interval (say a week) and look at all the events retrieved (starting with the latest) to find a good value.  If no values in interval, use ArcValue (rtBefore) to see if there are any more values that aren't Pt Created.  If no good value found, look at the interval before, and so on.

 

Bearing in mind that 99% of the time, there will be a good value at or just before the time specified, so method 1 is going to be more efficient than method 2 which in the simplest case retrieves a lot more values.  But in that 1% of cases where the tag has had nothing but lots of bad values for a long time, then an awful lot of wire calls will be necessary and could hold up the application.

 

What I want is a way to get the server to do the work of ignoring bad events, cutting down the number of wire calls in the worst case.  Can't see any way to do this though.

Outcomes