Create a dataset from two or more datasets

Good Morning. I have a question and I believe it is very simple for you.

I have two tables, where the first table reports hourly values
of the efficiency of one machine, and the second table gives the hour by hour of the efficiency of another machine. The idea is to create a new dataset where column 0 will be the values ​​referring to column ‘Hour’, column 1 will refer to the efficiency of the
‘BM1’ and column 2 will refer to ‘BM2’.

Follow the picture as an Example

Thank you so much

Hello,
a few points to make things clearer:

  • do you want to keep the 2 initial tables, or just end up with the merged one ?
  • Where do the tables come from ? Are they bound to dataset tags ? Results of database queries ? More complex stuff ?
  • Do you expect the hour columns to be identical in both tables ? I mean, will rows always match ?

exactly. the lines always match, the values ​​of each machine (BM1, BM2) come from SEPASOFT’s MES Analysis Controller components. So every hour I will have a new row and each machine’s table is updated. The idea is to create a script in Event Handlers → PropertyChange, as I will want to update the new table every minute. The MES analysis controller component will provide me with hourly outfeed values, but I have already created a script to create in a custom property of each MES Analysis controller, a dataset that gives me hourly values ​​of the efficiency of each machine

What version of Ignition are you using? It may make a difference.

version 7.9.9

Assuming that this is in some event on the window


pyTable2Data = system.dataset.toPyDataSet(event.souce.parent.getComponent('path to table 2').data)

#get column data from table two
bm2Data = [row['BM2'] for row in pyTable2Data]

table1Data = event.source.parent.getComponent('path to table 1').data

combinedDataset = system.dataset.addColumn(table1Data,col=bm2Data,colName = pyTable2Data.getColumnName(1),colType=pyTable2Data.getColumnType(1))

you can use bm2 = table2.getColumnAsList(1) to get the column instead of converting to a pyDataSet then constructing the list. You need to know the index of the column, but, well…

getColumnAsList() wasn’t in the list for V7.9

https://docs.inductiveautomation.com/display/DOC79/Datasets

Didn’t want to take the chance, might work, might not.

It is defiantly in V8.1 though. So for posterities sake:

In V8.1

table1Data = event.source.parent.getComponent('path to table 1').data
table2Data = event.source.parent.getComponent('path to table 2').data
bm2Index = table2Data.getColumnIndex('BM2')
combinedDataset = system.dataset.addColumn(table1Data,col=table2Data.getColumnAsList(bm2Index),colName = 'BM2',colType=table2Data.getColumnType(bm2Index))

It isn’t in the Dataset interface, but it happens to be implemented on the BasicDataset, which is the most common implementation. (And on on most others.) In a pinch, passing a generic dataset to the BasicDataset construct to ensure that method is available is pretty cheap.