SatVUE Portal - LUA Reports

Lua/SatVUE Report Examples

The Lua report engine allows for the generation of reports in any text format that you think of, it just requires a bit of code.

TSV Report

Tab Seperated Values (TSV) are essentially CSV files that use a TAB character instead of a comma to seperate values.

-- if there is no data, print a note and return
if (table.getn(report_data) == 0) then
  print 'No data points'
  return
end

-- create the header row
for name, value in ipairs(report_data['data'][0]) do
  print name..'\t'
end
print '\r\n'    -- Windows line ending

-- loop over all the records
for index, row in ipairs(report_data['data']) do
  for name, value in ipairs(row) do
    print value..'\t'
  end
end
print '\n'      -- Unix/Mac line ending
Which would generate a report like:
Timestamp	Field1	Field2	Field3
2017-12-05 12:00:00	1	2	3
2017-12-06 12:00:00	1.1	2.1	3.1
2017-12-07 12:00:00	3.3	4.4	5.5
						


Custom Format Report

Lua report are completly customizable, for example, if you wanted to just know when a water level was too high or too low. The following report code could be used to generate an exception report.

-- if there is no data, print a note and return
if (table.getn(report_data) == 0) then
  print 'No data points'
  return
end

-- Print the Report title
print 'SatVUE Exception Report (Generated '..formatDateTime(getEpochUTC(), 'Y-m-d H:i:s')..')\r\n'
print 'Date Range: '..report_data['start']..' to '..report_data['end'].'\r\n\r\n'

-- Find all the water levels that exceed 10m or are under 1m
for index, row in ipairs(report_data['data']) do
  -- if the water level is above 10m
  if (row['Water Level'] > 10) then
    print 'Water level dangerously high, '..row['Water Level']..'m, at '..row['_timestamp_']..'\r\n'
  end

  -- if the water level is below 1m
  if (row['Water Level'] < 1) then
    print 'Water level low, '..row['Water Level']..'m, at '..row['_timestamp_']..'\r\n'
  end
end
Which would generate a report like:
SatVUE Exception Report (Generated 2018-01-01 12:00:00)
Date Range: 2017-12-01 00:00:00 to 2018-01-01 00:00:00

Water level dangerously high, 15.4m, at 2017-12-05 12:10:00
Water level dangerously high, 12.6m, at 2017-12-06 12:10:00
Water level low, 0.5m, at 2017-12-20 12:10:00