Skip to content

Commit 6319cf3

Browse files
chore!: change static obligatory parameters
1 parent 4adbac9 commit 6319cf3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

app/evaluation.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Result(TypedDict):
88
is_correct: bool
9+
error: int
910

1011
def evaluation_function(response, answer, params) -> Result:
1112
"""
@@ -30,11 +31,15 @@ def evaluation_function(response, answer, params) -> Result:
3031
return types and that evaluation_function() is the main function used
3132
to output the evaluation response.
3233
"""
33-
34+
global is_correct
35+
global error_output
36+
error_output = 0
3437
try:
3538
api_endpoint = params.get("api_endpoint", 'resistance/')
3639

3740
if len(response) != 6:
41+
error_output = 1
42+
is_correct = False
3843
raise Exception("Connection ID must be 6 characters long")
3944

4045
api_response = requests.get(f"{os.environ.get('API_CONNECTION')}/{api_endpoint}{response}")
@@ -46,11 +51,27 @@ def evaluation_function(response, answer, params) -> Result:
4651
if response == "000000":
4752
is_correct = True
4853
elif api_data in [params.get('correct_answer', None), -1.0, [{"resistance": -1}]]:
54+
if response == "resistors/":
55+
len_data = len(api_data)
56+
if len_data != len(params.get('correct_answer', None)):
57+
is_correct = False
58+
error_output = 2
59+
else:
60+
for i in params.get('correct_answer', None):
61+
if i not in api_data:
62+
is_correct = False
63+
error_output = 3
64+
elif response == "resistance/":
65+
if api_data != params.get('correct_answer', None):
66+
is_correct = False
67+
error_output = 4
4968
is_correct = True
5069
else:
5170
is_correct = False
71+
error_output = 5
5272
except requests.RequestException as e:
5373
print(f"Error API connection: {e}")
5474
is_correct = False
75+
error_output = 6
5576

56-
return Result(is_correct=is_correct)
77+
return Result(is_correct=is_correct, error=error_output)

0 commit comments

Comments
 (0)