cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Location on infotable issue

marcelpaiva
5-Regular Member

Location on infotable issue

I spent some time trying to implement a service that would get a infotable from network connections and add some info from the things in this network.This info would be home mashup and location.

The problem came in the location fied, it would only be set to NaN.

The solution I found was to clone the infotable after the data in it and then add the same data again. Still don't know why.

Here is the code (the "nome_arvore" field is just the name of the things without underscores):

var params = {

maxDepth: undefined /* NUMBER */

};

// result: INFOTABLE dataShape: NetworkConnection

var r = Networks[Network].GetNetworkConnections(params);

var newField = new Object();

newField.name = "nome_arvore";

newField.baseType = 'STRING';

r.AddField(newField);

var newField2 = new Object();

newField2.name = "mashup";

newField2.baseType = 'MASHUPNAME';

r.AddField(newField2);

var newField3 = new Object();

newField3.name = "local";

newField3.baseType = 'LOCATION';

r.AddField(newField3);

var tableLength = r.rows.length;

for (var x = 0; x < tableLength; x++) {

    var q = r.rows.to;

    q = q.split('');

    for (i=1; i<30; i++)

        {

            if(q == "_")

                {

                    q= " ";

                }

        }

    q = q.join("");

    r.rows.nome_arvore = q;

    r.rows.mashup = Things[r.rows.to].GetHomeMashup();

    if(Things[r.rows.to].tipo == "Device") {

        r.rows.local = Things[r.rows.to].Local_de_instalação;

        //r.rows.local = lo;

}

}

var params = {

t1: r /* INFOTABLE */

};

// result: INFOTABLE dataShape: "undefined"

var I = Resources["InfoTableFunctions"].Clone(params);

var tableLength = I.rows.length;

for (var x = 0; x < tableLength; x++){

    if(Things[I.rows.to].tipo == "Device") {

        I.rows.local = Things[I.rows.to].Local_de_instalação;

}

}

var result = I;

I would like to know why I have to do it.

Thank you,

Marcel

2 REPLIES 2
PaiChung
22-Sapphire I
(To:marcelpaiva)

to me this code reads a bit strange.

I would probably do  (Warning pseudo code to follow)

myConnections = GetNetworkConnections

result = CreateInfoTableFromDataShape (define the datashape you need)

for each (var row in myConnections .rows) {

var newEntry = new Object();

newEntry.Entity = row.to

if ...{

     newEntry.Location = Things[row.to].location

}

newEntry.HomeMashup = Things[row.to].GetHomeMashup();

result.addRow(newEntry);

}

If you didn't have the if clause, I would've used DeriveFields

marcelpaiva
5-Regular Member
(To:PaiChung)

Hi Pai Chung​,

Thank you for the answer. Sorry about the code, I am used to low level coding....

Instead of creating a new infotable I tryed to just modify the infotable given by the "Networks[Network].GetNetworkConnections(params)" function. I suppose that maybe this is the problem, since the "Resources["InfoTableFunctions"].Clone(params)" function does create a new infotable and solves the problem in my code, and in your pseudo code a new infotable is created right at the beggining.

i'll consider this as a programing practice on future services.

Thank you for your time!

Marcel

Top Tags