Good day,
I would like to know if it is possible to get the timestamp related to a value in a trend that was found after I query for a maximum value between a defined period of time.
system.tag.queryTagHistory(paths=["tag1"],startDate=s,endDate=e,returnSize=d,aggregationMode='Maximum')
By default, this function returns a timestamp and a value (assuming the returnSize is set to 1), but the timestamp is always equals to the startDate and I would like to know at what time this maximum was reached in that period.
Best regards,
I'm not sure you can do that using that function.
But it should be easy enough to query the data "as stored" for a time window, then use python's max
with its key
argument to get the timestamp associated with the maximum value.
You'll just have to convert the dataset queryTagHistory
returns into an iterable. system.dataset.toPyDataSet
should be enough:
something like
ds = system.tag.queryTagHistory(...)
max_ts, max_val = max(system.dataset.toPyDataSet(ds), key=lambda row: row[1])
this should give you what you want but I can't test it now.
If not, it shouldn't be too far off.
You can also try system.tag.queryTagCalculations
, maybe it will return the timestamp of the actual max ? It's been a while since I've used it.