I'm doing KPI's in node-red, and I'm using node-red-node-firebird to connect my database and get the results from it. For that I made a query to select the columns I need, one of those is:
NAME Varchar(40), with an example value: "Pizzas"
(example: Select NAME from mytable)
When I receive the query response on node-red, I store it inside the msg.payload. The problem is the result that I get it isn't the string "Pizzas" but a buffer "NAME":{"type":"Buffer","data":[80,105,122,122,97,115]}}.
How can I get the string and not the buffer?
I already tried a lot of things, among them:
On the query I have tried cast(NAME AS varchar(40)) AS NAME; [NAME] without success. Put msg.payload.data.toString('utf-8') in function node but nothing happens, the function:
var objectData = msg.objectData; //this is the query response
//------------Columns----------------------------
var fields = [];
var i = 0;
if(objectData.length > 0) {
var data = objectData[0];
for(var key in data) {
fields[i] = key;
i++;
}
//TRY nº1
objectData.foreach(function(obj){
if (Buffer.isBuffer(obj) === true) {
obj = obj.toString('utf-8');
}
})
}
//-----------------------------------------
msg.method = "POST";
msg.url = //My api request//;
msg.headers = {};
msg.headers["Content-Type"] = "application/json";
msg.headers.Authorization = //auth//;
msg.payload = {
'groupID': 'Group123',
'companyID': 1221,
'table': 'DemoTable',
'fields': fields,
'data': objectData, //problem
'delete': true,
};
//TRY nº2
msg.payload = msg.payload.data.toString('utf-8');
return msg;
I solved my problem changing the select to:
SELECT cast(name as varchar(100) character set win1252) NOME FROM mytable
Thanks for the help :)
I have few OL3 MultiLineString objects like
Object { type: "MultiLineString", coordinates: Array[2] }
Object { type: "MultiLineString", coordinates: Array[3] }
Object { type: "MultiLineString", coordinates: Array[4] }
Object { type: "MultiLineString", coordinates: Array[3] }
Now I want to merge all of them in a new big MultiLineString ( like PostGIS ST_Union function ). Is there some way to do this using OL3 or I must deal with JS arrays?
Have you look at the library JSTS
Personnaly, I use this library to make an union on two geometry.
var parser = new jsts.io.OL3Parser();
var a = parser.read(first_OlFeature.getGeometry());
var b = parser.read(second_OlFeature.getGeometry());
var unionGeometry = a.union(b);
var featureFromUnion = new ol.Feature().setGeometry(parser.write(unionGeometry));
Until better solution:
var newMultiline = {};
newMultiline.type = 'MultiLineString';
var newCoordinates = [];
for(x=0; x < routeData.length; x++ ) {
var geom = routeData[x].geometry;
for (z=0; z<geom.coordinates.length; z++ ) {
newCoordinates.push( geom.coordinates[z] )
}
}
newMultiline.coordinates = newCoordinates;
I have 2 highcharts like this:http://jsfiddle.net/bqnkeLx9/
And I want to be able combine them into something like this: http://jsfiddle.net/gy2yo184/
Basically, is there an easy way to join 2 arrays together based on another array?
var category1 = [1,2,4,6,9]
var arr1 = [1,2,3,4,5]
var category2 = [1,3,6,8]
var arr2 = [6,7,8,9]
//do something to end with:
var allcategories = [1,2,3,4,6,8,9]
arr1 = [1,2,0,3,4,0,5]
arr2 = [6,0,7,0,8,9,0]
or maybe there is an easier way to plot this?
I don't think there is an easy way to do it. Or rather easier than:
making unique array of categories
manually filling up array with 0 values, when category is missing
For example:
// union without diplicates:
// taken from:
// http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
And now use case:
// arrays:
var cats_1 = [1,2,4,6,9],
cats_2 = [1,3,6,8],
data_1 = [1,2,3,4,5],
data_2 = [6,7,8,9],
data_1_modified = [],
data_2_modified = [],
categories;
// get cateogries
categories = cats_1.concat(cats_2).unique();
// you may want to sort categories
categories.sort(function(a, b) {
return a - b;
});
categories.map(function(e, i) {
var index;
if( (index = cats_1.indexOf(e)) == -1) {
data_1_modified.push(0); // missing category
} else {
data_1_modified.push(data_1[index]);
}
if( (index = cats_2.indexOf(e)) == -1) {
data_2_modified.push(0); // missing category
} else {
data_2_modified.push(data_2[index]);
}
return e;
});
$('#container1').highcharts({
xAxis: {
categories: categories
},
series: [{
data: data_1_modified
}, {
data: data_2_modified
}]
});
And live demo: http://jsfiddle.net/bqnkeLx9/1/
you can Use javascript function concat() to join two array.
assuming here is our arrays
var category1 = [1,2,4,6,9]
var arr1 = [1,2,3,4,5]
var category2 = [1,3,6,8]
var arr1 = [1,2,3,4,5]
var category = category1.concat(category1);
the elements of array category will be something like as below
[1,2,4,6,9,8]
now you can pass array in highchart
Update
After removing all duplicate elements and after sorting final array is stored in arrayuniqueCat
$(function () {
var category1 = [1,2,4,6,9];
var category2 = [6,3,1,8];
var allcategories = category1.concat(category2);
var arr1 = [2,2,0,3,4,0,5];
var arr2 = [6,0,7,0,8,9,0];
var uniqueCat = allcategories.filter(function(elem, index, self) {
return index == self.indexOf(elem);
}).sort();
$('#container1').highcharts({
xAxis: {
categories: uniqueCat
},
series: [{
data: arr1
},{
data: arr2
}]
});
});
fiddle
So i am trying to make a word jumlbe sort of program but i am running into some difficulties with the function for shuffelling the words
So i tried:
function klikk(evt){
var i:int = 0;
var ordet:String = inntastetOrd;
var lengde:int = ordet.length;
var tall:int = 0;
var karakter:String;
for(i=0;i<ordet.length; i++)
{
tall = Math.random() *ordet.length;
karakter = ordet[tall];
ordet[i] = ordet[tall];
ordet[tall] = karakter;
}
But i am getting: "Error #1069: Property "some value" not found on String and there is no default value."
Thanks for help!
If you want to chose a letter in a String, you need to transform this String into Array with the split method.
For example:
var letters:String = "word";
trace(letters[2]); // Error #1069
var a:Array = letters.split(""); // w,o,r,d
trace(a[2]); // r
I don't know why the TableView hides the end of a long string automatically for me. Is there a way that I can avoid that? Here are screenshot and code:
var data = [];
var row = Ti.UI.createTableViewRow();
var label = Ti.UI.createLabel({ text: 'ALongLongLongLongLongLongLongLongLongStringFromDatabaseOrSomewhere~', });
row.add(label);
data[0] = row;
var table = Titanium.UI.createTableView({
data: data,
style: Titanium.UI.iPhone.TableViewStyle.GROUPED,
});
Ti.UI.currentWindow.add(table);
Thanks a lot.
var toImg = row.toImage(),
rowHeight = toImg.height;
row.height = rowHeight;
toImg = null;
try
var row = Ti.UI.createTableViewRow({
height: 'auto'
});
or
var row = Ti.UI.createTableViewRow({
height: Ti.UI.SIZE
});
if you are version 2.0 or greater.