LM trend log functions Back


require('trends')

Include library before calling trend log functions


trends.fetch(name, dates, resolution)
trends.fetchone(name, dates, resolution)

Fetch one or many values for the given period

Parameters:

Return values:

fetch returns Lua table with values for the given period or nil on error. Number of values depends on period, resolution and data retention settings

fetchone returns single value for the given period or nil on error

Example:

require('trends')

-- will fetch data between 2016.04.15 00:00 and 2016.04.16 00:00
dates = {
  ['start'] = { year = 2016, month = 4, day = 15 },
  ['end'] = { year = 2016, month = 4, day = 16 },
}

-- fetch current value
day = trends.fetchone('Gas', dates)

-- get data for the past year
dates = {}
dates['start'] = os.date('*t')
dates['start'].year = dates['start'].year - 1
dates['end'] = os.date('*t')

-- fetch previous value
yearly = trends.fetch('Gas', dates, 86400)

trends.NaN value is used for points which contain invalid values or cannot be found

The default value is 0, but it can also be set to 0 / 0 (NaN - not a number).

Example:

require('trends')

-- use "not a number" for invalid values
trends.NaN = 0 / 0

-- get data for the past year
dates = {}
dates['start'] = os.date('*t')
dates['start'].year = dates['start'].year - 1
dates['end'] = os.date('*t')

value = trends.fetchone('Hot Water', dates)

-- NaN ~= NaN, means value was not found
if value ~= value then
  return
end