# Perspective Ad-Hoc Trends with Remote Tag Providers

**URL:** <https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078>\
**Category:** Ignition Exchange\
**Tags:** perspective\
**Created:** [May 27, 2020, 1:32pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078 "2020-05-27T13:32:54Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 27, 2020, 1:32pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/1 "2020-05-27T13:32:54Z")

</div>

I was working with the Perspective AdHoc trends view created by Matt Raybourn on the exchange, and noticed that when working with remote tag providers it was excruciatingly slow to load the tag tree. The reason for this is that the browsing is recursive, and a separate system.tag.browse call is executed for every single tag. In a case where you have hundreds or thousands of tags, this can start to take much longer than acceptable to load in the client.

The system.tag.browse and system.tag.getConfiguration functions are very similar, except that the getConfiguration function has a built in “recursive” parameter, that allows you to send one remote call and collect every tag and all of its children, instead of needing to execute multiple remote calls to build the page.

I rewrote the binding transform on the items property of the tag browse tree to the following, and this allows remote providers to be scanned and rendered much more quickly than using system.tag.browse, it is a little more complicated, and system.tag.getConfiguration doesnt always return things in the same order they exist in the tag folder so I had to sort them, but this can make the page much more usable in cases where previously it would take up to 30 minutes to load a remote tag provider with 500 tags. This may not be the absolute fastest way to query large remote tag providers, but its the best one I have come up with.

Hope this helps someone, and if Matt Raybourn sees it than it may be valuable to be on the actual exchange item itself!

```auto
	#This could come from a property
	tagProvider = "[Texas North]"
	
	#[{label, expanded, data, items[]}]
	#The replacement function for browseConfiguration (Using the full dictionary of tags)
	def browseTagConfiguration(tagConfiguration, startPath):
		tags = []
		
		for result in tagConfiguration:
			tagPath = startPath + "/" + str(result["path"])
			
			#If there is a number as the last item in the path, use that as the sorting index, comment this out for alphabetical sorting
	# try:
	# nameArray = tagPath.split(' ')
	# index = int(nameArray[len(nameArray) - 1])
	# except:
	# index = 9999
			#Leave this for alphabetical sorting
			index = 0
			
			
			#Check the tagType to determine the item structure
			if str(result["tagType"]) in ["Folder", "UdtInstance", "Provider"]:
				tag = {'label': result["path"], 'expanded': False, 'data': {'folder':tagPath, 'index':index}}
				
				#An empty folder will not contain the "tags" key in its configuration
				if result.has_key("tags"):
	
					#Numerical sorting
					#tag['items'] = sorted(browseTagConfiguration(result["tags"],tagPath ), key = lambda i: i["data"]['index'])
					
					#Alphabetical sorting
					tag['items'] = sorted(browseTagConfiguration(result["tags"],tagPath ), key = lambda i: i['label'])
					
					if len(tag['items']) > 0:
						tags.append(tag)
			else:
				#A tag without history enabled will not contain the "historyEnabled" key in its configuration
				if result.has_key("historyEnabled"):
					#I only wanted to return tags that I was collecting history on
					if result["historyEnabled"]:
						tags.append({'label': result["path"], 'data': {'tag': tagPath, 'index':index}, 'items': [], 'expanded': False})
	
		return tags
	
	
	def browseHistoricalTags(path):
			tags = []
			#results = system.tag.browse(path).getResults()
			results = system.tag.browseHistoricalTags(path).getResults()
			
			if results != None:
				for result in results:
					if result.hasChildren() == True:
						tag = {'label': result.path.lastPathComponent, 'expanded': False, 'data': {'folder': result.path}}
						tag['items'] = browseHistoricalTags(result.path)
						if len(tag['items']) > 0:
							tags.append(tag)
					else:
						tags.append({'label': result.path.lastPathComponent, 'data': {'tag': result.path}})
			return tags
	
	if value:
		tags = browseHistoricalTags(tagProvider)
	else:
		tagConfiguration = system.tag.getConfiguration(tagProvider, 1)[0]

		#Numerical sorting
		#tags = sorted(browseTagConfiguration(tagConfiguration["tags"],''), key = lambda i: i["data"]['index'])
		#Alphabetical Sorting
		tags = sorted(browseTagConfiguration(tagConfiguration["tags"],tagProvider ), key = lambda i: i['label'])
		
	
	return tags

```

EDIT: Originally I accidentally left the incorrect function in for browseHistoricalTags! I have replaced it with the correct one.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 27, 2020, 1:52pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/2 "2020-05-27T13:52:54Z")

</div>

Well done!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 27, 2020, 4:42pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/3 "2020-05-27T16:42:28Z")

</div>

Very cool, and kudos for sharing your solution! @mraybourn 🙂

---

<div class="post-metadata">

