Hello and Happy New Year everyone 🙂
So the following map computes the Index under Symbology via Arcade which is cool but I would like to add the Index as a column/attribute/field to the data. The code runs fine but since I am still new to Arcade can you @LisaB as I believe it's your code please explain what the following functions/syntax do? (I have added comments next to the syntax that I am having trouble understanding). Cheers!
Code:
var fields = [
{ value: $feature["B17020_calc_pctPovE"], comparison: 13, alias: "Poverty rate" }, // what is value, comparison and it's value and alias doing?
{ value: $feature["B08201_calc_pctNoVehE"], comparison: 9, alias: "Households without access to a vehicle" },
{ value: $feature["B28002_calc_pctNoIntE"], comparison: 14, alias: "Households without access to internet" },
{ value: $feature["B27010_calc_pctNoInsE"], comparison: 9, alias: "Households without health insurance" },
{ value: $feature["B01001_calc_pctDependE"], comparison: 38, alias: "Dependent population (Ages <18 or 65+)" }
];
function calcFactor(fieldsArray){
var factorCount = 0 // Why add factorCount?
var factorTotal = 0 // // Why add factorTotal?
for(var x in fieldsArray){
var val = fieldsArray[x].value // What's the syntax doing here?
var comp = fieldsArray[x].comparison // What's the syntax doing here?
var indexValue = (val/comp)*100 // Why divide val by comp?
factorTotal += indexValue // What's the syntax doing here?
factorCount += 1 // What's the syntax doing here?
}
var overallIndex = factorTotal/factorCount
var indexText = when(overallIndex < 60, "Lowest Stress", overallIndex >= 60 && overallIndex < 90, "Low Stress", overallIndex >= 90 && overallIndex < 110, "Average Stress", overallIndex >= 110 && overallIndex < 140, "High Stress", overallIndex >= 140, "Highest Stress", "N/A")
return indexText
}