Receiving NaN response

16 views
Skip to first unread message

Branson, GaBriella C

unread,
Nov 21, 2024, 7:45:15 PM11/21/24
to topbrai...@googlegroups.com

I have a field where I am trying to infer a decimal value using the following:

 

let fNode = wfschema.asAnalysisPosition(focusNode)

let media = fNode.media

let sum_media = media?.reduce((cur, val) => cur + val.mediaDevelopmentHours, 0)

let perfSupp = fNode.performanceSupportMaterials

let sum_perfSupp = perfSupp?.reduce((cur, val) => cur + val.developmentHours, 0)

let estTime = fNode.estimatedTimeToCompletion

if(media && media.length > 0 && perfSupp && perfSupp.length > 0 && estTime) (sum_media + sum_perfSupp) * estTime

 

It is returning an NaN and I cannot figure out why. I have verified that each of the properties it is looking at has a decimal datatype. How else should I troubleshoot?

 

Please let me know if additional information is required. Thanks!

 

GaBriella Branson

Interagency Wildland Fire Data Management – Knowledge Manager

U.S. Department of the Interior, Office of Wildland Fire 

Mobile: 907-483-0330 | gabriell...@ios.doi.gov

Follow us online: Website | Facebook | Flickr | X

Stay connected! Sign up to receive email updates

 

Logo for the Interior Department's Office of Wildland Fire  

 

Richard Cyganiak

unread,
Nov 22, 2024, 2:34:30 AM11/22/24
to topbrai...@googlegroups.com
Hi GaBriella,

One way to debug is to add console.log after each assignment:

let fNode = ...
console.log(fNode)
let media = ...
console.log(media)

And then have the Script Console panel open. Whenever console.log is executed in an ADS script, the argument is added to the output in the script console.

In JavaScript, NaN means “not a number” and is often the result of doing maths with a value that is not a number (such as a string, or an undefined value, or an array). I remember bumping into NaN when I thought I had accessed a single-value property, but it was actually multi-valued, returning an array-like value.

Richard


<image001.jpg>   <image002.png>
 

-- 
The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
To post to this group, send email to topbrai...@googlegroups.com
--- 
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/topbraid-users/CO6PR09MB7319351504DD77749220F2B0DA232%40CO6PR09MB7319.namprd09.prod.outlook.com.

Holger Knublauch

unread,
Nov 22, 2024, 2:49:33 AM11/22/24
to 'Luis Enrique Ramos García' via TopBraid Suite Users
Yes, and if you are in TopBraid Studio, you have a full Script Debugger panel at your disposal, allowing you to step through each line of code and checking what the values of the variables really are.

As Richard says, maybe some of still returned as objects (such as LiteralNode) instead of JS numbers.

Holger


Branson, GaBriella C

unread,
Nov 22, 2024, 9:07:41 AM11/22/24
to topbrai...@googlegroups.com

Thank you, Holger and Richard!

 

From: topbrai...@googlegroups.com <topbrai...@googlegroups.com> On Behalf Of Holger Knublauch
Sent: Friday, November 22, 2024 1:49 AM
To: 'Luis Enrique Ramos García' via TopBraid Suite Users <topbrai...@googlegroups.com>
Subject: [EXTERNAL] Re: [topbraid-users] Receiving NaN response

 

 

 This email has been received from outside of DOI - Use caution before clicking on links, opening attachments, or responding.  

 

Reply all
Reply to author
Forward
0 new messages