15.12.2023, 12:49
This will log the highest value and respective date for the past 7 days.
Code:
daycount = 7
trendname = 'TEMP'
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - daycount
dates['end'] = os.date('*t')
values = require('trends').fetch(trendname, dates, 86400, true)
table.sort(values, function(a, b)
return a[2] > b[2]
end)
max = values[ 1 ]
time, value = unpack(max)
date = os.date('%F', time)
log(date, value)