Hello! I am currently working on Project in Thingworx: My Goal is to visualize data I get from a csv file in two line Charts.
For that, I created a Mashup with a big TextBox, in which i copypaste the csv data in runtime. In addition, i have an grid widget and two linechart widgets.
First of all, after pasting the csv data into the TextBox, a Service is called which parses the data and fills the infotable. The Service's Output is a infotable and the Input Parameter is a string. By now, it Looks like the infotable is filled with empty values so i am kind of confused right now...
My service looks like this:
var txt = CSVinput;
var i = 0;
//var valArray = txt.replace("\n"," ");
var valArray = txt.split(" ");
var params = {
infoTableName : "InfoTable",
dataShapeName : "LogDataShape"
};
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var cnt = 0;
while (i < valArray.length-1){
var row = new Object();
if(cnt == 0){
row.DateTime = valArray + " " + valArray[i+1];
cnt = 1;
}
else if(cnt == 1){
row.Temperature = valArray;
cnt = 2;
}
else if(cnt == 2){
row.Press_601_mbar = valArray;
cnt = 3;
}
else if(cnt == 3){
row.Press_651_mbar = valArray;
cnt = 0;
result.AddRow(row);
}
i++;
}
the Input string looks like this: in the TextBox, there is exactly one space between each value and I asume a "\n"-endline at the end of the last value.
Date | Time | Press_601_mbar | Press_651_mbar | Temp_518a_°C |
02.03.2017 | 23:40:15 | -93 | -332 | 35.4 |
02.03.2017 | 23:40:16 | -95 | -333 | 35.4 |
02.03.2017 | 23:40:17 | -97 | -334 | 35.4 |
02.03.2017 | 23:40:18 | -99 | -333 | 35.4 |
02.03.2017 | 23:40:19 | -101 | -333 | 35.4 |
02.03.2017 | 23:40:20 | -102 | -336 | 35.4 |
02.03.2017 | 23:40:21 | -101 | -338 | 35.4 |
02.03.2017 | 23:40:22 | -95 | -343 | 35.4 |
02.03.2017 | 23:40:23 | -88 | -346 | 35.4 |
02.03.2017 | 23:40:24 | -85 | -353 | 35.4 |
02.03.2017 | 23:40:25 | -83 | -356 | 35.3 |
02.03.2017 | 23:40:26 | -85 | -358 | 35.4 |
02.03.2017 | 23:40:27 | -87 | -356 | 35.4 |
02.03.2017 | 23:40:28 | -88 | -356 | 35.4 |
I would really really appreciate any kind of advice or help you can give me!!
Thank you so much in advance!
Hello,
You are doing your AddRow only for one case:
...
else if(cnt == 3)
...
I don't understand very well your service but you can add the snippet Logger to see what your service is doing.
However, it would not be easier to use an csv parser and directly store your data in to an infotable?
Best regards,
Ana Duarte
Hi,
To add to what Ana has already mentioned, here is the link to download the csv parser extension: https://marketplace.thingworx.com/Items/csv-parser