Easy Chart Power Table

Okay, so here is how I would approach this.

First sometime ago, I helped with a similar problem, and @PGriffith showed this "chunker" function (that he got from stackOverflow), that I will use. It's extremely useful in situations like this because it allows you to read all of the tags in one go and then separate out the "chunks" into the things you care about.

def chunker(seq,size):
    return (seq[pos:pos + size] for pos in xrange(0,len(seq),size))

Original Chunker Post

So define that somewhere in the script prior to using it.

Then your script can look like this:

def chunker(seq,size):
    return(seq[pos:pos + size] for pos in xrange(0,len(seq),size))

pens = event.source.parent.getComponent('Easy Chart').tagPens

paths = pens.getColumnAsList(1)
properties = ['Tooltip','Value','EngUnit']

tagPaths = ['{}.{}'.format(path,prop) for prop in properties for path in paths]
tagValues = system.tag.readBlocking(tagPaths)

columns =  [[qv.value for qv in chunk] for chunk in chunker(tagValues,len(paths))]
columns.insert(2,event.source.parent.getComponent('Power Table').xTraceValues.getColumnAsList(1))

for index,column,desc,colType in zip(xrange(1,5),columns,("DESCRIPTION","VALUE","XTRACE","UNIT"),(str,float,float,str)):
    pens = system.dataset.addColumn(pens,index,list(column),desc,colType)

event.source.parent.getComponent('Power Table').data = pens

EDIT: changes made to reflect the errors @justinedwards.jle pointed out.

3 Likes