Return Standard Deviation between two or more tags?

What’s the best way to return the standard deviation between two or more tags over the last 5 days?
I’m able to do this for the standard deviation for individual tags like this:

endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -5040)
dataSet = system.tag.queryTagHistory(paths=['[default]TempA', '[default]TempB'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="StdDev", returnFormat='Wide')
pyData = system.dataset.toPyDataSet(dataSet)
for row in pyData:
    for value in row:
        print(value)

But is there a way to get the standard deviation for both tags (or three etc)? Or would I need to do that with another function after I grab the data from each tag?

My goal is trying to get the standard deviation of temperature sensors in my house over the past 7 days so I can track if things I do (like turning on fans more) effect it. Not the most scientific method since there are other variables (mainly outside temp), but thought it might be an interesting number to look at. Thanks for your help!

I went ahead and grabbed the max and min temp from all my temp tags over a week and then got the max and min from those and then calculated the std dev from that (this is missing the code that grabs my tags max and min values but it basically looks like the code in the question except grabbing the max and min):

tMax = {'Family Room':pyData[0][1], 'Living Room':pyData[0][2], 'Downstairs Hallway':pyData[0][3], 'Upstairs Hallway':pyData[0][4], 'Master Bedroom':pyData[0][5]}
highest = max(tMax.items(), key=lambda i: i[1])
print("Max: " + highest[0])
print(highest[1])

tMin = {'Family Room':pyData[0][1], 'Living Room':pyData[0][2], 'Downstairs Hallway':pyData[0][3], 'Upstairs Hallway':pyData[0][4], 'Master Bedroom':pyData[0][5]}
lowest = min(tMin.items(), key=lambda i: i[1])
print("Min: " + lowest[0])
print(lowest[1])
print("StdDev: " + str(system.math.standardDeviation([highest[1], lowest[1]])))

I think that works fine?

You can use system.tag.queryTagCalculations

https://docs.inductiveautomation.com/display/DOC80/system.tag.queryTagCalculations

1 Like