Thanks for your lp file.
I tried to do sum of the value, but can't get length value, still 0 for result. however I can see the result value as array type in console...
I tried lots of solution with each, for... without success. Any idea ?
result array in console log. Also result[0] or result[1] or result[0][0]...don't work.
----------
only solution I found is using inside the function
However I can't understand why in the other solution the lenght and [x] don't work
I tried to do sum of the value, but can't get length value, still 0 for result. however I can see the result value as array type in console...
I tried lots of solution with each, for... without success. Any idea ?
Code:
function readTrend( listeId, dayBefore, dayBase )
{
var data = JSON.stringify({
dates_curr: {
start: getdate(dayBefore),
end: getdate(dayBase)
},
ids: listeId,
});
var result = [];
var totVal=[];
$.post('/scada-vis/trends/fetch', { data }, function(trends) {
trends = JSON.parse(trends);
$.each(trends, function(_, trend) {
result.push(trend.data);
});
});
return sum(result);
}
Code:
function sum(array) {
//test each
let totVal = 0
console.log(array[1]);
let newArray=new Array();
newArray=array;
$.each(newArray, function(_, lined) {
console.log(lined.data);
});
// test for
for (let l = 0; l < array.length; l++) {
console.log('hello');
var sum = 0;
for (let k = 0; k < array[l].length; k++) {
sum += array[l][k];
}
//console.log(sum);
totVal.push(sum);
}
return sum(result);
}
result array in console log. Also result[0] or result[1] or result[0][0]...don't work.
Code:
Array []
0: Array(24) [ 112, 112, 114, … ]
1: Array(24) [ 291, 173, 666, … ]
2: Array(24) [ 13, 14, 13, … ]
length: 3
<prototype>: Array []
scada-vis:771:11
----------
only solution I found is using inside the function
Code:
function readTrend( listeId, dayBefore, dayBase, total )
{
var data = JSON.stringify({
dates_curr: {
start: getdate(dayBefore),
end: getdate(dayBase)
},
ids: listeId,
});
var result = [];
var totVal=[];
$.post('/scada-vis/trends/fetch', { data }, function(trends) {
trends = JSON.parse(trends);
$.each(trends, function(_, trend) {
if (total>0) {
let totVal = 0
for (let l = 0; l < trend.data.length; l++) {
totVal += trend.data[l];
}
result.push(totVal);
} else {
result.push(trend.data);
}
});
});
return result;
}
However I can't understand why in the other solution the lenght and [x] don't work
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT