22from typing import TypedDict
33import requests
44from dotenv import load_dotenv
5+
56load_dotenv ()
67
8+
79class Result (TypedDict ):
810 is_correct : bool
911 error : int
1012
13+
1114def evaluation_function (response , answer , params ) -> Result :
1215 """
1316 Function used to evaluate a student response.
@@ -35,34 +38,40 @@ def evaluation_function(response, answer, params) -> Result:
3538 global error_output
3639 error_output = 0
3740 try :
38- api_endpoint = params .get ("api_endpoint" , ' resistance/' )
41+ api_endpoint = params .get ("api_endpoint" , " resistance/" )
3942
4043 if len (response ) != 6 :
4144 error_output = 1
4245 is_correct = False
4346 raise Exception ("Connection ID must be 6 characters long" )
4447
45- api_response = requests .get (f"{ os .environ .get ('API_CONNECTION' )} /{ api_endpoint } { response } " )
48+ api_response = requests .post (
49+ f"{ os .environ .get ('API_CONNECTION' )} /{ api_endpoint } { response } "
50+ )
4651 api_data = api_response .json ()
4752
4853 if isinstance (api_data , list ) and len (api_data ) > 0 :
4954 api_data = str (api_data )
5055
5156 if response == "000000" :
5257 is_correct = True
53- elif api_data in [params .get ('correct_answer' , None ), - 1.0 , [{"resistance" : - 1 }]]:
58+ elif api_data in [
59+ params .get ("correct_answer" , None ),
60+ - 1.0 ,
61+ [{"resistance" : - 1 }],
62+ ]:
5463 if response == "resistors/" :
5564 len_data = len (api_data )
56- if len_data != len (params .get (' correct_answer' , None )):
65+ if len_data != len (params .get (" correct_answer" , None )):
5766 is_correct = False
5867 error_output = 2
5968 else :
60- for i in params .get (' correct_answer' , None ):
69+ for i in params .get (" correct_answer" , None ):
6170 if i not in api_data :
6271 is_correct = False
6372 error_output = 3
6473 elif response == "resistance/" :
65- if api_data != params .get (' correct_answer' , None ):
74+ if api_data != params .get (" correct_answer" , None ):
6675 is_correct = False
6776 error_output = 4
6877 is_correct = True
@@ -74,4 +83,5 @@ def evaluation_function(response, answer, params) -> Result:
7483 is_correct = False
7584 error_output = 6
7685
77- return Result (is_correct = is_correct , error = error_output )
86+ return Result (is_correct = is_correct , error = error_output )
87+
0 commit comments