9 Replies Latest reply on Dec 21, 2016 6:50 PM by pmartin

    set True For value in analysis

    MikeSpath

      Hello:

      I'm trying to figure out how to set the True For value in an analysis via the SDK

      In the help file I found this about Time Rule but not sure if this is correct neighborhood

      On my AF server I have an analysis rule that has a number of start triggers, each has there own expression (made up of template attributes) and the True For value is setup for each different values, units (eg. 5 min., 20 sec., etc..). I'm not sure what the "RulePlugins" are..

       

      // Set the Analysis Rule and Time Rule

      myAnalysis.AnalysisRulePlugIn = myPISystem.AnalysisRulePlugIns["Imbalance"];

      myAnalysis.TimeRulePlugIn = myPISystem.TimeRulePlugIns["Periodic"];


      // Configure the Time Rule

      string config = "Frequency=3600";

      AFTimeRule timeRule;

      timeRule = myAnalysis.TimeRule;

      timeRule.ConfigString = config;

        • Re: set True For value in analysis
          gregor

          Hello Mike,

           

          Can you please explain a little more detailed what you like to accomplish via custom AF SDK code? Maybe you can build a mock-up in PI System Explorer and take some screenshots. This may already help yourself in finding out what it takes to do the same programmatically. 

          • Re: set True For value in analysis
            pmartin

            Hi Mike,

             

            It is possible to set the Time True (another name for True for) parameter in the configstring of a particular AnalysisRule.  You will likely want to set this for your PerformanceEquation AnalysisRule. 

             

            Here is the format I have for one of my existing analyses:

            "@group(\"Start triggers\") @timetrue(\"0\")\r\nStartTrigger1 := 'sinusoid' > 500;"

             

            The value for timetrue is in seconds.

            1 of 1 people found this helpful
            • Re: set True For value in analysis
              MikeSpath

              I have a followup question to setting the timetrue parameter: how would you edit this parameter? First get the Analysis then rewrite the config screen?

                • Re: set True For value in analysis
                  pmartin

                  Yeah, that's correct.  Find the AnalysisRule that you want to change the parameter for and modify the config string.

                    • Re: set True For value in analysis
                      MikeSpath

                      Thanks for the help, I'm looking through the af sdk help: I have a feeling I'm on the wrong track....

                       

                       

                      string config = "Frequency=3600";

                       

                      AFTimeRule timeRule;

                       

                       

                      timeRule = item.TimeRule;

                       

                      timeRule.ConfigString = config;

                       

                       

                       

                        • Re: set True For value in analysis
                          pmartin

                          Hi Mike,

                           

                          We want to modify the PerformanceEquation AnalysisRule for the Analysis.  We're not creating a new one or modifying time rule.  Here is how I did it.

                           

                          AFAnalysis a = db.Elements["Modify_TimeTrue"].Analyses["Analysis1"];
                          AFAnalysisRule ar = a.AnalysisRule.AnalysisRules["PerformanceEquation"];
                          Console.WriteLine(ar.ConfigString);
                          string newConfigString = Regex.Replace(ar.ConfigString,@"@timetrue.*","@timetrue(\"3600\")\r");
                            Console.WriteLine(newConfigString);
                          

                           

                          My approach uses a simple regex to find the string "@timetrue" and match until the end of line and then replace is with what I want my new timetrue value to be.  Hopefully this helps!

                          1 of 1 people found this helpful
                            • Re: set True For value in analysis
                              MikeSpath

                              Thanks so much Paul, it is very puzzling to me still about TimeRules, not sure what they do, how to access even in Pi Explorer. Thank you for your patience as I learn my way through the SDK.

                              Mike

                                • Re: set True For value in analysis
                                  pmartin

                                  The TimeRule specifies how often the analysis is run.  It can be Periodic (run every "x" seconds) or Natural (run when an input tag is changed).  You would attach this to your analysis like so:

                                   

                                  analysis.TimeRulePlugIn = server.TimeRulePlugIns["Natural"];
                                  

                                  OR

                                  analysis.TimeRulePlugIn = server.TimeRulePlugIns["Periodic"];
                                  analysis.TimeRule.ConfigString = "Frequency=3600";
                                  

                                   

                                  My best advice is to look at some of your existing analyses in debug mode.  It should give you a feel for how things are connected and you can compare what properties you see in PI System Explorer to what properties are shown in Visual Studio's debugger.