5 Replies Latest reply on May 4, 2016 5:34 PM by Al_Gagnon

    AF SDK - PctGood

    Al_Gagnon

      How can i get the PctGood of a tag, between a certain timeframe, for a tag using AF SDK?

        • Re: AF SDK - PctGood
          bshang

          You can use AFCalculation.PercentTrue Method and for the expression, pass in "IsBad('tagname')=false" or any other accepted PE syntax.

            • Re: AF SDK - PctGood
              pthivierge

              This is Interesting Barry! I was curious as I never needed  to use PercentGood yet with the AF SDK, and this is indeed the method to use, except if you are already using summaries (e.g. PIPoint.FilteredSummaries ) because you can request PercentGood to be returned based on the AFSummaryTypes you are asking for.  While searching I also found this page which I believe can be quite useful if you are coming from a PI SDK angle PI SDK Equivalents.

               

              Hope this adds to this discussion

                • Re: AF SDK - PctGood
                  gregor

                  Hi Al, Barry and Patrice,

                   

                  I found this interesting too and tried this on my own. My first solution is applying the math client side and the second one is using the approach Patrice had in mind. The beauty with that is that summaries are evaluated server side which can help a lot to reduce the network traffic compared to example # 1

                   

                  Example 1

                          static void Main(string[] args)
                          {
                              PIServer srv = new PIServers()["PIServer"];
                              PIPoint pt = PIPoint.FindPIPoint(srv, "CDT158");
                              AFTime omega = AFTime.NowInWholeSeconds;
                              AFTime alpha = omega.LocalTime.AddHours(-8);
                              AFTimeRange tRange = new AFTimeRange(alpha, omega);
                              AFValues values = pt.RecordedValues(tRange, AFBoundaryType.Inside, String.Empty, true, Int32.MaxValue);
                              Double iGood = 0;
                              foreach (AFValue value in values)
                              {
                                  if (value.Status == AFValueStatus.Good) { iGood += 1; }
                              }
                              Double pctGood = 100 * iGood / values.Count;
                              Console.WriteLine("{0}% good values", pctGood);
                              Console.ReadKey();
                          }
                  

                      

                  Example 2

                          static void Main(string[] args)
                          {
                              PIServer srv = new PIServers()["PIServer"];
                              PIPoint pt = PIPoint.FindPIPoint(srv, "CDT158");
                              AFTime omega = AFTime.NowInWholeSeconds;
                              AFTime alpha = omega.LocalTime.AddHours(-8);
                              AFTimeRange tRange = new AFTimeRange(alpha, omega);, 0);
                              IDictionary<AFSummaryTypes, AFValue> summary = pt.Summary(tRange, AFSummaryTypes.PercentGood, AFCalculationBasis.TimeWeighted, AFTimestampCalculation.MostRecentTime);
                              AFValue pctGood = summary[AFSummaryTypes.PercentGood];
                              Console.WriteLine("PctGood is {0}", pctGood.Value);
                              Console.ReadKey();
                          }
                  
              • Re: AF SDK - PctGood
                Al_Gagnon

                hi everyone,

                 

                i have tried what you have suggested, and while i get a result back, its not what i am expecting.

                Essentially i am trying to match the results to the following query without any success.

                 

                SELECT "tag", "pctgood" , "calcbasis" FROM "piarchive".."picount"

                        WHERE time = '*' AND timestep = '30d' and tag in (

                select tag from pipoint..pipoint where pointsource = 'INSERT POINT SOURCE HERE') and pctgood <=70

                 

                This query will give me a bunch of tags with their pctGood for the time range.  However when i use the examples you have all provided, i am never able to match the results.

                 

                Thoughts?