Tabela de Histórico na View

Novo Script para Servidor para a View com histórico de um datapoint qualquer:

Insira um Script para servidor, e coloque o código abaixo:

/* @license MIT */
// Data points included in history (ID or XID)
var points = [ point.id ];
// Limita a tabela a 15 linhas:
// Mude para mais linhas se necessario
var limite = 15;
// History period (select time unit above)
var time_period = 2;
// History time unit:
// 0 → minutes
// 1 → hours
// 2 → days
var time_unit = 1;
// Change SimpleDateFormat time pattern (advanced!)
var time_pattern = “yyyy-MM-dd KK:mm a”;
//
// DON’T CHANGE THE CODE BELOW
//
// Convert time to milliseconds
time_unit = time_unit > 2 ? 2 : time_unit;
var units = [ 60000, 3600000, 43200000];
var startTime = new Date().getTime() - (time_period * units[time_unit]);
var html=“”;
// Create HTML
html += “

“;
html += createFinalCSV();
html += “
”;
return html;
//
//// Functions
//
// Create final CSV file content
function createFinalCSV() {
var csv = “Data sourceData pointValueTime”;
for (var i in points) {
var pointInfo = getDataPointInfo(points[i]);
csv += createCSVHistory(pointInfo, startTime); }
return csv;}
// Create CSV history for each data point specified
function createCSVHistory(point, startTime) {
var pvDAO = new com.serotonin.mango.db.dao.PointValueDao();
var history = pvDAO.getPointValues(point.id, startTime);
var sdf = new java.text.SimpleDateFormat(time_pattern);
var length = history.size() - 1;
var linha = “”;
var alength=length;
if (length>limite) alength=limite;
for (var i = alength; i >= 0; i–) {
var data = “”+ point.source + “” +
point.name + “” + history.get(i).value + “” + sdf.format(history.get(i).time)+””;
linha += data; }
return linha;}
// Get data point information (id, xid, point name and data source name)
function getDataPointInfo(identifier) {
var dpDAO = new com.serotonin.mango.db.dao.DataPointDao();
var dp = dpDAO.getDataPoint(identifier);
var pointId = dp.getId();
var pointXid = String(dp.getXid());
var pointName = String(dp.getName());
var sourceName = String(dp.getDataSourceName());
return { id: pointId, xid: pointXid, name: pointName, source: sourceName };}

Veja o Resultado:

1 curtida

Boa tarde, não consegui fazer funcionar o código.

Qual o erro informado?