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:
Solved! Go to Solution.
@ArmstKP I have traced down the cause of this to a few things
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
@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!
@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"}}
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?
@ArmstKP I have traced down the cause of this to a few things
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
@PeterNasuti Thank you for the help and reasoning. This cleared the error, enabling me to run the analytic.
Appreciate it!!!