1 Reply Latest reply on Mar 12, 2018 10:59 PM by lmurphy

    Run Analysis using AFSDK


      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

          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


          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!