Hello!!
I have been looking all over Esri Community and I cannot figure out how to correctly use Arcade to form a rating system!
For some background information on what I am trying to do: I am an intern who monitors any and all pedestrian features. I take measurements such as slope, length width, gap size, signal timing, etc. to ensure that the features are ADA compliant. There is a rating system in place to help us determine the severity of the damage of the feature, if there is any at all. This rating system is an excel sheet that we manually use and we compare it to the data collected to rate the feature.
What I want to do is automate this process. I have successfully created this rating system, however, the expression I came up with is very very long and tedious to add on to. I have limited knowledge of Arcade so any help would be much appreciated!
var cs = When($feature["cross_slope"]>2 && $feature["cross_slope"]<2.5, 8, when($feature["cross_slope"]>=2.5 && $feature["cross_slope"]<3, 7, when($feature["cross_slope"]>=3 && $feature["cross_slope"]<4, 6, when($feature["cross_slope"]>=4 && $feature["cross_slope"]<5, 5, when($feature["cross_slope"]>=5 && $feature["cross_slope"]<6, 4, when($feature["cross_slope"]>=6 && $feature["cross_slope"]<7, 3, when($feature["cross_slope"]>=7 && $feature["cross_slope"]<1000, 2, 10)))))))
var gw = when($feature["gap_width"]=='rating6gap', 6, when($feature["gap_width"]=='rating3gap', 3, when($feature["gap_width"]=='rating2gap', 2, 10)))
var lw = when($feature["lip_width"]=='rating8lip', 8, when($feature["lip_width"]=='rating6lip', 6, when($feature["lip_width"]=='rating3lip', 3, 10)))
var pa = when($feature["passing_area"]=='no', 5, 10)
var ras = when($feature["road_slope"]>$feature["running_slope"] && 5<$feature["running_slope"]<11, 9, when($feature["road_slope"]>$feature["running_slope"]>$feature["running_slope"] && 11<=$feature["running_slope"]<100, 8, 10))
var rw = when($feature["route_width"]>35 && $feature["route_width"]<36, 7, when($feature["route_width"]>32 && $feature["route_width"]<=35, 5, when($feature["route_width"]>28 && $feature["route_width"]<=32, 4, when($feature["route_width"]>24 && $feature["route_width"]<=28, 3, when($feature["route_width"]>0 && $feature["route_width"]<=24, 2, 10)))))
var rs = when($feature["running_slope"]>5 && $feature["running_slope"]<6, 8, when($feature["running_slope"]>=6 && $feature["running_slope"]<7, 7, when($feature["running_slope"]>=7 && $feature["running_slope"]<8, 6, when($feature["running_slope"]>=8 && $feature["running_slope"]<9, 5, when($feature["running_slope"]>=9 && $feature["running_slope"]<10, 4, when($feature["running_slope"]>=10 && $feature["running_slope"]<11, 3, when($feature["running_slope"]>=11 && $feature["running_slope"]<100000, 2, 10)))))))
var sub = when(cs == rs && cs != 10 && rs != 10, cs-1, when(cs == rw && rw != 10, rw-1, when(cs == lw && lw != 10, lw-1, when(cs == gw && gw !=10, gw-1, when(cs == pa && pa != 10, pa-1, when(rs == rw && rw != 10, rw-1, when(rs == lw && lw != 10, lw-1, when(rs == gw && gw != 10, gw-1, when(rs == pa && pa != 10, pa-1, when(rw == lw && lw !=10, lw-1, when(rw == gw && gw != 10, gw-1, when(rw == pa && pa != 10, pa-1, when(lw == gw && gw != 10, gw-1, when(lw == pa && pa != 10, pa-1, when(gw ==pa && pa != 10, pa-1, 10)))))))))))))))
var total = min(cs, gw, lw, pa, rw, rs, sub)
iif(total == 10, 'Yes', 'No')
Solved! Go to Solution.
It sounds like quite the procedure! Here are a few pointers:
For example, That first line of your expression could be written as follows:
var c = $feature["cross_slope"]
var cs = When(
c >= 7, 2,
c >= 6, 3,
c >= 5, 4,
c >= 4, 5,
c >= 3, 6,
c >= 2.5, 7,
c > 2, 8,
10
)
Which is a bit easier to read than before.
You might also want to look at the Decode function, too, which can take an input of any kind and return corresponding values. The next two lines of code in your expression might be written:
var gw = Decode($feature["gap_width"],
'rating6gap', 6,
'rating3gap', 3,
'rating2gap', 2,
10
)
var lw = Decode($feature["lip_width"],
'rating8lip', 8,
'rating6lip', 6,
'rating3lip', 3,
10
)
If you want to get into more advanced Arcade, you can even work with your own custom functions. We can, for instance, define a function that returns True if a given value is over 10, then use that together with the Any function to replicate the final two lines of your expression.
function overTen(value) { return value > 10 }
return Any([cs, gw, lw, pa, rw, rs, sub], overTen)
Oh, it's no trouble. This expression has gotten fairly complex, so it's understandable that some of what I'm doing seems a bit opaque.
The text version of what I did was create a function that looks at each field in an array of dictionaries, then compare that field against every field listed in a "comps" array, and uses Push to add that value to the empty array I created.
However! If you need to compare every field with every other field, we don't even need to worry about that. If we have an array of all fields, we can just loop over it. Say there were 10 fields, you'd need to compare any one field against the other 9.
Since the output of compDecrease will be identical for two matching values regardless of order (that is, compDecrease(a, b) == compDecrease(b, a), as long as a == b), we can just compare 1 against 2-10, 2 against 3-10, 3 against 4-10, etc.
So, try this instead, as it may be easier to understand. We will iterate over all the fields in an array of fields to compare. For each field, we'll compare it with all the remaining fields in the array.
var compFields = [
w2,
gw,
lw,
etc...
]
var outArray = [];
// Iterate over fields
for (var f1 = 0; f1 < Count(compFields); f1++){
// Start at next field, go to end
for (var f2 = f1 + 1; f2 < Count(compFields); f2++){
// Compare fields and push to outArray
Push(outArray, compDecrease(compFields[f1], compFields[f2]))
}
}
return Min(outArray);
That's the best part of using nested loops like this. You don't need to repeat anything! The inner loop will check all the fields against the first, but then the outer loop moves to the next field and then checks it against the rest of the fields in the inner loop.
Here's a simplified nested loop and its output to help demonstrate the concept:
var strings = ['here', 'are', 'some', 'sample', 'strings']
var outstr = ''
for (var f1 = 0; f1 < Count(strings); f1++){
for (var f2 = f1 + 1; f2 < Count(strings); f2++){
outstr += `Outer loop ${f1}, Inner loop ${f2}: ${strings[f1]} - ${strings[f2]}\n`
}
}
return outstr
Which returns
Outer loop 0, Inner loop 1: here - are
Outer loop 0, Inner loop 2: here - some
Outer loop 0, Inner loop 3: here - sample
Outer loop 0, Inner loop 4: here - strings
Outer loop 1, Inner loop 2: are - some
Outer loop 1, Inner loop 3: are - sample
Outer loop 1, Inner loop 4: are - strings
Outer loop 2, Inner loop 3: some - sample
Outer loop 2, Inner loop 4: some - strings
Outer loop 3, Inner loop 4: sample - strings
It sounds like quite the procedure! Here are a few pointers:
For example, That first line of your expression could be written as follows:
var c = $feature["cross_slope"]
var cs = When(
c >= 7, 2,
c >= 6, 3,
c >= 5, 4,
c >= 4, 5,
c >= 3, 6,
c >= 2.5, 7,
c > 2, 8,
10
)
Which is a bit easier to read than before.
You might also want to look at the Decode function, too, which can take an input of any kind and return corresponding values. The next two lines of code in your expression might be written:
var gw = Decode($feature["gap_width"],
'rating6gap', 6,
'rating3gap', 3,
'rating2gap', 2,
10
)
var lw = Decode($feature["lip_width"],
'rating8lip', 8,
'rating6lip', 6,
'rating3lip', 3,
10
)
If you want to get into more advanced Arcade, you can even work with your own custom functions. We can, for instance, define a function that returns True if a given value is over 10, then use that together with the Any function to replicate the final two lines of your expression.
function overTen(value) { return value > 10 }
return Any([cs, gw, lw, pa, rw, rs, sub], overTen)
Wonderful! Thank you for the advice! This looks a lot cleaner than my original function.
My next question is what should I do about the function on line 14?
On line 14, the intended point of the function was to find 2 variables/fields that had the same rating and then because they are the same, the rating would go down one. So lets say that $feature["cross_slope"] and $feature["running_slope"] both equal a rating of 7, because they are the same, the total rating would be 6. Then at the end we take the worst (lowest) total rating out of all of them.
We are expanding our operation of collecting data, this means that we need to add more fields and more conditions in our forms and expressions. I have similar functions to line 14 that are about 3 or 4 times as long and it is very very difficult to read through, it is especially difficult to add on to it. Is there any way to try and make it cleaner? I have experimented with user defined functions and I cannot seem to get it to work for this one.
Thank you again for your help!!
Yes, line 14 is quite a lot to have in a single line, but it can be similarly cleaned up, and is a great case for a custom function. If I'm understanding it correctly, you would like to decrease the score if two given fields match.
I should point out that when you have successive conditions in a where function, it stops evaluating as soon as one is true. If you want the lowest value from line 14, you'll need some other way to get at it.
Anyway, here's a slightly simpler way to rewrite what's happening in line 14, I think.
// compare two fields. if equal, return the first field's value minus 1, otherwise return 10
function compDecrease(field, compfield){
if (field != 10 && field == compfield){
return field-1
}
else {
return 10
}
}
// populate an array with the per-field comparisons from compDecrease function
comps = [
compDecrease(cs, rw),
compDecrease(cs, lw),
compDecrease(cs, gw),
compDecrease(cs, pa),
compDecrease(rs, rw),
compDecrease(rs, lw),
compDecrease(rs, gw),
compDecrease(rs, pa),
compDecrease(rw, lw),
compDecrease(rw, gw),
compDecrease(rw, pa),
compDecrease(lw, gw),
compDecrease(lw, pa),
compDecrease(gw, pa)
]
// get the lowest value out of the comps array
var sub = Min(comps)
Am I correct in assuming that for the input series of fields, you basically want to compare them all with each other? There may be an even more concise way to write that kind of thing using a couple of loops.
Also, do you want a given value to decrease by more than one if there are multiple matches?
Hello!
Yes I am trying to compare all of them together to find the lowest rating score, and I only need the score to decrease by one even if there are multiply matches. I have put all of your input together into one expression, and it works great!
var cross = $feature["cross_slope"]
var cs = When(
cross >= 7 && cross < 10000, 2,
cross >= 6 && cross < 7, 3,
cross >= 5 && cross < 6, 4,
cross >= 4 && cross < 5, 5,
cross >= 3 && cross < 4, 6,
cross >= 2.5 && cross < 3, 7,
cross > 2 && cross < 2.5, 8,
10
)
var run = $feature["running_slope"]
var rs = When(
run>5 && run<6, 8,
run>=6 && run<7, 7,
run>=7 && run<8, 6,
run>=8 && run<9, 5,
run>=9 && run<10, 4,
run>=10 && run<11, 3,
run>=11 && run<100000, 2, 10
)
var road = $feature["road_slope"]
var ras = when(
road > run && 5 < run < 11, 9,
road > run > run && 11 <= run < 100, 8, 10
)
var width = $feature["route_width"]
var rw = when(
width > 35 && width < 36, 7,
width > 32 && width <= 35, 5,
width > 28 && width <= 32, 4,
width > 24 && width <= 28, 3,
width > 0 && width <= 24, 2, 10
)
var gw = Decode($feature["gap_width"],
'rating6gap', 6,
'rating3gap', 3,
'rating2gap', 2,
10
)
var lw = Decode($feature["lip_width"],
'rating8lip', 8,
'rating6lip', 6,
'rating3lip', 3,
10
)
var pa = when(
$feature["passing_area"] == 'no', 5, 10
)
// compare two fields. if equal, return the first field's value minus 1, otherwise return 10
function compDecrease(field, compfield){
if (field != 10 && field == compfield){
return field-1
}
else {
return 10
}
}
// populate an array with the per-field comparisons from compDecrease function
var comps = [
compDecrease(cs, rw),
compDecrease(cs, lw),
compDecrease(cs, gw),
compDecrease(cs, pa),
compDecrease(cs, rs),
compDecrease(rs, rw),
compDecrease(rs, lw),
compDecrease(rs, gw),
compDecrease(rs, pa),
compDecrease(rw, lw),
compDecrease(rw, gw),
compDecrease(rw, pa),
compDecrease(lw, gw),
compDecrease(lw, pa),
compDecrease(gw, pa)
]
// get the lowest value out of the comps array
var sub = min(comps)
min(cs, gw, lw, pa, rw, rs, sub)
The expression as a whole is a lot cleaner and it is so much easier to read and understand! However, I must admit I am still worried about the length of the "comps" variable. For this expression it is perfect, but for some of our other forms it could get messy fast.
var sub = when(wr == gw && gw !=10, wr-1, when(wr == lw && lw != 10, wr-1, when(wr == ll && ll != 10, wr-1, when(wr == lwidth && lwidth != 10, wr-1, when(wr == lrs && lrs != 10, wr-1, when(wr == lcs && lcs != 10, wr-1, when(lw == gw && gw != 10, lw-1, when(gw == ll && ll != 10, gw-1, when(gw == lwidth && lwidth != 10, gw-1, when(gw == lrs && lrs != 10, gw-1, when(gw == lcs && lcs != 10, gw-1, when(lw == ll && ll != 10, lw-1, when(lw == lwidth && lwidth != 10, lw-1, when(lwidth == ll && ll != 10, lwidth-1, when(lwidth == lrs && lrs != 10, lwidth-1, when(lwidth == lcs && lcs != 10, lwidth-1, when(lrs == lcs && lcs != 10, lrs-1, when(rcs == rrs && rcs != 10, rrs-1, when(rcs == rightflare && rcs != 10, rightflare-1, when(rcs == rw && rcs != 10, rw-1, when(rcs == lcs && rcs != 10, lcs-1, when(rcs == lrs && rcs != 10, lrs-1, when(rrs == rightflare && rrs != 10, rightflare-1, when(rrs == rw && rrs != 10, rw-1, when(rrs == lcs && rrs != 10, lcs-1, when(rrs == lrs && rrs != 10, lrs-1, when(rightflare == rw && rightflare != 10, rw-1, when(rightflare == lcs && rightflare != 10, lcs-1, when(rightflare == lrs && rightflare != 10, lrs-1, when(rw == lcs && rw != 10, lcs-1, when(rw == lrs && rw != 10, lrs-1, when(lrs == lcs && lrs != 10, lcs-1, when(rcs == wr && rcs != 10, wr-1, when(rcs == gw && rcs != 10, gw-1, when(rcs == ll && rcs != 10, ll-1, when(rcs == lwidth && rcs != 10, lwidth-1, when(rcs == lw && rcs != 10, lw-1, 10)))))))))))))))))))))))))))))))))))))
var sub2 = when(rrs == wr && rrs != 10, wr-1, when(rrs == gw && rrs != 10, gw-1, when(rrs == ll && rrs != 10, ll-1, when(rrs == lwidth && rrs != 10, lwidth-1, when(rrs == lw && rrs != 10, lw-1, when(rightflare == wr && rightflare != 10, wr-1, when(rightflare == gw && rightflare != 10, gw-1, when(rightflare == ll && rightflare != 10, ll-1, when(rightflare == lwidth && rightflare != 10, lwidth-1, when(rw == wr && rw != 10, wr-1, when(rw == gw && rw != 10, gw-1, when(rw == lwidth && rw != 10, lwidth-1, when(rw == ll && rw != 10, ll-1, when(rw == lw && rw != 10, lw-1, when(lcs == wr && lcs != 10, wr-1, when(lcs == gw && lcs != 10, gw-1, when(lcs == ll && lcs != 10, ll-1, when(lcs == lwidth && lcs != 10, lwidth-1, when(lcs == lw && lcs != 10, lw-1, when(lrs == wr && lrs != 10, wr-1, when(lrs == gw && lrs != 10, gw-1, when(lrs == ll && lrs != 10, ll-1, when(lrs == lwidth && lrs != 10, lwidth-1, when(lrs == lw && lrs != 10, lw-1, when(lrs == gw && lrs != 10, gw-1, when(lrs == lw && lrs != 10, lw-1, when(lcs == gw && lcs != 10, gw-1, when(lcs == lw && lcs != 10, lw-1, when(leftflare == wr && leftflare != 10, wr-1, when(leftflare == gw && leftflare != 10, gw-1, when(leftflare == lw && leftflare != 10, lw-1, when(leftflare == ll && leftflare != 10, ll-1, when(leftflare == lwidth && leftflare != 10, lwidth-1, when(leftflare == lrs && leftflare != 10, lrs-1, when(leftflare == lcs && leftflare != 10, lcs-1, when(leftflare == rw && leftflare != 10, rw-1, when(leftflare == rrs && leftflare != 10, rrs-1, when(leftflare == rcs && leftflare != 10, rcs-1, when(leftflare == rightflare && leftflare != 10, rightflare-1, when(cutt == wr && cutt != 10, wr-1, when(cutt == gw && cutt != 10, gw-1, when(cutt == lw && cutt != 10, lw-1, when(cutt == ll && cutt != 10, ll-1, when(cutt == lwidth && cutt != 10, lwidth-1, when(cutt == lrs && cutt != 10, lrs-1, when(cutt == lcs && cutt != 10, lcs-1, when(cutt == rw && cutt != 10, rw-1, when(cutt == rrs && cutt != 10, rrs-1, when(cutt == rcs && cutt != 10, rcs-1, when(cutt == leftflare && cutt != 10, leftflare-1, when(cutt == rightflare && cutt != 10, rightflare-1, 10) ))))))))))))))))))))))))))))))))))))))))))))))))))
var sub3 = when(leftflare2 == wr && leftflare2 != 10, wr-1, when(leftflare2 == gw && leftflare2 != 10, gw-1, when(leftflare2 == lw && leftflare2 != 10, lw-1, when(leftflare2 == ll && leftflare2 != 10, ll-1, when(leftflare2 == lwidth && leftflare2 != 10, lwidth-1, when(leftflare2 == lrs && leftflare2 != 10, lrs-1, when(leftflare2 == lcs && leftflare2 != 10, lcs-1, when(leftflare2 == rw && leftflare2 != 10, rw-1, when(leftflare2 == rrs && leftflare2 != 10, rrs-1, when(leftflare2 == rcs && leftflare2 != 10, rcs-1, when(leftflare2 == leftflare && leftflare2 != 10, leftflare-1, when(leftflare2 == rightflare && leftflare2 != 10, rightflare-1, when(leftflare2 == leftflare3 && leftflare2 != 10, leftflare3-1, when(leftflare2 == leftflare4 && leftflare2 != 10, leftflare4-1, when(leftflare2 == rightflare2 && leftflare2 != 10, rightflare2-1, when(leftflare2 == rightflare3 && leftflare2 != 10, rightflare3-1, when(leftflare2 == rightflare4 && leftflare2 != 10, rightflare4-1, when(leftflare2 == rw2 && leftflare2 != 10, rw2-1, when(leftflare2 == rw3 && leftflare2 != 10, rw3-1, when(leftflare2 == rw4 && leftflare2 != 10, rw4-1, when(leftflare2 == rrs2 && leftflare2 != 10, rrs2-1, when(leftflare2 == rrs3 && leftflare2 != 10, rrs3-1, when(leftflare2 == rrs4 && leftflare2 != 10, rrs4-1, when(leftflare2 == rcs2 && leftflare2 != 10, rcs2-1, when(leftflare2 == rcs3 && leftflare2 != 10, rcs3-1, when(leftflare2 == rcs3 && leftflare2 != 10, rcs3-1, when(leftflare2 == rcs4 && leftflare2 != 10, rcs4-1, when(leftflare3 == wr && leftflare3 != 10, wr-1, when(leftflare3 == gw && leftflare3 != 10, gw-1, when(leftflare3 == lw && leftflare3 != 10, lw-1, when(leftflare3 == ll && leftflare3 != 10, ll-1, when(leftflare3 == lwidth && leftflare3 != 10, lwidth-1, when(leftflare3 == lrs && leftflare3 != 10, lrs-1, when(leftflare3 == lcs && leftflare3 != 10, lcs-1, when(leftflare3 == rw && leftflare3 != 10, rw-1, when(leftflare3 == rrs && leftflare3 != 10, rrs-1, when(leftflare3 == rcs && leftflare3 != 10, rcs-1, when(leftflare3 == leftflare && leftflare3 != 10, leftflare-1, when(leftflare3 == rightflare && leftflare3 != 10, rightflare-1, when(leftflare3 == leftflare3 && leftflare3 != 10, leftflare3-1, when(leftflare3 == leftflare4 && leftflare3 != 10, leftflare4-1, when(leftflare3 == rightflare2 && leftflare3 != 10, rightflare2-1, when(leftflare3 == rightflare3 && leftflare3 != 10, rightflare3-1, when(leftflare3 == rightflare4 && leftflare3 != 10, rightflare4-1, when(leftflare3 == rw2 && leftflare3 != 10, rw2-1, when(leftflare3 == rw3 && leftflare3 != 10, rw3-1, when(leftflare3 == rw4 && leftflare3 != 10, rw4-1, when(leftflare3 == rrs2 && leftflare3 != 10, rrs2-1, when(leftflare3 == rrs3 && leftflare3 != 10, rrs3-1, when(leftflare3 == rrs4 && leftflare3 != 10, rrs4-1, when(leftflare3 == rcs2 && leftflare3 != 10, rcs2-1, when(leftflare3 == rcs3 && leftflare3 != 10, rcs3-1, when(leftflare3 == rcs3 && leftflare3 != 10, rcs3-1, when(leftflare3 == rcs4 && leftflare3 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub4 = when(leftflare4 == wr && leftflare4 != 10, wr-1, when(leftflare4 == gw && leftflare4 != 10, gw-1, when(leftflare4 == lw && leftflare4 != 10, lw-1, when(leftflare4 == ll && leftflare4 != 10, ll-1, when(leftflare4 == lwidth && leftflare4 != 10, lwidth-1, when(leftflare4 == lrs && leftflare4 != 10, lrs-1, when(leftflare4 == lcs && leftflare4 != 10, lcs-1, when(leftflare4 == rw && leftflare4 != 10, rw-1, when(leftflare4 == rrs && leftflare4 != 10, rrs-1, when(leftflare4 == rcs && leftflare4 != 10, rcs-1, when(leftflare4 == leftflare && leftflare4 != 10, leftflare-1, when(leftflare4 == rightflare && leftflare4 != 10, rightflare-1, when(leftflare4 == leftflare3 && leftflare4 != 10, leftflare3-1, when(leftflare4 == leftflare4 && leftflare4 != 10, leftflare4-1, when(leftflare4 == rightflare2 && leftflare4 != 10, rightflare2-1, when(leftflare4 == rightflare3 && leftflare4 != 10, rightflare3-1, when(leftflare4 == rightflare4 && leftflare4 != 10, rightflare4-1, when(leftflare4 == rw2 && leftflare4 != 10, rw2-1, when(leftflare4 == rw3 && leftflare4 != 10, rw3-1, when(leftflare4 == rw4 && leftflare4 != 10, rw4-1, when(leftflare4 == rrs2 && leftflare4 != 10, rrs2-1, when(leftflare4 == rrs3 && leftflare4 != 10, rrs3-1, when(leftflare4 == rrs4 && leftflare4 != 10, rrs4-1, when(leftflare4 == rcs2 && leftflare4 != 10, rcs2-1, when(leftflare4 == rcs3 && leftflare4 != 10, rcs3-1, when(leftflare4 == rcs3 && leftflare4 != 10, rcs3-1, when(leftflare4 == rcs4 && leftflare4 != 10, rcs4-1, when(rightflare2 == wr && rightflare2 != 10, wr-1, when(rightflare2 == gw && rightflare2 != 10, gw-1, when(rightflare2 == lw && rightflare2 != 10, lw-1, when(rightflare2 == ll && rightflare2 != 10, ll-1, when(rightflare2 == lwidth && rightflare2 != 10, lwidth-1, when(rightflare2 == lrs && rightflare2 != 10, lrs-1, when(rightflare2 == lcs && rightflare2 != 10, lcs-1, when(rightflare2 == rw && rightflare2 != 10, rw-1, when(rightflare2 == rrs && rightflare2 != 10, rrs-1, when(rightflare2 == rcs && rightflare2 != 10, rcs-1, when(rightflare2 == leftflare && rightflare2 != 10, leftflare-1, when(rightflare2 == rightflare && rightflare2 != 10, rightflare-1, when(rightflare2 == leftflare3 && rightflare2 != 10, leftflare3-1, when(rightflare2 == leftflare4 && rightflare2 != 10, leftflare4-1, when(rightflare2 == rightflare2 && rightflare2 != 10, rightflare2-1, when(rightflare2 == rightflare3 && rightflare2 != 10, rightflare3-1, when(rightflare2 == rightflare4 && rightflare2 != 10, rightflare4-1, when(rightflare2 == rw2 && rightflare2 != 10, rw2-1, when(rightflare2 == rw3 && rightflare2 != 10, rw3-1, when(rightflare2 == rw4 && rightflare2 != 10, rw4-1, when(rightflare2 == rrs2 && rightflare2 != 10, rrs2-1, when(rightflare2 == rrs3 && rightflare2 != 10, rrs3-1, when(rightflare2 == rrs4 && rightflare2 != 10, rrs4-1, when(rightflare2 == rcs2 && rightflare2 != 10, rcs2-1, when(rightflare2 == rcs3 && rightflare2 != 10, rcs3-1, when(rightflare2 == rcs3 && rightflare2 != 10, rcs3-1, when(rightflare2 == rcs4 && rightflare2 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub5 = when(rightflare3 == wr && rightflare3 != 10, wr-1, when(rightflare3 == gw && rightflare3 != 10, gw-1, when(rightflare3 == lw && rightflare3 != 10, lw-1, when(rightflare3 == ll && rightflare3 != 10, ll-1, when(rightflare3 == lwidth && rightflare3 != 10, lwidth-1, when(rightflare3 == lrs && rightflare3 != 10, lrs-1, when(rightflare3 == lcs && rightflare3 != 10, lcs-1, when(rightflare3 == rw && rightflare3 != 10, rw-1, when(rightflare3 == rrs && rightflare3 != 10, rrs-1, when(rightflare3 == rcs && rightflare3 != 10, rcs-1, when(rightflare3 == leftflare && rightflare3 != 10, leftflare-1, when(rightflare3 == rightflare && rightflare3 != 10, rightflare-1, when(rightflare3 == leftflare3 && rightflare3 != 10, leftflare3-1, when(rightflare3 == leftflare4 && rightflare3 != 10, leftflare4-1, when(rightflare3 == rightflare2 && rightflare3 != 10, rightflare2-1, when(rightflare3 == rightflare3 && rightflare3 != 10, rightflare3-1, when(rightflare3 == rightflare4 && rightflare3 != 10, rightflare4-1, when(rightflare3 == rw2 && rightflare3 != 10, rw2-1, when(rightflare3 == rw3 && rightflare3 != 10, rw3-1, when(rightflare3 == rw4 && rightflare3 != 10, rw4-1, when(rightflare3 == rrs2 && rightflare3 != 10, rrs2-1, when(rightflare3 == rrs3 && rightflare3 != 10, rrs3-1, when(rightflare3 == rrs4 && rightflare3 != 10, rrs4-1, when(rightflare3 == rcs2 && rightflare3 != 10, rcs2-1, when(rightflare3 == rcs3 && rightflare3 != 10, rcs3-1, when(rightflare3 == rcs3 && rightflare3 != 10, rcs3-1, when(rightflare3 == rcs4 && rightflare3 != 10, rcs4-1, when(rightflare4 == wr && rightflare4 != 10, wr-1, when(rightflare4 == gw && rightflare4 != 10, gw-1, when(rightflare4 == lw && rightflare4 != 10, lw-1, when(rightflare4 == ll && rightflare4 != 10, ll-1, when(rightflare4 == lwidth && rightflare4 != 10, lwidth-1, when(rightflare4 == lrs && rightflare4 != 10, lrs-1, when(rightflare4 == lcs && rightflare4 != 10, lcs-1, when(rightflare4 == rw && rightflare4 != 10, rw-1, when(rightflare4 == rrs && rightflare4 != 10, rrs-1, when(rightflare4 == rcs && rightflare4 != 10, rcs-1, when(rightflare4 == leftflare && rightflare4 != 10, leftflare-1, when(rightflare4 == rightflare && rightflare4 != 10, rightflare-1, when(rightflare4 == leftflare3 && rightflare4 != 10, leftflare3-1, when(rightflare4 == leftflare4 && rightflare4 != 10, leftflare4-1, when(rightflare4 == rightflare2 && rightflare4 != 10, rightflare2-1, when(rightflare4 == rightflare3 && rightflare4 != 10, rightflare3-1, when(rightflare4 == rightflare4 && rightflare4 != 10, rightflare4-1, when(rightflare4 == rw2 && rightflare4 != 10, rw2-1, when(rightflare4 == rw3 && rightflare4 != 10, rw3-1, when(rightflare4 == rw4 && rightflare4 != 10, rw4-1, when(rightflare4 == rrs2 && rightflare4 != 10, rrs2-1, when(rightflare4 == rrs3 && rightflare4 != 10, rrs3-1, when(rightflare4 == rrs4 && rightflare4 != 10, rrs4-1, when(rightflare4 == rcs2 && rightflare4 != 10, rcs2-1, when(rightflare4 == rcs3 && rightflare4 != 10, rcs3-1, when(rightflare4 == rcs3 && rightflare4 != 10, rcs3-1, when(rightflare4 == rcs4 && rightflare4 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub6 = when(rw2 == wr && rw2 != 10, wr-1, when(rw2 == gw && rw2 != 10, gw-1, when(rw2 == lw && rw2 != 10, lw-1, when(rw2 == ll && rw2 != 10, ll-1, when(rw2 == lwidth && rw2 != 10, lwidth-1, when(rw2 == lrs && rw2 != 10, lrs-1, when(rw2 == lcs && rw2 != 10, lcs-1, when(rw2 == rw && rw2 != 10, rw-1, when(rw2 == rrs && rw2 != 10, rrs-1, when(rw2 == rcs && rw2 != 10, rcs-1, when(rw2 == leftflare && rw2 != 10, leftflare-1, when(rw2 == rightflare && rw2 != 10, rightflare-1, when(rw2 == leftflare3 && rw2 != 10, leftflare3-1, when(rw2 == leftflare4 && rw2 != 10, leftflare4-1, when(rw2 == rightflare2 && rw2 != 10, rightflare2-1, when(rw2 == rightflare3 && rw2 != 10, rightflare3-1, when(rw2 == rightflare4 && rw2 != 10, rightflare4-1, when(rw2 == rw2 && rw2 != 10, rw2-1, when(rw2 == rw3 && rw2 != 10, rw3-1, when(rw2 == rw4 && rw2 != 10, rw4-1, when(rw2 == rrs2 && rw2 != 10, rrs2-1, when(rw2 == rrs3 && rw2 != 10, rrs3-1, when(rw2 == rrs4 && rw2 != 10, rrs4-1, when(rw2 == rcs2 && rw2 != 10, rcs2-1, when(rw2 == rcs3 && rw2 != 10, rcs3-1, when(rw2 == rcs3 && rw2 != 10, rcs3-1, when(rw2 == rcs4 && rw2 != 10, rcs4-1, when(rw3 == wr && rw3 != 10, wr-1, when(rw3 == gw && rw3 != 10, gw-1, when(rw3 == lw && rw3 != 10, lw-1, when(rw3 == ll && rw3 != 10, ll-1, when(rw3 == lwidth && rw3 != 10, lwidth-1, when(rw3 == lrs && rw3 != 10, lrs-1, when(rw3 == lcs && rw3 != 10, lcs-1, when(rw3 == rw && rw3 != 10, rw-1, when(rw3 == rrs && rw3 != 10, rrs-1, when(rw3 == rcs && rw3 != 10, rcs-1, when(rw3 == leftflare && rw3 != 10, leftflare-1, when(rw3 == rightflare && rw3 != 10, rightflare-1, when(rw3 == leftflare3 && rw3 != 10, leftflare3-1, when(rw3 == leftflare4 && rw3 != 10, leftflare4-1, when(rw3 == rightflare2 && rw3 != 10, rightflare2-1, when(rw3 == rightflare3 && rw3 != 10, rightflare3-1, when(rw3 == rightflare4 && rw3 != 10, rightflare4-1, when(rw3 == rw2 && rw3 != 10, rw2-1, when(rw3 == rw3 && rw3 != 10, rw3-1, when(rw3 == rw4 && rw3 != 10, rw4-1, when(rw3 == rrs2 && rw3 != 10, rrs2-1, when(rw3 == rrs3 && rw3 != 10, rrs3-1, when(rw3 == rrs4 && rw3 != 10, rrs4-1, when(rw3 == rcs2 && rw3 != 10, rcs2-1, when(rw3 == rcs3 && rw3 != 10, rcs3-1, when(rw3 == rcs3 && rw3 != 10, rcs3-1, when(rw3 == rcs4 && rw3 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub7 = when(rw4 == wr && rw4 != 10, wr-1, when(rw4 == gw && rw4 != 10, gw-1, when(rw4 == lw && rw4 != 10, lw-1, when(rw4 == ll && rw4 != 10, ll-1, when(rw4 == lwidth && rw4 != 10, lwidth-1, when(rw4 == lrs && rw4 != 10, lrs-1, when(rw4 == lcs && rw4 != 10, lcs-1, when(rw4 == rw && rw4 != 10, rw-1, when(rw4 == rrs && rw4 != 10, rrs-1, when(rw4 == rcs && rw4 != 10, rcs-1, when(rw4 == leftflare && rw4 != 10, leftflare-1, when(rw4 == rightflare && rw4 != 10, rightflare-1, when(rw4 == leftflare3 && rw4 != 10, leftflare3-1, when(rw4 == leftflare4 && rw4 != 10, leftflare4-1, when(rw4 == rightflare2 && rw4 != 10, rightflare2-1, when(rw4 == rightflare3 && rw4 != 10, rightflare3-1, when(rw4 == rightflare4 && rw4 != 10, rightflare4-1, when(rw4 == rw2 && rw4 != 10, rw2-1, when(rw4 == rw3 && rw4 != 10, rw3-1, when(rw4 == rw4 && rw4 != 10, rw4-1, when(rw4 == rrs2 && rw4 != 10, rrs2-1, when(rw4 == rrs3 && rw4 != 10, rrs3-1, when(rw4 == rrs4 && rw4 != 10, rrs4-1, when(rw4 == rcs2 && rw4 != 10, rcs2-1, when(rw4 == rcs3 && rw4 != 10, rcs3-1, when(rw4 == rcs3 && rw4 != 10, rcs3-1, when(rw4 == rcs4 && rw4 != 10, rcs4-1, when(rrs2 == wr && rrs2 != 10, wr-1, when(rrs2 == gw && rrs2 != 10, gw-1, when(rrs2 == lw && rrs2 != 10, lw-1, when(rrs2 == ll && rrs2 != 10, ll-1, when(rrs2 == lwidth && rrs2 != 10, lwidth-1, when(rrs2 == lrs && rrs2 != 10, lrs-1, when(rrs2 == lcs && rrs2 != 10, lcs-1, when(rrs2 == rw && rrs2 != 10, rw-1, when(rrs2 == rrs && rrs2 != 10, rrs-1, when(rrs2 == rcs && rrs2 != 10, rcs-1, when(rrs2 == leftflare && rrs2 != 10, leftflare-1, when(rrs2 == rightflare && rrs2 != 10, rightflare-1, when(rrs2 == leftflare3 && rrs2 != 10, leftflare3-1, when(rrs2 == leftflare4 && rrs2 != 10, leftflare4-1, when(rrs2 == rightflare2 && rrs2 != 10, rightflare2-1, when(rrs2 == rightflare3 && rrs2 != 10, rightflare3-1, when(rrs2 == rightflare4 && rrs2 != 10, rightflare4-1, when(rrs2 == rw2 && rrs2 != 10, rw2-1, when(rrs2 == rw3 && rrs2 != 10, rw3-1, when(rrs2 == rw4 && rrs2 != 10, rw4-1, when(rrs2 == rrs2 && rrs2 != 10, rrs2-1, when(rrs2 == rrs3 && rrs2 != 10, rrs3-1, when(rrs2 == rrs4 && rrs2 != 10, rrs4-1, when(rrs2 == rcs2 && rrs2 != 10, rcs2-1, when(rrs2 == rcs3 && rrs2 != 10, rcs3-1, when(rrs2 == rcs3 && rrs2 != 10, rcs3-1, when(rrs2 == rcs4 && rrs2 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub8 = when(rrs3 == wr && rrs3 != 10, wr-1, when(rrs3 == gw && rrs3 != 10, gw-1, when(rrs3 == lw && rrs3 != 10, lw-1, when(rrs3 == ll && rrs3 != 10, ll-1, when(rrs3 == lwidth && rrs3 != 10, lwidth-1, when(rrs3 == lrs && rrs3 != 10, lrs-1, when(rrs3 == lcs && rrs3 != 10, lcs-1, when(rrs3 == rw && rrs3 != 10, rw-1, when(rrs3 == rrs && rrs3 != 10, rrs-1, when(rrs3 == rcs && rrs3 != 10, rcs-1, when(rrs3 == leftflare && rrs3 != 10, leftflare-1, when(rrs3 == rightflare && rrs3 != 10, rightflare-1, when(rrs3 == leftflare3 && rrs3 != 10, leftflare3-1, when(rrs3 == leftflare4 && rrs3 != 10, leftflare4-1, when(rrs3 == rightflare2 && rrs3 != 10, rightflare2-1, when(rrs3 == rightflare3 && rrs3 != 10, rightflare3-1, when(rrs3 == rightflare4 && rrs3 != 10, rightflare4-1, when(rrs3 == rw2 && rrs3 != 10, rw2-1, when(rrs3 == rw3 && rrs3 != 10, rw3-1, when(rrs3 == rw4 && rrs3 != 10, rw4-1, when(rrs3 == rrs2 && rrs3 != 10, rrs2-1, when(rrs3 == rrs3 && rrs3 != 10, rrs3-1, when(rrs3 == rrs4 && rrs3 != 10, rrs4-1, when(rrs3 == rcs2 && rrs3 != 10, rcs2-1, when(rrs3 == rcs3 && rrs3 != 10, rcs3-1, when(rrs3 == rcs3 && rrs3 != 10, rcs3-1, when(rrs3 == rcs4 && rrs3 != 10, rcs4-1, when(rrs4 == wr && rrs4 != 10, wr-1, when(rrs4 == gw && rrs4 != 10, gw-1, when(rrs4 == lw && rrs4 != 10, lw-1, when(rrs4 == ll && rrs4 != 10, ll-1, when(rrs4 == lwidth && rrs4 != 10, lwidth-1, when(rrs4 == lrs && rrs4 != 10, lrs-1, when(rrs4 == lcs && rrs4 != 10, lcs-1, when(rrs4 == rw && rrs4 != 10, rw-1, when(rrs4 == rrs && rrs4 != 10, rrs-1, when(rrs4 == rcs && rrs4 != 10, rcs-1, when(rrs4 == leftflare && rrs4 != 10, leftflare-1, when(rrs4 == rightflare && rrs4 != 10, rightflare-1, when(rrs4 == leftflare3 && rrs4 != 10, leftflare3-1, when(rrs4 == leftflare4 && rrs4 != 10, leftflare4-1, when(rrs4 == rightflare2 && rrs4 != 10, rightflare2-1, when(rrs4 == rightflare3 && rrs4 != 10, rightflare3-1, when(rrs4 == rightflare4 && rrs4 != 10, rightflare4-1, when(rrs4 == rw2 && rrs4 != 10, rw2-1, when(rrs4 == rw3 && rrs4 != 10, rw3-1, when(rrs4 == rw4 && rrs4 != 10, rw4-1, when(rrs4 == rrs2 && rrs4 != 10, rrs2-1, when(rrs4 == rrs3 && rrs4 != 10, rrs3-1, when(rrs4 == rrs4 && rrs4 != 10, rrs4-1, when(rrs4 == rcs2 && rrs4 != 10, rcs2-1, when(rrs4 == rcs3 && rrs4 != 10, rcs3-1, when(rrs4 == rcs3 && rrs4 != 10, rcs3-1, when(rrs4 == rcs4 && rrs4 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub9 = when(rcs4 == wr && rcs4 != 10, wr-1, when(rcs4 == gw && rcs4 != 10, gw-1, when(rcs4 == lw && rcs4 != 10, lw-1, when(rcs4 == ll && rcs4 != 10, ll-1, when(rcs4 == lwidth && rcs4 != 10, lwidth-1, when(rcs4 == lrs && rcs4 != 10, lrs-1, when(rcs4 == lcs && rcs4 != 10, lcs-1, when(rcs4 == rw && rcs4 != 10, rw-1, when(rcs4 == rrs && rcs4 != 10, rrs-1, when(rcs4 == rcs && rcs4 != 10, rcs-1, when(rcs4 == leftflare && rcs4 != 10, leftflare-1, when(rcs4 == rightflare && rcs4 != 10, rightflare-1, when(rcs4 == leftflare3 && rcs4 != 10, leftflare3-1, when(rcs4 == leftflare4 && rcs4 != 10, leftflare4-1, when(rcs4 == rightflare2 && rcs4 != 10, rightflare2-1, when(rcs4 == rightflare3 && rcs4 != 10, rightflare3-1, when(rcs4 == rightflare4 && rcs4 != 10, rightflare4-1, when(rcs4 == rw2 && rcs4 != 10, rw2-1, when(rcs4 == rw3 && rcs4 != 10, rw3-1, when(rcs4 == rw4 && rcs4 != 10, rw4-1, when(rcs4 == rrs2 && rcs4 != 10, rrs2-1, when(rcs4 == rrs3 && rcs4 != 10, rrs3-1, when(rcs4 == rrs4 && rcs4 != 10, rrs4-1, when(rcs4 == rcs2 && rcs4 != 10, rcs2-1, when(rcs4 == rcs3 && rcs4 != 10, rcs3-1, when(rcs4 == rcs3 && rcs4 != 10, rcs3-1, when(rcs4 == rcs4 && rcs4 != 10, rcs4-1, when(rcs3 == wr && rcs3 != 10, wr-1, when(rcs3 == gw && rcs3 != 10, gw-1, when(rcs3 == lw && rcs3 != 10, lw-1, when(rcs3 == ll && rcs3 != 10, ll-1, when(rcs3 == lwidth && rcs3 != 10, lwidth-1, when(rcs3 == lrs && rcs3 != 10, lrs-1, when(rcs3 == lcs && rcs3 != 10, lcs-1, when(rcs3 == rw && rcs3 != 10, rw-1, when(rcs3 == rrs && rcs3 != 10, rrs-1, when(rcs3 == rcs && rcs3 != 10, rcs-1, when(rcs3 == leftflare && rcs3 != 10, leftflare-1, when(rcs3 == rightflare && rcs3 != 10, rightflare-1, when(rcs3 == leftflare3 && rcs3 != 10, leftflare3-1, when(rcs3 == leftflare4 && rcs3 != 10, leftflare4-1, when(rcs3 == rightflare2 && rcs3 != 10, rightflare2-1, when(rcs3 == rightflare3 && rcs3 != 10, rightflare3-1, when(rcs3 == rightflare4 && rcs3 != 10, rightflare4-1, when(rcs3 == rw2 && rcs3 != 10, rw2-1, when(rcs3 == rw3 && rcs3 != 10, rw3-1, when(rcs3 == rw4 && rcs3 != 10, rw4-1, when(rcs3 == rrs2 && rcs3 != 10, rrs2-1, when(rcs3 == rrs3 && rcs3 != 10, rrs3-1, when(rcs3 == rrs4 && rcs3 != 10, rrs4-1, when(rcs3 == rcs2 && rcs3 != 10, rcs2-1, when(rcs3 == rcs3 && rcs3 != 10, rcs3-1, when(rcs3 == rcs3 && rcs3 != 10, rcs3-1, when(rcs3 == rcs4 && rcs3 != 10, rcs4-1, 10))))))))))))))))))))))))))))))))))))))))))))))))))))))
var sub10 = when(rcs2 == wr && rcs2 != 10, wr-1, when(rcs2 == gw && rcs2 != 10, gw-1, when(rcs2 == lw && rcs2 != 10, lw-1, when(rcs2 == ll && rcs2 != 10, ll-1, when(rcs2 == lwidth && rcs2 != 10, lwidth-1, when(rcs2 == lrs && rcs2 != 10, lrs-1, when(rcs2 == lcs && rcs2 != 10, lcs-1, when(rcs2 == rw && rcs2 != 10, rw-1, when(rcs2 == rrs && rcs2 != 10, rrs-1, when(rcs2 == rcs && rcs2 != 10, rcs-1, when(rcs2 == leftflare && rcs2 != 10, leftflare-1, when(rcs2 == rightflare && rcs2 != 10, rightflare-1, when(rcs2 == leftflare3 && rcs2 != 10, leftflare3-1, when(rcs2 == leftflare4 && rcs2 != 10, leftflare4-1, when(rcs2 == rightflare2 && rcs2 != 10, rightflare2-1, when(rcs2 == rightflare3 && rcs2 != 10, rightflare3-1, when(rcs2 == rightflare4 && rcs2 != 10, rightflare4-1, when(rcs2 == rw2 && rcs2 != 10, rw2-1, when(rcs2 == rw3 && rcs2 != 10, rw3-1, when(rcs2 == rw4 && rcs2 != 10, rw4-1, when(rcs2 == rrs2 && rcs2 != 10, rrs2-1, when(rcs2 == rrs3 && rcs2 != 10, rrs3-1, when(rcs2 == rrs4 && rcs2 != 10, rrs4-1, when(rcs2 == rcs2 && rcs2 != 10, rcs2-1, when(rcs2 == rcs3 && rcs2 != 10, rcs3-1, when(rcs2 == rcs3 && rcs2 != 10, rcs3-1, when(rcs2 == rcs4 && rcs2 != 10, rcs4-1, 10)))))))))))))))))))))))))))
var sub11 = when(cc == wr && cc != 10, wr-1, when(cc == gw && cc != 10, gw-1, when(cc == lw && cc != 10, lw-1, when(cc == lwidth && cc != 10, lwidth-1, when(cc == lrs && cc != 10, lrs-1, when(cc == lcs && cc != 10, lcs-1, when(cc == rw && cc != 10, rw-1, when(cc == rw2 && cc != 10, rw2-1, when(cc == rw3 && cc != 10, rw3-1, when(cc == rw4 && cc != 10, rw4-1, when(cc == rrs && cc != 10, rrs-1, when(cc == rrs2 && cc != 10, rrs2-1, when(cc == rrs3 && cc != 10, rrs3-1, when(cc == rrs4 && cc != 10, rrs4-1, when(cc == rcs && cc != 10, rcs-1, when(cc == rcs2 && cc != 10, rcs2-1, when(cc == rcs3 && cc != 10, rcs3-1, when(cc == rcs4 && cc != 10, rcs4-1, when(cc == leftflare && cc != 10, leftflare-1, when(cc == leftflare2 && cc != 10, leftflare2-1, when(cc == leftflare3 && cc != 10, leftflare3-1, when(cc == leftflare4 && cc != 10, leftflare4-1, when(cc == rightflare && cc != 10, rightflare-1, when(cc == rightflare2 && cc != 10, rightflare2-1, when(cc == rightflare3 && cc != 10, rightflare3-1, when(cc == rightflare4 && cc != 10, rightflare4-1, when(cc == cutt && cc != 10, cutt-1, 10)))))))))))))))))))))))))))
var total= min(sub11, cc, wr, gw, lw, ll, lwidth, lrs, lcs, rw, rrs, rcs, leftflare, rightflare, sub, sub2, sub3, leftflare2, leftflare3, leftflare4, rightflare2, rightflare3, rightflare4, rw2, rw3, rw4, rrs2, rrs3, rrs4, rcs2, rcs3, rcs4, sub4, sub5, sub6, sub7, sub8, sub9, sub10)
iif(total == 10,'Yes', 'No')
This is the longest expression that I work with. As you can see, this is only determining if there is the same rating then decreasing it by 1. I put my expressions in a Word Doc to save them, and this expression alone takes up around 5 pages. ( I'm no expert but that seems a little bit too long!) The expression you gave me is absolutely wonderful and it would still make this so much easier to deal with! But do you know of anything that could make this process shorter? You mentioned potentially using loops, how would that work?
Thank you again for all of your help, I really really appreciate it!!
Yikes! Let's see if we can shorten some of those.
So, we'll use that same function from before, compDecrease. In order to work through all of the comparisons using a loop, we need a reliable way to do so.
Looking at some of the expressions you've got, it appears that not every field pair gets compared, is that correct? If you just want to compare every field against every other field, there's a way for that, but if you need to compare specific fields against other specific fields, we'll need a dictionary. Or rather, an array of dictionaries, I think.
The arrays will have this structure to them:
[
{field: 'some_field', comps: ['array', 'of', 'fields', 'to', 'compare']},
{field: 'another_field', comps: ['another', 'array', 'of', 'fields']},
etc...
}
With that array, we can iterate over each item using a for loop, and for each key, access the corresponding array, and iterate over each of those to get the values.
Now, the list of "to compare" attributes will still be quite long, so you could break that across multiple lines if you want.
I'm going to create a second function for this, and it can be re-used for each sub that you need to calculate. Your arrays and dictionaries will all need the same structure for this to work.
Here's a re-write of how to get the sub6 variable:
function compDecrease(field, compField){
if (field != 10 && field == compField){
return field-1
}
else {
return 10
}
}
function subComps(compArray){
var outArray = [];
// Go through each item in the comp array
for (var c in compArray){
var comps = compArray[c]['comps']
// For each 'field', run compDecrease against every item in the 'comps' list, add to out_array
for (var comp in comps){
Push(outArray, compDecrease(compArray[c]['field'], comps[comp]))
}
}
return Min(outArray)
}
var sub6_comps = [
{field: rw2, comps: [wr, gw, lw, ll, lwidth, lrs, lcs, rw, rrs, rcs, leftlare, leftflare2, leftflare3, leftflare4, rightflare, rightflare2, rightflare3, rightflare4, rw3, rw4, rrs2, rrs3, rrs4, rcs2, rcs3, rcs4]},
{field: rw3, comps: [wr, gw, lw, ll, lwidth, lrs, lcs, rw, rrs, rcs, leftflare, leftflare2, leftflare3, leftflare4, rightflare, rightflare2, rightflare3, rightflare4, rw3, rw4, rrs2, rrs3, rrs4, rcs2, rcs3, rcs4]}
]
var sub6 = subComps(sub6_comps)
It may seem like a lot, but now you can calculate all of your different subs using the same function by first establishing your array and then running the custom function, so the total length of the expression should come down quite a bit.
I'm afraid to say that I am having a hard time understanding what you have done. Arcade is still a foreign language to me so I do apologize for any silly questions, misunderstandings and a lack of correct vocabulary.
To answer you question, I do need to compare every field to every other field. ("Field" as in the variables I have made such as rw2, gw, lw, etc..) What I'm having a hard time understanding is the "subComps" function, I understand that you made an empty array to start the dictionary in a way, but that is the limit of my knowledge. Your notes are very helpful, but I don't quite understand the logic, would you be able to explain it a bit?
Thanks!
Oh, it's no trouble. This expression has gotten fairly complex, so it's understandable that some of what I'm doing seems a bit opaque.
The text version of what I did was create a function that looks at each field in an array of dictionaries, then compare that field against every field listed in a "comps" array, and uses Push to add that value to the empty array I created.
However! If you need to compare every field with every other field, we don't even need to worry about that. If we have an array of all fields, we can just loop over it. Say there were 10 fields, you'd need to compare any one field against the other 9.
Since the output of compDecrease will be identical for two matching values regardless of order (that is, compDecrease(a, b) == compDecrease(b, a), as long as a == b), we can just compare 1 against 2-10, 2 against 3-10, 3 against 4-10, etc.
So, try this instead, as it may be easier to understand. We will iterate over all the fields in an array of fields to compare. For each field, we'll compare it with all the remaining fields in the array.
var compFields = [
w2,
gw,
lw,
etc...
]
var outArray = [];
// Iterate over fields
for (var f1 = 0; f1 < Count(compFields); f1++){
// Start at next field, go to end
for (var f2 = f1 + 1; f2 < Count(compFields); f2++){
// Compare fields and push to outArray
Push(outArray, compDecrease(compFields[f1], compFields[f2]))
}
}
return Min(outArray);
Ok, I think I'm starting to understand this a bit more. So for this set up, would I need to repeat line 14 in the same format but this time for "f3" and keep going for each field in the array? Then add "compFields[f3]" to line 17 and repeat that for each field as well?
That's the best part of using nested loops like this. You don't need to repeat anything! The inner loop will check all the fields against the first, but then the outer loop moves to the next field and then checks it against the rest of the fields in the inner loop.
Here's a simplified nested loop and its output to help demonstrate the concept:
var strings = ['here', 'are', 'some', 'sample', 'strings']
var outstr = ''
for (var f1 = 0; f1 < Count(strings); f1++){
for (var f2 = f1 + 1; f2 < Count(strings); f2++){
outstr += `Outer loop ${f1}, Inner loop ${f2}: ${strings[f1]} - ${strings[f2]}\n`
}
}
return outstr
Which returns
Outer loop 0, Inner loop 1: here - are
Outer loop 0, Inner loop 2: here - some
Outer loop 0, Inner loop 3: here - sample
Outer loop 0, Inner loop 4: here - strings
Outer loop 1, Inner loop 2: are - some
Outer loop 1, Inner loop 3: are - sample
Outer loop 1, Inner loop 4: are - strings
Outer loop 2, Inner loop 3: some - sample
Outer loop 2, Inner loop 4: some - strings
Outer loop 3, Inner loop 4: sample - strings