This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

CSV format
#4
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)
Reply


Messages In This Thread
CSV format - by jobb@nordstrandsel.se - 13.09.2023, 15:52
RE: CSV format - by admin - 14.09.2023, 07:21
RE: CSV format - by jobb@nordstrandsel.se - 14.09.2023, 09:41
RE: CSV format - by admin - 14.09.2023, 10:09
RE: CSV format - by jobb@nordstrandsel.se - 14.09.2023, 11:41
RE: CSV format - by admin - 14.09.2023, 11:47
RE: CSV format - by jobb@nordstrandsel.se - 14.09.2023, 12:06
RE: CSV format - by admin - 14.09.2023, 12:36
RE: CSV format - by jobb@nordstrandsel.se - 14.09.2023, 13:23

Forum Jump: