Updating multiple dataset values

Hi, I have a script on a numeric label, each time the value changes I do some operations and depending on the result of the operations I update several rows of a table dataset.

What I have now is this:
if event.propertyName == “value”:
print “change in performance value”
updatedRow = system.dataset.updateRow(data, 0,{“Value”:(performance*100)})
event.source.parent.getComponent(‘Pie Chart 1’).data = updatedRow
data = event.source.parent.getComponent(‘Pie Chart 1’).data
updatedRow = system.dataset.updateRow(data, 1,{“Value”:(1-performance)*100})
event.source.parent.getComponent(‘Pie Chart 1’).data = updatedRow

I am reading the dataset and update 1 row, then read again the dataset and update other row and so on …

The solution works, however I am looking for a much efficient solution. Do you have any other ideas?


Yes, you should hang onto the intermediate dataset and perform all of the updates on it, then set it back to the component. Something like this:

if event.propertyName == 'value':
	perf = event.source.newValue
	pchart = event.source.parent.getComponent('Pie Chart 1')
	ds = pchart.data
	ds = system.dataset.updateRow(ds, 0, {'Value': (perf * 100)})
	ds = system.dataset.updateRow(ds, 1, {'Value': ((1.0-perf) * 100)})
	pchart.data = ds

{ ps. Use triple-backquotes on lines above and below your pasted code to format it nicely. These: ``` . You could edit your original post to do so. }


Thank you ! it works now.