Dataset to type class java.lang.Integer

I have been using the script from the exchange to extract all the tag values from my udt tag see pic(3), and would like to have my float values included as well see Pic (1) if "[" "]" not added to the append statement for the var newData.

I not sure whether this is only related to the ",." issue

We use "," as decimal separator

If I put square bracket around [newData] when appending works fine however my result requires extra handling which I would like to avoid.
Any good ideas, try to fix it in the script or move the handling of the different data types to the view when presenting them ?

See picture (2) below from Perspective view.

def getAllTheTagz(udtPath):

tagPaths = [tag.fullPath for tag in system.tag.browseTags(parentPath = udtPath, recursive = True ) if not tag.isFolder() and not tag.isUDT() ]
print tagPaths
_results = system.tag.readAll(tagPaths)
var = 1.1
theTagz = {}
theTagy =[]
headers =["Tag Name","Value"]#,"Last Ok"]
today = system.date.now()

for i in range(len(tagPaths)):
	newDataType = type( _results[i].value)
	
	if  newDataType == type(1) or newDataType == type(var) or newDataType == type("string") or newDataType == type(False) or newDataType == type(today):
		newData =  _results[i].value
		#print i,str(tagPaths[i][len(udtPath):]),newData, type(newData)
		theTagy.append([str(tagPaths[i][len(udtPath):]),newData])
		#theTagy.append([str(tagPaths[i][len(udtPath):]), _results[i].value])
		
myRecipieValues = system.dataset.toDataSet(headers, theTagy)
return myRecipieValues #theTagy

Pic (1)

Pic(2)

Pic(3) Rawdata from tag
image

Pretty sure dataset columns can only have one type.
By putting the [] around it you made the type string.

I can't test it right now but I believe your getAllTheTags function could be a simplified a bit:

def getAllTheTags(udtPath):
	tagPaths = [tag.fullPath for tag in system.tag.browse(udtPath, {'tagType': "AtomicTag", 'recursive': True})]
	_results = system.tag.readBlocking(tagPaths)
	headers = ["Tag Name","Value"]#,"Last Ok"]
		
	data = [
		[
			path.lastPathComponent,
			tag.value
		] for tag, path in zip(_results, tagPaths)
			if isinstance(tag.value, (int, float, str, bool, java.lang.date))
	]
	return system.dataset.toDataSet(headers, data)

The java.lang.date might not be the right type, but you get the idea.

You cant make a dataset with different types so this whole function doesnt work tbh.
You should not return it as dataset, just as ("json") object array.
The table can display that too

3 Likes

java.util.Date

2 Likes

Actually, you can specify java.lang.Object as a column type, then you can put anything in the column. But a json list of mappings is better for a Perspective table.

4 Likes

thanks I will create a JSON object array instead off.

That did work very well,
Any idea to create a style for formatting based on the result from isinstance unless it straight forward to build some logic after the value field
Would like to swap "," and "." and maybe do some formatting on the Boolean

The options for that are in.
props.column
https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Table
you'll have to add the two columns there.

Yep, Columns already added.
But looking for how to do the ".," swap so it's aligned with my local format.
Which is "," as decimal separator.

Fill in the columns array and customize the rendering of each column there.

You might be forced to bind the format string of the column against the session locale and then use a Map transform within the binding. Also, make sure the field property for the column config is pointing to the desired column in your data.