Wanting to Add Data to Dataset

I’m may not be following correctly, but here is what I think you have (or, it’s how I read it).

  • You have a table component (I’ll call it ‘table’), that has information on it for these Minor Bins.
  • The names of the bins are in the first column of the table.
  • You want to read the tags for the bin modes. The bin names in the table are also, happily, part of the tag path.

If that is true, the script to make your tag list would look something like this:

### Verbose method

# Get the table component, since we will read from and write to it. 
table = path.to.table

# Get the table's dataset
dataIn = table.data

# Get the bin names. [0] Assumes the bin names are in the first column
binList = dataIn.getColumnAsList[0]  

# define our tag path. %s will let us subtitute a string later.
baseTagPath = '[default]Minor Bins/%s/Mode'

# Make an empty list to store the tag names
tagList = []

# loop through the bin names
for bin in binList:
	# Add a new tag path, substituting in the (hopefully) actual bin name.
	tagList.append(baseTagPath % bin)

# Read the list of tags we just created.	
tagsIn = system.tag.readBlocking(tagList)

# Make an empty list to hold our tag values
values = []

# Loop through the tag obects.
for tag in tagsIn:
	# add each tag value to the values list
	values.append(tag.value)

# Add the column to the dataset with a column name 'mode' and write it to the table.
table.data = system.dataset.addColumn(dataIn, values, 'mode')

For those who prefer list comprehensions:

# Get the table's dataset
dataIn = path.to.table.data

# Get the bin names. [0] Assumes the bin names are in the first column
binList = dataIn.getColumnAsList[0]  

# define our tag path. %s will let us subtitute a string later.
baseTagPath = '[default]Minor Bins/%s/Mode'

# Make the tag name list
tagList = [baseTagPath % bin for bin in binList]

# Read the list of tags we just created.	
tagsIn = system.tag.readBlocking(tagList)

# Make an empty list to hold our tag values
values = [tag.value for tag in tagsIn]

# Add the column to the dataset with a column name 'mode' and write it to the table.
path.to.table.data = system.dataset.addColumn(dataIn, values, 'mode')
1 Like