Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi all,
could somebody show me what is wrong in my code?? I wanted to go thru all the rows in infotable to add them to stream. but unfortunately only last row is added, despite the fact that first part of code reads all *.csv file.
var params = {
path: "ptc.csv" /* STRING */,
columnMappings: undefined /* STRING */,
hasHeader: true /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: "dd.MM.yyyy HH:mm:ss" /* STRING */,
fileRepository: "HYDAC_FR" /* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: undefined /* STRING */,
stringDelimiter: "\"" /* STRING */,
dataShape: "PTC_DATASHAPE" /* DATASHAPENAME */
};
var myInfoTable = Resources["CSVParserFunctions"].ReadCSVFile(params);
var tableLength = myInfoTable.rows.length;
for (var x = 0; x < tableLength; x++) {
var row = myInfoTable.rows[x];
var tags = new Array();
var timestamp = new Date();
var values = Things["PTC_STREAM"].CreateValues();
values.Par2 = row.Par2; //NUMBER
values.Par1 = row.Par1; //NUMBER
values.Par3 = row.Par3; //NUMBER
values.Date = row.Date; //DATETIME
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["PTC_STREAM"].AddStreamEntry(params);
}
thx in advance
gucio
Solved! Go to Solution.
You can't add two stream entries at the exact same timestamp (they will be overwritten), with new Date() you have millisecond precision and the for loop goes faster than 1 millisecond ;)
Well I think you are adding the row in stream after the loop .So basically it is iterating through the infotable and the last row is getting added in the stream .Try adding the stream entry inside the loop so that for every iteration it adds the values to the stream .
Thanks ,
Mukul Narang
You can't add two stream entries at the exact same timestamp (they will be overwritten), with new Date() you have millisecond precision and the for loop goes faster than 1 millisecond ;)
hi Carles,
Probably the timestamp could be the topic.
Is there any sleep/wait method/function in TX to wait for a while before new row will be read??
pause(1);
1-> Milliseconds
you are right - time was the issue.
I have to add "pause(1000)" to all rows be read.
but from my perspective real timestamp is not important, so I decided to write code that will insert data from *.csv file into timestamp cell:
timestamp : row.Date,
Thx Carles for your time :)