Hello Community,
I'm completely at a lost here. I have tried all possible combinations and was trying to figure out how to get this to work but it just doesn't work for me.
The thing I am trying to accomplish is the following:
I have 5 fields with a or b answers (1 or 0) and 5 fields with the correct solution. (also 1 or 0).
Q1-5 and A1-5.
I also have 5 fields with a Weight
W1-5.
I am trying to find a floating value of 0-1 based on the answer. This goes in the field Betrouwbaarheid
This is what I have so far, which is to you very clearly incorrect. But I have tried a lot of different types of formatting without avail.
Note: It's updated!
Expression<SPAN class="punctuation token">:</SPAN>
calc<SPAN class="punctuation token">(</SPAN>!Q1!<SPAN class="punctuation token">,</SPAN> !Q2!<SPAN class="punctuation token">,</SPAN> !Q3!<SPAN class="punctuation token">,</SPAN> !Q4!<SPAN class="punctuation token">,</SPAN> !Q5!<SPAN class="punctuation token">,</SPAN> !A1!<SPAN class="punctuation token">,</SPAN> !A2!<SPAN class="punctuation token">,</SPAN> !A3!<SPAN class="punctuation token">,</SPAN> !A4!<SPAN class="punctuation token">,</SPAN> !A5!<SPAN class="punctuation token">,</SPAN> !W1!<SPAN class="punctuation token">,</SPAN> !W2!<SPAN class="punctuation token">,</SPAN> !W3!<SPAN class="punctuation token">,</SPAN> !W4!<SPAN class="punctuation token">,</SPAN> !W5<SPAN class="punctuation token">)</SPAN>
Code block<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">calc</SPAN><SPAN class="punctuation token">(</SPAN>Q1<SPAN class="punctuation token">,</SPAN> Q2<SPAN class="punctuation token">,</SPAN> Q3<SPAN class="punctuation token">,</SPAN> Q4<SPAN class="punctuation token">,</SPAN> Q5<SPAN class="punctuation token">,</SPAN> A1<SPAN class="punctuation token">,</SPAN> A2<SPAN class="punctuation token">,</SPAN> A3<SPAN class="punctuation token">,</SPAN> A4<SPAN class="punctuation token">,</SPAN> A5<SPAN class="punctuation token">,</SPAN> W1<SPAN class="punctuation token">,</SPAN> W2<SPAN class="punctuation token">,</SPAN> W3<SPAN class="punctuation token">,</SPAN> W4<SPAN class="punctuation token">,</SPAN> W5<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> Q1 <SPAN class="operator token">==</SPAN> A1<SPAN class="punctuation token">:</SPAN>
c1 <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
c1 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">if</SPAN> Q2 <SPAN class="operator token">==</SPAN> A2<SPAN class="punctuation token">:</SPAN>
c2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
c2 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">if</SPAN> Q3 <SPAN class="operator token">==</SPAN> A3<SPAN class="punctuation token">:</SPAN>
c3 <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
c3 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">if</SPAN> Q4 <SPAN class="operator token">==</SPAN> A4<SPAN class="punctuation token">:</SPAN>
c4 <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
c4 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">if</SPAN> Q5 <SPAN class="operator token">==</SPAN> A5<SPAN class="punctuation token">:</SPAN>
c5 <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
c5 <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
betr <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>c1 <SPAN class="operator token">*</SPAN> W1 <SPAN class="operator token">+</SPAN> c2 <SPAN class="operator token">*</SPAN> W2 <SPAN class="operator token">+</SPAN> c3 <SPAN class="operator token">*</SPAN> W3 <SPAN class="operator token">+</SPAN> c4 <SPAN class="operator token">*</SPAN> W4 <SPAN class="operator token">+</SPAN> c5 <SPAN class="operator token">*</SPAN> W5<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN> <SPAN class="punctuation token">(</SPAN>W1 <SPAN class="operator token">+</SPAN> W2 <SPAN class="operator token">+</SPAN> W3 <SPAN class="operator token">+</SPAN> W4 <SPAN class="operator token">+</SPAN> W5<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> betr<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Thanks to the people below a part was resolved. My new code gives no syntax errors.
However, i still get an error when trying to do a field calculation.
ERROR 000539: File "<expression>", line 1
calc(, , , , , , , , , , , , , , )
^
SyntaxError: invalid syntax
Failed to execute (CalculateField).<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I hope anyone can shed me some light into how this codeblock programming works. It's a complete and utter mystery to me.