AnsweredAssumed Answered

AF Datapipes and PI Datapipes

Question asked by natdavidson on Mar 22, 2018
Latest reply on Sep 26, 2018 by night2day

I have and AF hierarchy with elements that have attributes that run some analysis to determine if a parent attribute should be a 1 or a 0. I wanted to monitor the change of these parent attributes' changes from 0 to 1, and thought an AF Datapipe would be the best way to go, but ran into some memory problems when i got all the attributes added (About 13.5k), probably due to the 20 or so calculations (from its' children attributes) that this attribute depends on. We fixed the memory problem by making the attribute a PI Point data reference, but now we've either exposed a new or existing problem. Since this attribute relies on other of it's children attributes doing analyses, and itself is an analysis that outputs to a PI Point, the AF Datapipe i was using is seeing the updates to the attribute as updates, so every attribute is being sent to the AF Datapipe, regardless of value change, just because the attribute was updated. Now i'm exploring the possibility that this might be a better case for a PI Datapipe, and have written some test code, but i seem to be getting the same results; every PI Point is getting sent to the Datapipe because it's being updated. Could someone help me find a way to only get updates on value changes (i.e. when the value changes, not even an archive updated). I'll provide my code below, i tried to generalize it, it's a little rough.

 

            string MyDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string loggingFilePath = MyDocumentsPath + @"\Logging\";
            string loggingFileName = "";
            string logfile = "";
            PISystems myPISystems = new PISystems();
            PISystem myPISystem = myPISystems["AFSystem"];
            PIServers myPIServers = new PIServers();
            PIServer myPIServer = myPIServer["PIServer"];


            AFDatabase myDB;
            AFNamedCollection<AFAttribute> colAttributes;
            colAttributes = null;
            AFNamedCollection<AFElement> colCityElements;
            myDB = ebayPISystem.Databases["DATABASE"];
            AFDataPipe myAFDP = new AFDataPipe();
            List<string> PointsNames = new List<string>();


            colAttributes = AFAttribute.FindElementAttributes(
                myDB,
                null,
                null,
                null,
                null,
                AFElementType.Any,
                "Template1",
                null,
                TypeCode.Empty,
                true,
                AFSortField.Name,
                AFSortOrder.Ascending,
                20000);


    //PI Datapipe experiment
            foreach (AFAttribute att in colAttributes)
            {
                try {PointsNames.Add(att.PIPoint.Name); } //Try block because some points can't be built yet, but still appear in search
                catch { };                
            }
            IList<PIPoint> attributePoints = PIPoint.FindPIPoints(myPIServer, PointsNames, null);
            List<AFDataPipeEvent> pipeResults = new List<AFDataPipeEvent>();
            using (PIDataPipe myPIDP = new PIDataPipe(AFDataPipeType.Archive))
            {
int teststop3 = 0;
                myPIDP.AddSignups(attributePoints);
                while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                {                    
                    AFListResults<PIPoint, AFDataPipeEvent> myResults = myPIDP.GetUpdateEvents(14000);
                    if (myResults.Results.Count > 0)
                    {
                        foreach (var item in myResults.Results)
                        {
                            if(item.PreviousEventAction.ToString() == item.Action.ToString())
                            {
                                teststop3++;
                            }
                        }


                    }
                }
            }


    //Pre-PI Datapipe experiment
            myAFDP.AddSignups(colAttributes);
            AFListResults<AFAttribute, AFDataPipeEvent> updateResults;
            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                updateResults = myAFDP.GetUpdateEvents();
                if (updateResults.Results.Count > 0)
                {
                    CustomClass VerfiyResult = new CustomClass();


                    foreach (AFDataPipeEvent item in updateResults)
                    {
                        AFAttribute itemAttribute = item.Value.Attribute;
                        if (itemAttribute.Parent == null)
                            //Log result
                        else
                            //Log different result
                        VerfiyResult.VerifyValues(itemAttribute, logfile, true);                     
                    }
                }
                else
                    Console.WriteLine("AFDataPipe was empty. " + updateResults.Results.Count + " results.");

Outcomes