**Author:** ![mraybourn](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mraybourn](https://forum.inductiveautomation.com/u/mraybourn)\
**Post date:** [May 27, 2020, 5:16pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/4 "2020-05-27T17:16:51Z")

</div>

Yeah, that is awesome, thanks for posting it!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 27, 2020, 9:47pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/5 "2020-05-27T21:47:58Z")

</div>

I was a bit sad that from 7 to 8, the tag browse function lost its recursive option. Do you know why that was?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [June 10, 2020, 1:39pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/6 "2020-06-10T13:39:04Z")

</div>

As a follow up to this,

If you have a system with a huge number of tags, this can start to become a bit slow as it tries to recursively iterate through a huge number of tags.

So I built another version that browses one folder at a time progressively

> [@Perspective Progressive Tag Tree](http://forum.inductiveautomation.com/t/perspective-progressive-tag-tree/35495):
>
> I had a few people reach out and ask me about the Perspective tag browse tree I setup to recursively build with getConfiguration, and ask about a way to progressively build the tree as the user digs into it, to decrease loading time for large tag quantity systems. So I went ahead and built a version for that too! I actually put this one on the exchange, but wanted to make sure it still works with @mraybourn’s [Ad-hoc Trends page](https://inductiveautomation.com/exchange/46/overview), so I made sure that this one is drop-in to that view and provides…

> **[Ignition Exchange](https://inductiveautomation.com/exchange/2033/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

---

<div class="post-metadata">

**Author:** ![miyanalu](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@miyanalu](https://forum.inductiveautomation.com/u/miyanalu)\
**Post date:** [August 12, 2020, 5:14pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/7 "2020-08-12T17:14:26Z")

</div>

This view was awesome. I think something like this to browse a PLC will be very cool. I was able to develop something similar with the system.opc.browseServer function but I was not able to get the data type of the tags so could not efficiently import tags to the ignition gateway.

---

<div class="post-metadata">

**Author:** ![c-w-t](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@c-w-t](https://forum.inductiveautomation.com/u/c-w-t)\
**Post date:** [August 20, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/8 "2020-08-20T15:34:46Z")

</div>

LOVE IT! Thanks, you saved me hours I think.

---

<div class="post-metadata">

**Author:** ![c-w-t](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@c-w-t](https://forum.inductiveautomation.com/u/c-w-t)\
**Post date:** [September 2, 2020, 7:15pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/9 "2020-09-02T19:15:35Z")

</div>

I hope this is related enough to not be a hijack…

Has anyone seen or used an example of system.tag.browseHistorical() on a remote gateway when the script is running on a gateway that doesn’t have the tag history module licensed? I have a scale-out architecture and my front-end server only has Perspective licensed, so I can’t create a historical tag provider. I can browse real time tags on the remote gateway, but not its historical tags using the path string like ‘histprov:myDB:/drv:myIgnitionGateway:myTagProvider:/tag:myFolderOfTags’ because there is no histprov on the gateway running that script. I have access to the same database connection that the historical data is stored to, so it feels like I should be able to address it via a path using the driver and the database connection.

I’m I missing something obvious? Or do I need to design a custom query to fetch the history tags directly from the sqlth tables in this case?

Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 2, 2020, 7:40pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/10 "2020-09-02T19:40:08Z")

</div>

Have you tried using sendRequest() ? (From remote gateway to ask origin gateway to query history.)

---

<div class="post-metadata">

**Author:** ![c-w-t](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@c-w-t](https://forum.inductiveautomation.com/u/c-w-t)\
**Post date:** [September 3, 2020, 1:41pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/11 "2020-09-03T13:41:04Z")

</div>

That I have not tried! I’ll explore that and report back…

Thanks Pete!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 6, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/12 "2020-09-06T12:56:44Z")

</div>

> [@c-w-t](#):
>
> Pete

I think you mean Phil 😄

---

<div class="post-metadata">

**Author:** ![c-w-t](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@c-w-t](https://forum.inductiveautomation.com/u/c-w-t)\
**Post date:** [September 8, 2020, 7:36pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/13 "2020-09-08T19:36:19Z")

</div>

LOL!! Yep. Thanks Phil!

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [September 21, 2021, 2:06pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/14 "2021-09-21T14:06:06Z")

</div>

Is this the official way to request tag history from a separate server, or is there some magical way the Gateway Network handles this for you? Like C-W-T mentioned, what if we have a Perspective Front-End server and a centralized Tag Historian back-end server…the Power Chart component doesn’t let you specify raw data, instead, you provide the tag path.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 21, 2021, 2:33pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/15 "2021-09-21T14:33:01Z")

</div>

At that point I would set up the central tag server as a remote tag provider to the perspective gateway. That should allow you to access all real-time and historical gateway like it was local

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2021, 3:16pm UTC](https://forum.inductiveautomation.com/t/perspective-ad-hoc-trends-with-remote-tag-providers/35078/16 "2021-09-21T15:16:34Z")

</div>

The specific question related to _not having the license_ at the receiving end. Having the license on both ends would be the official way to do this.
