Since I have no idea what you have, I’ll assume a few things:
- Two exiting datasources: averageQuery and rangeQuery
- Each dataset has two columns: t_stamp and value
There are a couple of different ways to combine datasets.
If the datasets have different time stamps and you want to keep them all. This is great for graphs and charts, but perhaps not so much for tables:
def updateData(data, sample):
"""
This function has the opportunity to add additional data into the report's
data map.
Arguments:
data: This is a map, whose keys are report data keys and values should
be sequences, maps, scalar values, or datasets to provide information to
the report.
sample: A flag that will be True if the report data being gathered is
for a preview of the report. Use to avoid slow queries and calculations
to keep previews quick.
"""
averageDataset = system.dataset.toPyDataSet(data['averageQuery'])
rangeDataset = system.dataset.toPyDataSet(data['rangeQuery'])
headers = ['t_stamp', 'average', 'range']
dataOut = []
for row in averageDataset:
dataOut.append(row[0],row[1], None)
for row in rangeDataset:
dataOut.append([row[0], None, row[1]])
combinedDataSet = system.dataset.toDataSet(headers, dataOut)
data['combinedData'] = system.dataset.sort(combinedDataSet, 0)
Or you just keep the timestamps from one dataset, which makes for a cleaner looking table. (this example uses the timestamps from the average data):
def updateData(data, sample):
"""
This function has the opportunity to add additional data into the report's
data map.
Arguments:
data: This is a map, whose keys are report data keys and values should
be sequences, maps, scalar values, or datasets to provide information to
the report.
sample: A flag that will be True if the report data being gathered is
for a preview of the report. Use to avoid slow queries and calculations
to keep previews quick.
"""
averageDataset = system.dataset.toPyDataSet(data['averageQuery'])
rangeDataset = system.dataset.toPyDataSet(data['rangeQuery'])
headers = ['t_stamp', 'average', 'range']
dataOut = []
for avgRow, rangeRow in zip(averageDataset, rangeDataset):
dataOut.append([avgRow[0],avgRow[1], rangeRow[1]])
data['combinedData'] = system.dataset.toDataSet(headers, dataOut)