7 Replies Latest reply on Dec 19, 2018 4:11 PM by Rick Davin

    How to create correct ConfigString


      Hey guys,


      I need to create Ad Hoc Analysis on my c# app.


      I need to create this, execute, get results and remove.


      So i readed AFSdk docs... and i'm in trouble with ConfigStrings...


      Here is my configString example:

      "LV := 'LVi'/100;\r\nHV := 'HVi'/100;\r\nAVG := (LV+HV)/2;"

      Error: Cannot run this analysis rule because its configuration is invalid.  See ConfigurationExceptions for details.


      And i've tried to get configstring from one analysis configured in PI SystemExplorer... and i get...


      "LV := '{dbdbb8ae-ff59-4262-877f-a4c466a5975c};LVi'/100;...


      how can i get this ID ?! which is the correct form to add ConfigString ?! there is any methods to add line to config on the analysis services !?

        • Re: How to create correct ConfigString

          Hey Alan,


          Before jumping into the details on how to do this, can we get more details on your AF SDK application?


          How many analyses are you planning on creating, executing and deleting? What's the time frame from creation to deletion? How complex are these analyses? Do they use asset analytics functions?




            • Re: How to create correct ConfigString

              Hello Sebastien,

              Thanks for the awnser !

              I'm planning to get about 50 tanks.... and i need only to check if my tank volume is between superior and inferior limits.


              The details:

              I have one element (tank) and i need to keep tank volume between (SUPERIOR LIMIT AND INFERIOR LIMIT) see the image below:



              And i need to compute how many time (in seconds) the volume is NOT between Superior and Inferior limits. So i create an analysis...


              I get the calculus in the period defined by: st (Start Time) and et (End Time). If i specify st and et... and evalute ... everything works great... see below


              But i need to input st and et in runtime... on my app


              How can i do that ?! Is there another way to make this calculus work ?! Performance Equation, AFFilteredSummaries !? I can do it without analysis... (with a function)
              AF SDK have this function TimeLT and TimeGT !?


                • Re: How to create correct ConfigString
                  Dan Fishman

                  You could use the AF SDK methods described in the AFCaluclation Class.  In particular, you might find the Calculate at times method useful.  Using AFCalculation you should be able to reuse the same expression and just change your target. 

                  1 of 1 people found this helpful
                  • Re: How to create correct ConfigString

                    Alan, why do you need it to be calculated at runtime?


                    Regarding the ConfigString, it's hard to guess what's wrong as we don't have access to the full code or the referenced AF Element. Something you can do is to create an analysis manually, get it through the AF SDK and save it to be used by your code.

                      • Re: How to create correct ConfigString

                        It must be at runtime because the user need to specify the timespan he needs.

                        An example:

                        "How many seconds my tank vol is outside the range on last 7days ?! or 3 days? or today ?!" the time range must be flexible...


                        I've tried to do what u recommended:

                        "Something you can do is to create an analysis manually, get it through the AF SDK and save it to be used by your code."

                        I have created the analysis manually... and on code set the time interval... but it's persisted on AF Attributes... in my opinion it can generates some resource competition or deadlock problems... i need a more robust solution.

                          • Re: How to create correct ConfigString

                            I see... So, you should definitely go with Dan Fishman's answer and use the AFCalculation class. Create an Analysis just to run a single calculation is not only overkill but also bad practice as it involves a lot of moving parts that are not well suited for concurrency scenarios of user-oriented applications.

                            • Re: How to create correct ConfigString
                              Rick Davin

                              I would make many suggestions including changing the layout of your Tank elements.  Your limits are peer attributes to the Volume measurement.  This may work on a small, simple asset but it may not scale out very well.  Consider these very real possibilities:


                              • You only have Low and High limits.  What about Low-Low and High-High, not just for tanks but other assets?
                              • What about more complex assets with a dozen or more measurements?  Will you then want 2 to 4 limits for each measurement to also be on the root of the element?


                              What I would suggest is you investigate attribute TRAITS.  The Limit related traits would create child attributes to the measurement in question.  And you may have any combination of Low, High, Low-Low, and High-High.


                              The next advice is if you have no concerns about tag counts.  You could create an analysis for each measurement to check if it is within limits.  A simple Boolean or a 0 or 1 might suffice just to declare that you are within limits or not.  However, you may want to consider which limit is in violation.  In that case, you may consider mapping to a digital state set (starting at 0 and incrementing by 1), or to a integer value of { -2, -1, 0, 1, 2 } which would mean { Low-Low violation, Low violation, OK or within limits, High violation, High-High violation }.


                              The important things are to do:

                              • Have your analysis be triggered on any event change of the measurement OR its limit traits
                              • Output the result to a PI Point so that the condition is persisted for faster retrieval


                              Then when you are wanting to see how long that measurement was performing within limits, you check to see when that output PI Point was OK.  If you want to see how long that measurement was outside of limits, you check to see when the PI Point was not OK.  The key is that it is done in 2 stages.  The first stage calculates whether the measurement is within limits and saves that to an output PI Point.  The second stage then reads that output PI Point over a time range.