1 Reply Latest reply on May 7, 2018 12:38 PM by Rick Davin

    create a large number of analysis in code

    eradwan

      Hi There,

      I'm planning to use the following code over more than 15000 tags that serve as 'INHIBIT' tags in our safety system. Users need to get some statistics from these tags that give a string value that include the value 'Inhibit' among other values, I want to use event frames as it will also give the duration of each time when the tag was in inhibit mode. However, this way, I'll end up with an analysis for each tag as the tag name is part of the config string for the EF rule! Do you know of any smarter way to accomplish this?

       

      try
                  {
                      PISystem ps;
                      AFDatabase AF_Pilot;
                      AFElement ocd1SourAfElement;
                     
      
      
                      var connection = new AfConnectionHelper("SRLAAP81", "AF Pilot");
                      ps = connection.GetPiSystem();
                      connection.Connect();
                      AF_Pilot = ps.Databases.DefaultDatabase;
                     
      
      
                      Guid ocd1SourGuid = new Guid("bc8ac68b-4dc4-11e8-be45-005056a312a2");
                      ocd1SourAfElement = AFElement.FindElement(ps, ocd1SourGuid);
      
      
                      AFElementTemplate efTemplate = AF_Pilot.ElementTemplates["INHIBIT"];
      
      
                      AFAnalysis efAnalysis = ocd1SourAfElement.Analyses.Add("EF_Calc");
      
      
                      efAnalysis.AnalysisRulePlugIn = ps.AnalysisRulePlugIns["EventFrame"];
                      efAnalysis.AnalysisRule.ConfigString = String.Format("EFTGUID={0};EFTNAME={1}", efTemplate.UniqueID, efTemplate.Name);
      
      
                      AFAnalysisRule triggerRule = efAnalysis.AnalysisRule.AnalysisRules.Add(ps.AnalysisRulePlugIns["PerformanceEquation"]);
                      triggerRule.ConfigString = "StartTrigger:= '1300NDFPHLM14A028.PV' = \"INHIBIT\" ";
                      AFAnalysisRule timeTrueRule = efAnalysis.AnalysisRule.AnalysisRules.Add(ps.AnalysisRulePlugIns["TimeTrue"]);
                      timeTrueRule.ConfigString = "TimeTrueValue=0";
      
      
                      efAnalysis.TimeRulePlugIn = ps.TimeRulePlugIns["Natural"];
                      efAnalysis.SetStatus(AFStatus.Enabled);
      
      
                      efAnalysis.CheckIn();
      
      
                      List<AFAnalysis> myAnalyses = new List<AFAnalysis>();
                      myAnalyses.Add(efAnalysis);
      
      
                      string startTime = "*-7d";
                      string endTime = "*";
                      AFAnalysisService myAFAnalysisSvc = ps.AnalysisService;
                      myAFAnalysisSvc.QueueCalculation(myAnalyses, new AFTimeRange(startTime, endTime),
                      AFAnalysisService.CalculationMode.DeleteExistingData);
      
      
                      efAnalysis.CheckIn();
                  }
                  catch (Exception ex)
                  {
                     
                      throw;
                  }
              }