14.09.2023, 10:09
Then you probably need something like this. For it to work correctly all trends included in the export must have the same resolution.
Code:
require('trends')
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')
now = os.time()
function fetch(tname)
local res = {}
local values = trends.fetch(tname, dates)
local count = #values
local step = 86400 / count
for i, value in ipairs(values) do
table.insert(res, {
now - (count - i) * step,
value
})
end
return res
end
buf = {
fetch('Trend name 1'),
fetch('Trend name 2')
}
csv = {}
for i, row1 in ipairs(buf[ 1 ]) do
date = os.date('%Y-%m-%d %H:%M', row1[ 1 ])
value1 = row1[ 2 ]
row2 = buf[ 2 ][ i ] or {}
value2 = row2[ 2 ] or 0
csv[ #csv + 1 ] = string.format(',,,%s,%.2f,,,,%.0f,,',
date, value1, value2)
end
csv = table.concat(csv, '\n')
log(csv)