Get the Historical Tag Path from the Tag Path

Good afternoon.

I would like to know if it is possible to obtain the Historical Tag Path from the Tag Path.

For example, if I know the Tag Path is “simulator/turbine 3”, I would like to get its Historical Tag Path automatically: ''histprov:DB:/drv:controller:default:/tag:simulator/turbine 3", without need to build the text string cocatenating the different elements that compose it.
Is there a function that returns the Historical Tag Path?

Best Regards.

Here you go:

@lrose Not sure that helps as there could be multiple drivers/providers and Paul’s method creates them as static. Although once you know the parts you could use this to create the path. Might have to read all of the parts from the tag itself. Not sure if there’s another way

@nminchin I agree but it the only method I know of that isn’t concatenation the parts together.

Perhaps combining this with pulling the tag configuration?

Good night.

I’ve thought about using the "system.tag.getConfiguration()" function, but of all the elements I need to build the Historical Tag Path, that function only gives me the history provider. I don’t understand why that function doesn’t provide the Gateway and TagProvider of a tag. It would be ideal.
So I’ll build the Historical Tag Path by concatenating its parts.

So, the driver is actually part of the full tag path. It is possible if you are using remote tag providers to use a gateway message handler in conjunction with this function to get what you’re looking for.

If you put this function in a shared script on the same gateway as the tag provider, then it should return your historical tag path.

Inspired heavily from the script provided by @PGriffith

def getHistoricalTagPath(path):
    from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes,QualifiedPathUtils
    from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

    qPath = QualifiedPathUtils.fromTagPathNew(TagPathParser.parseSafe('default',path))
    histProv, gateway = system.tag.readBlocking([path + '.historyProvider','[System]Gateway/SystemName'])
    driver = ':'.join([gateway.value,qPath.getPathComponent('prov')])
    return QualifiedPath.Builder().set(WellKnownPathTypes.HistoryProvider,histProv.value).setDriver(driver).setTag(qPath.getPathComponent('tag')).build().toString()

So using the following assumptions:

  1. The system name of the gateway this function is run on is controller
  2. The historical provider of the tag is set to DB
  3. You provide the path '[default]simulater/turbine 3' or 'simulater/turbine 3'

Then this function will return histprov:DB:/drv:controller:default:/tag:simulater/turbine 3

You could also just hard code the gateway in if it isn’t going to change often.

I chose to use system.tag.readBlocking() here because system.tag.getConfiguration() only returns non-default properties, since a historical provider is not provided by default it should always be returned, but better safe than sorry. Also, I needed to call the function anyway to get the gateway name, so just as easy to get it from there.

You may want to consider either verifying that history is enabled for the provided path, or coalescing to a default if a ‘historical provider’ is not provided.

If you take out the toString() and instead return just a QualifiedPath then you could use this function to do a lot of things, for instance checking for incorrect configurations.

print [tag['fullPath'] for tag in system.tag.browse('path/to/folder',{'tagType':'Atomic Tag'}).getResults() if getHistoricalTagPath(tag['fullPath']).getPathComponent('prov') in ('null','SomeOtherIncorrectProvider')]
1 Like