I’d like to use a time series chart inside a table in a similar way one would nest a query inside another. However I need the tags that I’ll be displaying to be dynamic and selected as part of another query. I can do this in script and use system.tag.queryTagHistory() to get the appropriate dataset. However I can only get it to work with a single historical dataset, where I need multiple (the exact number would vary depending on the parent query). Is there a way to produce the same kind of datsets that result from a nested query? In script, I’ve tried various combinations of lists, dictionaries, datasets, etc. none of which seem to work. In the report designer it looks like a nested query produces a dataset inside a dataset but of course if I try to do that in script it bombs. Any help would be appreciated.
Very helpful. I used system.tag.queryTagHistory() for the child query and it works just fine. The inner query bit ended up looking like this:
for r in range(parentds.rowCount):
# Use parentds.getValueAt(r, 'some ref column') to retrieve foreign key(s)
sel = "SELECT asset,facility,fullPath,label FROM rpt_tankBatteryLevelTrend_view WHERE facility = ?"
facilityName = parentds.getValueAt(r,"name")
args = [facilityName]
pds = system.db.runPrepQuery(sel,args,"SQLSERVER")
tps = [x["fullPath"] for x in pds]
hdrs = [str(x["label"]) for x in pds]
startDate = data["StartDate"]
endDate = data["EndDate"]
colNames = ["t_stamp"] + hdrs
h = system.tag.queryTagHistory(paths=tps,returnFormat="Wide",columnNames=colNames,intervalMinutes=5,startDate=startDate,endDate=endDate,ignoreBadQuality=True)
# for each data column, another one exists that's always true (used to evaluate for key visibility on the chart)
col = [True] * h.rowCount
for c in hdrs:
h = system.dataset.addColumn(h,col,c + 'Show',bool)
childList.append(QueryResults(h, parentqr, r))
for itm in fullSet:
if itm in hdrs:
penKeyRows.append([itm,True])
else:
penKeyRows.append([itm,False])
I added additional columns to control the visibility of the pen key on the chart as the returned dataset has a variable number of pens (columns) up to 16.