3 Replies Latest reply on Mar 28, 2018 3:23 PM by lmurphy

    Run Analysis using AFSDK

    nthorson

      I have a scenario where out of the box Analysis scheduling is not meeting my needs (or at least I don't know how to configure it to do so).  I am currently using Analysis 2016 R2.  Here is the basic scenario.

       

      1.  Custom Windows Service pulls data from an FTP every 24 hours and writes data to PI

      2.  Service writes data to 2 PI Points, i.e. pi_point_1 and pi_point_2

      3.  The values have 15 minute intervals, so every 24 hours 96 new values are written to each PI Point

      4.  From here I want to use Analysis to do some additional processing of the data and write the results to a new PI Point.  For simplicity's sake, assume the following.

       

      pi_point_3 = pi_point_1 + pi_point_2

       

      Problem is if I use event based updates, I have to use both pi_point_1 and pi_point_2 as triggers.  Therefore, I get two values with the same timestamp for pi_point_3.  If I could configure Analysis to use "Replace" instead of "Insert" like you can with the AFSDK, it would not be a problem. However, I don't see anywhere where I can do that.  Furthermore, I can't use periodic updates because the data comes in up to 24 hours after a value's timestamp.  If I could set a delay on the periodic updates, it would fix the problem. 

       

      The only solution I see is to have my service execute the Analysis using the AFSDK.  However, I am not sure how to do so.  Is there example code or tutorial on this capability?

        • Re: Run Analysis using AFSDK
          lmurphy

          Hi Nick,

           

          I would recommend upgrading to Analysis Service 2017 R2. In this version, you can enable automatic recalculation for analyses.

           

          As a test, I set up the following PowerShell script to trigger a backfill of a day's data for 2 separate tags: inputtag1 and inputtag2:

           

          $con = Connect-PIDataArchive -PIDataArchiveMachineName lmurphy7910

           

          $value = 0
          for($ii=0;$ii -lt 96;$ii++)
          {
              Add-PIValue -PointName inputtag1 -Value $value -Time (Get-Date).AddDays(-2).Date.AddMinutes($ii*15) -Connection $con
              Add-PIValue -PointName inputtag2 -Value ($value*2) -Time (Get-Date).AddDays(-2).Date.AddMinutes($ii*15) -Connection $con
              $value++
          }
          }
          

           

          The following analysis was set up to add the values:

           

           

          Notice the boxed symbol indicating the analysis is set up for automatic recalculation. Also, the analysis is only triggered on only one of the inputs.

           

          We can then see the output only has one timestamp per input:

           

          Hope this helps!

           

          Liam

          2 of 2 people found this helpful
            • Re: Run Analysis using AFSDK
              nthorson

              Thanks for the feedback!  This seems to be working.  Originally I was concerned pi_point_1 would get updated first and kick off the analysis before pi_point_2 was updated.  However, I learned there is a 5 second delay between the time the point is updated and when the analysis runs.  Therefore, it should not be an issue.

                • Re: Run Analysis using AFSDK
                  lmurphy

                  Hi Nick,

                   

                  Yes, that is correct. The delay is configurable as well, using the \\<AFServer>\Configuration\OSIsoft\PIANO\AnalysisService\ServiceConfiguration|ServiceConfiguration attribute as well. If you want to alter the delay, you can change the following parameter and restart the Analysis Service:

                   

                  <CalculationWaitTimeInSeconds>5</CalculationWaitTimeInSeconds>

                   

                  That being said, if 5 seconds is enough to account for the remaining data flowing in, then I wouldn't recommend delaying the calculations unless necessary for a different use case.