예제 #1
0
        private int ReviewStatus_AFElementSearch_CountOnAllTurbinesCDR(string attribute, string windFarmName)
        {
            AFStopwatch stopwatch = new AFStopwatch();

            var afElementSearch = new AFElementSearch(_afDatabase, "MyQuery", "Name:" + windFarmName + " CategoryName:WTG");

            var elements = afElementSearch.FindElements();

            //Console.WriteLine("Done : " + elements.Count() + ", " + stopwatch.ElapsedMilliseconds + "ms");

            AFElement.LoadAttributes(elements.ToList(), new List <AFAttributeTemplate> {
                _afDatabase.ElementTemplates["WtgBaseTemplate"].AttributeTemplates["WSLG.EvtCt"].AttributeTemplates[attribute]
            });

            var countDictionary = new Dictionary <string, int>();

            foreach (var afElement in elements)
            {
                var count = afElement.Attributes["WSLG.EvtCt"].Attributes[attribute].GetValue().ValueAsInt32();

                if (count > 0)
                {
                    countDictionary[afElement.Name] = count;
                }
            }

            //Console.WriteLine("Done2 : " + elements.Count() + ", " + stopwatch.ElapsedMilliseconds + "ms");
            return(stopwatch.ElapsedMilliseconds);
            //_log.Info($"Time:{stopwatch.Elapsed.TotalSeconds}, Element:{windFarmName}, Element Count: {countDictionary.Keys.Count}, EventFrame Count:{countDictionary.Sum(e => e.Value)}");

            //foreach (var counts in countDictionary)
            //{
            //    _log.Info($"{counts.Key}:{counts.Value}");
            //}
        }
