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

Totaling valuestream - JSON does not allow non-finite numbers problem

DavorGranic
16-Pearl

Totaling valuestream - JSON does not allow non-finite numbers problem

I`m going trough  valuestream entries and filtering them and saving to infotable in a service.

Basicaly im totalling values between hour A to hour B on each day for a week.

 

Problem is I get error when i use:

Totall+= StreamValue;

 

Im getting error:

"Wrapped org.json.JSONException: JSON does not allow non-finite numbers. Cause: JSON does not allow non-finite numbers."

 

everythign works fine if I use Totall+=1 or Totall= StreamValue;  but  +=StreamValue makes a problem.

 

Code used:

var params = {

                oldestFirst: undefined /* BOOLEAN */,

                maxItems: undefined /* NUMBER */,

                endDate: undefined /* DATETIME */,

                query: undefined /* QUERY */,

                startDate: undefined /* DATETIME */

};

var data = me.QueryPropertyHistory(params);

var params = {

                infoTableName : "InfoTable",

                dataShapeName : "StorageDataShape_granicd"

};

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var tableLength = data.rows.length;

 

var newEntry = new Object();

var Once=0;

for (var y = 0; y < 7; y++)

{

        var Type1=0;

        Once=0;

        newEntry.timestamp=null;

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

        {

            var row=data.getRow(x);

            if(row.timestamp.getDay()===y && row.timestamp.getHours() >= FromHour && row.timestamp.getHours() < TillHour) //row.timestamp.getDay()==y

            {

                if(Once==0)

                {

                    newEntry.timestamp=row.timestamp;

                    Once=1;

                }

                Type1+= row.LM;      //problem line      

          }

       }

       newEntry.LM_Totall=Type1;

       result.AddRow(newEntry);        

}

me.Totallhours=result;

ACCEPTED SOLUTION

Accepted Solutions

Turns out problem was some properties in stream were NaN like error said(tho it refered to non-finite). I just needed to check in code first if they are NaN/empty then try to add them if they are not. :/ Best way is "if(x!=x)"  x - some property value.

View solution in original post

3 REPLIES 3
sbalta
13-Aquamarine
(To:DavorGranic)

Hello @DavorGranic,

 

Not sure exactly where the problem in the code could be, but I was thinking that this article might help:

https://www.ptc.com/en/support/article?n=CS267063 (refering to JSON not allowing non-finite numbers)

Turns out problem was some properties in stream were NaN like error said(tho it refered to non-finite). I just needed to check in code first if they are NaN/empty then try to add them if they are not. :/ Best way is "if(x!=x)"  x - some property value.

slangley
23-Emerald II
(To:DavorGranic)

Hi @DavorGranic.

 

If you are satisfied with the solution you posted, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Thank you for using our Community!

 

Regards.

 

--Sharon

Announcements


Top Tags