Creating Dataset from each row of list

Hi Everyone,

I am a little stuck. I am trying to create multiple datasets from the items of a list. Below is the code that generates a list of binary values.

if event.clickCount == 2:
	if event.source.selectedRow != -1 or 0:
		
		data = event.source.data
		row = event.source.selectedRow
		value = data.getValueAt(row, "intValue")
		selId = data.getValueAt(row, "index")
		stepNumber = data.getValueAt(row, "stepNumber")
			
		
		for i in range(data.rowCount):
			
			id = data.getValueAt(i, "stepNumber")
			value1 = data.getValueAt(i, "intValue")
		
			newList = []
			
			if selId == id:	
				newList.append(value1)
				
				binValueList = []
					
				for j in range(len(newList)):
					binValue = shared.math.dec2bin(value1)   
					binValueList.extend(binValue)
					
                    print binValueList[0]

This will return list of each desired value in binary. I would like to bind each individual row to the data property for a corresponding table.

00000000000000000001000001000000b
00000000000000000000010000000001b
00000000000000000000000000000000b
00000000000000000000000000000000b
00000000000000000000000000000000b
00000000000000000000000000000000b
11111111111111111000000011000000b
00000000000000000000000000000000b
00000000000000000000000000000000b
00000000000000000000000000000000b
00000000000000000000000000000000b
00000000000000000000000000000000b

i.e.

table1.data bound to first item on the list
table2,data bound to second item on the list
etc

I just can’t seem to figure out how to get each individual binary rows into a corresponding table. Any help would be greatly appreciated.

So you want to bind the data in one row to a table such that the table will have basically one cell of data and no more? Is that what you’re asking? Or are you trying to get the data in one specific cell of a larger multi-cell table to display one of these binary values? Please clarify.

I apologize for the confusion and will attempt to clarify. I would like to have each binary row bound to its own respective table. In that, I would end up with 12 tables each with only one row of data (a column for each bit). The dataset for each table would be 1R x 33C.

table1.data = 00000000000000000001000001000000b
table2.data = 00000000000000000000010000000001b
table3.data = 00000000000000000000000000000000b
.
.
.
table12.data = 00000000000000000000000000000000b

Hopefully that clarifies things a bit, and thanks for the help.

Ultimatetely, you need to get your binary number into a list like this:

bits = [1,0,1,1,1,1,0,1]

Then you’ll create a list of column headers, something like:

headers = [“Bit 0”, “Bit 1”, etc.]

Finally, you’ll create a dataset that you can use to set the data property of a table:

dataset = system.dataset.toDataSet(headers, [data])

So you’ll need another math function to get the bits from your integers and append each bit to the list. I have a function that does this, but won’t be back in the office to copy/paste it until next week.

It might make more sense to create just one dataset with many rows, write that dataset to a custom dataset property on the screen, and then use cell update bindings on your other tables.

Hopefully that’s of some use.

Sorry for being late to the party…

I tweaked what you posted a bit. Toward the top is a loop that generates the headers. Toward the bottom, I made a hypothetical change (because I have no idea what your table names are… ;)) to generate table names and split each conversion to the binary value (minus the ‘b’, and ignoring the bitcount).

if event.clickCount == 2:

	# generate header names (bit31, bit30, ..., bit0)
	headers = []
	for i in range(31,-1,-1):
		headers.append('bit'+str(i))
  
	if event.source.selectedRow != -1 or 0:
		
		data = event.source.data
		row = event.source.selectedRow
		value = data.getValueAt(row, "intValue")
		selId = data.getValueAt(row, "index")
		stepNumber = data.getValueAt(row, "stepNumber")
			
		
		for i in range(data.rowCount):
			
			id = data.getValueAt(i, "stepNumber")
			value1 = data.getValueAt(i, "intValue")
		
			newList = []
			
			if selId == id:	
				newList.append(value1)
				
				binValueList = []
					
				for j in range(len(newList)):
					# genrate tableName
					tableName = 'table' + str(j+1)
					# convert to binary (remove 'b' and ignoree bitcount)
					binValue = list(shared.math.dec2bin(value1)[0][:-1])
					event.source.parent.getComponent(tableName).data = system.dataset.toDataSet(headers, [binvalue])

Hope this helps!

On second thought I’m not quite sure I have it placed quite right, but it should still give you some good ideas.

Thank you both for helping me out. I was able to get what I wanted with the following, which is very close to what Jordan posted. Thanks again!

if event.clickCount == 2:
	headers = []		
	
	for i in range(31, -1, -1):
		headers.append('B' + str(i))
		
	if event.source.selectedRow != -1 or 0:
		data = event.source.data
		row = event.source.selectedRow
		value = data.getValueAt(row, "intValue")
		selId = data.getValueAt(row, "index")
		stepNumber = data.getValueAt(row, "stepNumber")
		newList = []
		
		for i in range(data.rowCount):
			id = data.getValueAt(i, "stepNumber")
			value1 = data.getValueAt(i, "intValue")
			
			if selId == id:
				newList.append(value1)
				binValueList = []
					
				for j in range(len(newList)):
				
					valueNew = newList[j]
					tableNumber = 'Table ' + str(j + 1)
					binValue = list(shared.math.dec2bin(valueNew)[0][:-1])
					event.source.parent.getComponent(tableNumber).data = system.dataset.toDataSet(headers, [binValue])
					
1 Like