Stream AddStreamEntry overwrites the data
hello, i am trying to cache some data, so: i have a service that has its output as an InfoTable and retrieves a couple of rows and 5 columns of data. i would like to cache this service as it takes some time to run, but the below code only caches the last row form the server even thought the loop is ok and reads all the rows. (that s why i aded the ii object, for debugging purposes) in monitoring i could not find anything. i also wanted to try the AddStreamEntries service but i got stuck with its implementation
can you please help?
var values;
var params = {
infoTableName : "InfoTable",
dataShapeName : "GabiDS"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(AMTable_ModuleDDS_CRA_PG)
var table = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var tags = new Array();
var timestamp = new Date();
// result: INFOTABLE dataShape: AMTable_ModuleDDS_CRA_PG
var actions = Things["GabiThing"].GetData();
if (actions) {
// loop through infotable
if(Things["GabiStream"]){
var params = {
endDate: timestamp /* DATETIME */,
immediate: true /* BOOLEAN */,
startDate: undefined /* DATETIME */
};
// no return
Things["GabiStream"].PurgeStreamEntries(params);
}
var tableLength = actions.rows.length;
for (var x = 0; x < tableLength; x++) {
var row = actions[x];
values = Things["GabiStream"].CreateValues();
try {
values.x = row.x; //INTEGER
} catch (err) {
logger.error('x is null');
}
try {
values.y = row.y; //INTEGER
} catch (err) {
logger.error('y is null');
}
try {
values.z = row.z; //INTEGER
} catch (err) {
logger.error('z is null');
}
try {
values.t = row.t; //INTEGER
} catch (err) {
logger.error('t is null');
}
var ii = new Object();
ii.x = row.x;
ii.y = row.y;
ii.z = row.z;
ii.t = row.t;
table.AddRow(ii);
var location = new Object();
location.latitude = 0;
location.longitude = 0;
location.elevation = 0;
location.units ="WGS84";
var params = {
tags : tags,
timestamp : timestamp,
source : me.name,
values : values,
location : location
};
Things["GabiStream"].AddStreamEntry(params);
}
}
var result = table;