예제 #2
0
        /// <summary>
        /// Create or update PI point data reference for an AF attribute in a list of AF elements
        /// </summary>
        /// <param name="at"></param>
        /// <param name="elist"></param>
        /// <param name="updateProgress"></param>
        private static void ProcessAttributeTemplate(AFAttributeTemplate at, IList <AFElement> elist, EventHandler <AFProgressEventArgs> updateProgress = null)
        {
            if (at.DataReference == null || !at.DataReference.Name.Equals("PI Point", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // Load attributes
            IList <AFAttributeTemplate> ats = new List <AFAttributeTemplate>();

            ats.Add(at);
            AFElement.LoadAttributes(elist, ats);

            ProcessAttributes(elist.Select(elm => elm.Attributes[at.Name]).ToList(), updateProgress);
        }
        public static IList <AFElement> LoadElements(AFElementTemplate elementTemplate, IEnumerable <string> attributesToLoad)
        {
            int totalCount;
            int startIndex = 0;
            int pageSize   = 1000;

            List <AFElement> results = new List <AFElement>();

            // Paging pattern
            do
            {
                var baseElements = elementTemplate.FindInstantiatedElements(
                    includeDerived: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);

                // If there are no elements, break the process
                if (baseElements.Count == 0)
                {
                    break;
                }

                IEnumerable <AFElement> elements = baseElements.OfType <AFElement>();

                IEnumerable <IGrouping <AFElementTemplate, AFElement> > elementGroupings = elements.GroupBy(elm => elm.Template);
                foreach (var item in elementGroupings)
                {
                    // The passed in attribute template name may belong to a base element template.
                    // GetLastAttributeTemplateOverride searches upwards the template inheritance chain
                    // until it finds the desired attribute template.
                    List <AFAttributeTemplate> attrTemplates = attributesToLoad
                                                               .Select(atr => GetLastAttributeTemplateOverride(item.Key, atr))
                                                               .Where(atr => atr != null)
                                                               .ToList();

                    List <AFElement> elementsToLoad = item.ToList();
                    AFElement.LoadAttributes(elementsToLoad, attrTemplates);
                    results.AddRange(elementsToLoad);
                }

                startIndex += baseElements.Count;
            } while (startIndex < totalCount);

            return(results);
        }
예제 #4
0
        protected override List <Action> GetActions()
        {
            var           attribute = "WSLG.CtVibMxVibEvtStNew";
            List <Action> actions   = Constants.WindFarms.Select(windFarm => (Action)(() =>
            {
                var actionStopwatch = new AFStopwatch();
                actionStopwatch.Start();

                var afElementSearch = new AFElementSearch(AfDatabase, "MyQuery",
                                                          "Name:" + windFarm + " CategoryName:WTG");

                var elements = afElementSearch.FindElements().ToList();

                //Console.WriteLine("Done : " + elements.Count() + ", " + stopwatch.ElapsedMilliseconds + "ms");

                AFElement.LoadAttributes(elements,
                                         new List <AFAttributeTemplate>
                {
                    AfDatabase.ElementTemplates["WtgBaseTemplate"].AttributeTemplates["WSLG.EvtCt"]
                    .AttributeTemplates[attribute]
                });

                //var countDictionary = new Dictionary<string, int>();

                //foreach (var afElement in elements)
                //{
                //    var count = afElement.Attributes["WSLG.EvtCt"].Attributes[attribute].GetValue().ValueAsInt32();

                //    if (count > 0)
                //    {
                //        countDictionary[afElement.Name] = count;
                //    }
                //}

                TestOutput.AddActionResult(
                    new ActionPerformanceResult
                {
                    ActionMillis = actionStopwatch.ElapsedMilliseconds,
                    ResultCount = elements.Count
                });
            })).ToList();

            return(actions);
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];

            AFElement boilerA = afDatabase.Elements["Region_0"].Elements["BoilerA"];

            AFElementTemplate   elementTemplate         = afDatabase.ElementTemplates["BasicBoilerTemplate"];
            AFAttributeTemplate temperatureAttrTemplate = elementTemplate.AttributeTemplates["Temperature"];
            AFAttributeTemplate modeAttrTemplate        = elementTemplate.AttributeTemplates["Mode"];

            AFElement.LoadAttributes(new[] { boilerA }, new[] { temperatureAttrTemplate, modeAttrTemplate });

            AFEnumerationSet digSet = afDatabase.EnumerationSets["Modes"];

            IList <AFValue> valuesToWrite = new List <AFValue>();

            for (int i = 0; i < 10; i++)
            {
                AFTime time = new AFTime(new DateTime(2015, 1, 1, i, 0, 0, DateTimeKind.Local));

                AFValue afValueFloat = new AFValue(i, time);
                // Associate the AFValue to an attribute so we know where to write to.
                afValueFloat.Attribute = boilerA.Attributes["Temperature"];

                AFEnumerationValue digSetValue    = i % 2 == 0 ? digSet["Auto"] : digSet["Manual"];
                AFValue            afValueDigital = new AFValue(digSetValue, time);
                afValueDigital.Attribute = boilerA.Attributes["Mode"];

                valuesToWrite.Add(afValueFloat);
                valuesToWrite.Add(afValueDigital);
            }

            // Perform a bulk write. Use a single local call to PI Buffer Subsystem if possible.
            // Otherwise, make a single call to the PI Data Archive.
            // We use no compression just so we can check all the values are written.
            // AFListData is the class that provides the bulk write method.
            AFListData.UpdateValues(valuesToWrite, AFUpdateOption.InsertNoCompression, AFBufferOption.BufferIfPossible);
        }
        /// <summary>
        /// Find elements implementing a given AF Element Template and load a list of attributes from these elements
        /// </summary>
        private List<AFElement> FindElements(AFElementTemplate elementTemplate, IEnumerable<string> attributesToLoad)
        {
            int totalCount;
            int startIndex = 0;
            var results = new List<AFElement>();

            do
            {
                var baseElements = elementTemplate.FindInstantiatedElements(
                                includeDerived: true,
                                sortField: AFSortField.Name,
                                sortOrder: AFSortOrder.Ascending,
                                startIndex: startIndex,
                                maxCount: ChunkSize,
                                totalCount: out totalCount);

                // if there is no new leaf elements, break the process
                if (baseElements.Count() == 0)
                    break;

                var elements = baseElements.Select(elm => (AFElement)elm).ToList();

                var elementGroupings = elements.GroupBy(elm => elm.Template);
                foreach (var item in elementGroupings)
                {
                    List<AFAttributeTemplate> attrTemplates = attributesToLoad.Select(atr => AFHelper.GetLastAttributeTemplateOverride(item.Key, atr)).ToList();
                    AFElement.LoadAttributes(item.ToList(), attrTemplates);
                }

                results.AddRange(elements);

                startIndex += baseElements.Count();
            } while (startIndex < totalCount);

            return results;
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFElementTemplate boilerTemplate = afDatabase.ElementTemplates["Boiler"];

            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                // Find a collection of elements instantiated from the Boiler tempplate.
                // Only the Elements' header information (Name, Description, Template, Type, etc.)
                // are loaded from the AF Server by this call.
                AFNamedCollection <AFElement> elements = AFElement.FindElements(
                    database: afDatabase,
                    searchRoot: null,
                    query: "Boiler",
                    field: AFSearchField.Template,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);
                if (elements == null)
                {
                    break;
                }

                // Partially load the element by retrieving information only for the Water Flow attribute.
                AFElement.LoadAttributes(elements, new[] { boilerTemplate.AttributeTemplates["Water Flow"] });

                Console.WriteLine("Found {0} Elements.", elements.Count);

                AFAttributeList attrList = new AFAttributeList();

                // Because we are retrieving the Water Flow attribute which was previously loaded,
                // no additional server calls are made.
                // If LoadAttributes had not been called previously, then a server call would have been made for each element
                // in the loop below.
                foreach (AFElement item in elements)
                {
                    attrList.Add(item.Attributes["Water Flow"]);
                }

                AFValues values = attrList.GetValue();

                Console.WriteLine("  Water Flow values");
                foreach (AFValue val in values)
                {
                    Console.WriteLine("  Element: {0}, Timestamp: {1}, Value: {2}",
                                      val.Attribute.Element, val.Timestamp, val.Value.ToString());
                }

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }