@@ -81,9 +81,14 @@ def handle_eval_command(event):
8181 return {"command" : "eval" , "result" : result }
8282
8383 # Determine what feedback to provide based on cases
84- feedback , warnings = feedback_from_cases (response , params , cases )
85- if feedback :
86- result ["feedback" ] = feedback
84+ matched_case , warnings = feedback_from_cases (response , params , cases )
85+ if matched_case :
86+ result ["feedback" ] = matched_case ["feedback" ]
87+ result ["matched_case" ] = matched_case ["id" ]
88+
89+ # Override is_correct provided by the original block by the case 'mark'
90+ if "mark" in matched_case :
91+ result ["is_correct" ] = bool (int (matched_case ["mark" ]))
8792
8893 # Add warnings out output if any were encountered
8994 if len (warnings ) != 0 :
@@ -95,7 +100,7 @@ def handle_eval_command(event):
95100def feedback_from_cases (response , params , cases ):
96101 """
97102 Attempt to find the correct feedback from a list of cases.
98- Returns a "feedback" string , and optional list of warnings
103+ Returns a matched 'case' (the full object) , and optional list of warnings
99104 """
100105
101106 # A list of "cases" was provided, try matching to each of them
@@ -147,19 +152,23 @@ def feedback_from_cases(response, params, cases):
147152 matches += [i ]
148153
149154 if len (matches ) == 0 :
150- return '' , warnings
155+ return None , warnings
156+
157+ # Select the matched case
158+ matched_case = cases [matches [0 ]]
159+ matched_case ['id' ] = matches [0 ]
151160
152161 if len (matches ) == 1 :
153162 # warnings += [{"case": matches[0]}]
154- return cases [ matches [ 0 ]][ 'feedback' ] , warnings
163+ return matched_case , warnings
155164
156165 else :
157166 s = ', ' .join ([str (m ) for m in matches ])
158167 warnings += [{
159168 "message" :
160169 f"Cases { s } were matched. Only the first one's feedback was returned"
161170 }]
162- return cases [ matches [ 0 ]][ 'feedback' ] , warnings
171+ return matched_case , warnings
163172
164173
165174"""
0 commit comments