Select to view content in your preferred language

Calc Field Tool Question.

771
5
Jump to solution
10-03-2023 10:13 AM
ArmstKP
Frequent Contributor

When I use the following expression to calculate the Heat Index in AGOL, the expression works great.  When I use this same expression in a calc field tool in Velocity, I get an error.  If I remove the "if" statements, then I don't get an error and can run the analytic.  What am I missing for the reasoning that I am getting this error?

 

var dictempF = $feature.last_values 
var dicvartempF = Dictionary(dictempF) 
var tempF = Round((dicvartempF.field1.value * 9/5) + 32,1)

var dichumidity = $feature.last_values 
var dicvarhumidity = Dictionary(dichumidity) 
var humidity = Round((dicvarhumidity.field2.value),1)

var T = tempF
var RH = humidity

var HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;
if (RH < 13 && T > 80 && T < 112) HI -= ((13-RH)/4)*SQRT((17-ABS(T-95.))/17);
if (RH > 85 && T > 80 && T < 87) HI += ((RH-85)/10) * ((87-T)/5);

if (HI < 80) HI = 0.5 * (T + 61.0 + ((T-68.0)*1.2) + (RH*0.094));

return Round(HI, 1);

 

Error:

ArmstKP_0-1696353632895.png

 

 

0 Kudos
1 Solution

Accepted Solutions
PeterNasuti
Esri Contributor

@ArmstKP I have traced down the cause of this to a few things

  1. The "95." on line 13 should be 95 or 95.0
  2. Taking a square root of a negative number generating an imaginary number on line 13 is also causing failure. To address this I wrapped the calculation in another ABS() function before the SQRT() function
  3. I changed the logic pattern to IIf() functions that update the "HI" variable and also handle the false case. I often recommend this IIf() function in Arcade configurations of Velocity
var dictempF = $feature.last_values 
var dicvartempF = Dictionary(dictempF) 
var tempF = Round((dicvartempF.field1.value * 9/5) + 32,1)

var dichumidity = $feature.last_values 
var dicvarhumidity = Dictionary(dichumidity) 
var humidity = Round((dicvarhumidity.field2.value),1)

var T = tempF
var RH = humidity
var HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;

HI = IIf((RH < 13 && T > 80 && T < 112), HI - (((13-RH)/4)*SQRT(ABS((17-ABS(T-95))/17))), HI);
HI = IIf((RH > 85 && T > 80 && T < 87), HI + (((RH-85)/10) * ((87-T)/5)), HI);
HI = IIf((HI < 80), (0.5 * (T + 61.0 + ((T-68.0)*1.2) + (RH*0.094))), HI);

return Round(HI, 1);

Let me know if this addresses the validation error on your side as well and if there is anything else that comes up.

Thanks,

Peter Nasuti

View solution in original post

0 Kudos
5 Replies
PeterNasuti
Esri Contributor

@ArmstKP Happy to help on this one - but I would need a sample of $feature.last_values to replicate the issue to be provided for the Arcade field sample value. Can you either email it to me (pnasuti@esri.com), Esri Community private message a sample, or post here if it is data that can be seen by the public? Thanks!

0 Kudos
ArmstKP
Frequent Contributor

@PeterNasuti here is a sample of $feature.last_values:

{"field4":{"value":5,"created_at":"2023-09-26T20:17:05Z"},"log":{"value":507,"created_at":"2023-09-26T13:38:07Z"},"field3":{"value":157.88,"created_at":"2023-09-26T20:17:06Z"},"field1":{"value":22.0706,"created_at":"2023-09-26T20:17:05Z"},"field2":{"value":54.8348,"created_at":"2023-09-26T20:17:05Z"},"field5":{"value":-47,"created_at":"2023-09-26T20:12:09Z"},"wifi":{"value":"fe:55:a8:0a:40:ef,-55;ee:55:a8:0a:40:ef,-56;02:6a:e3:84:cf:05,-79;94:57:a5:79:5d:7d,-84;88:5a:85:f5:f9:9f,-85","created_at":"2023-09-26T13:42:54Z"}}
0 Kudos
JeffSilberberg
Frequent Contributor

A couple of questions although Peter will probably have a better answer --  

Your if ( ) {TRUE};  Startments are missing the brackets...

You appear to be using the same data for Temperature and Humidity?

$feature.last_values

 

https://developers.arcgis.com/arcade/guide/logic/

Also, why are the there three IF statements versus an if - else? 

 

 

0 Kudos
PeterNasuti
Esri Contributor

@ArmstKP I have traced down the cause of this to a few things

  1. The "95." on line 13 should be 95 or 95.0
  2. Taking a square root of a negative number generating an imaginary number on line 13 is also causing failure. To address this I wrapped the calculation in another ABS() function before the SQRT() function
  3. I changed the logic pattern to IIf() functions that update the "HI" variable and also handle the false case. I often recommend this IIf() function in Arcade configurations of Velocity
var dictempF = $feature.last_values 
var dicvartempF = Dictionary(dictempF) 
var tempF = Round((dicvartempF.field1.value * 9/5) + 32,1)

var dichumidity = $feature.last_values 
var dicvarhumidity = Dictionary(dichumidity) 
var humidity = Round((dicvarhumidity.field2.value),1)

var T = tempF
var RH = humidity
var HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;

HI = IIf((RH < 13 && T > 80 && T < 112), HI - (((13-RH)/4)*SQRT(ABS((17-ABS(T-95))/17))), HI);
HI = IIf((RH > 85 && T > 80 && T < 87), HI + (((RH-85)/10) * ((87-T)/5)), HI);
HI = IIf((HI < 80), (0.5 * (T + 61.0 + ((T-68.0)*1.2) + (RH*0.094))), HI);

return Round(HI, 1);

Let me know if this addresses the validation error on your side as well and if there is anything else that comes up.

Thanks,

Peter Nasuti

0 Kudos
ArmstKP
Frequent Contributor

@PeterNasuti Thank you for the help and reasoning.  This cleared the error, enabling me to run the analytic.

Appreciate it!!!

 

0 Kudos