Hugovdberg / PIconnect

A python connector to the OSISoft PI and PI-AF databases
MIT License
91 stars 41 forks source link

Search for attribute by providing entire Path as String in PIAF #686

Closed sesambrein83 closed 1 year ago

sesambrein83 commented 1 year ago

Feature request

Abstract

Hi Hugo, so i'm pleased i can provide PI.py a Pitag or list of pitags directly with the search function, and get a list of objects back. But i would like to have that possibility in PIAF too. I would like to provide PIAF.py with a list of Paths to Attributes as we use them in PI AF. like db.search(r'baseelement/element/element|attribute|attribute|attribute')

Suggested solution

in PIAF.py there could be added a Search function just like in PI.py. But one that returns a collection of attribute objects.

it would probably have to split the string and loop through the descendants and children like here to return the last attribute.

i've tried to add this code to PIAF.py and that seems to work...it just needs some magic to make sure it can handle a list instead of a single string.

def search(self, AFtag: str): """ return a PIAFAttribute""" if len(AFtag) > 20 and "|" in AFtag: splittag = AFtag.split('|') elem = self.descendant(splittag[0]) attribute = elem.attributes[splittag[1]] if len(splittag) > 2: for x in range(len(splittag)-2): attribute = attribute.children[splittag[x+2]] return attribute

Hugovdberg commented 1 year ago

Added in #687, published in 0.10.5 on PyPI, now working on 0.10.6 to publish on conda-forge as well