generated from lambda-feedback/evaluation-function-boilerplate-wolfram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation_function.wl
62 lines (53 loc) · 2.01 KB
/
evaluation_function.wl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output as
Associations *)
equalQAssociation =
Function[
Module[{tolerance, correctQ, error},
If[NumericQ[#answer],
tolerance =
If[#params["tolerance_is_absolute"],
#params["tolerance"]
,
#params["tolerance"] * #params["answer"]
];
error = Abs[#answer - #response];
correctQ = TrueQ[error <= tolerance]
,
error = "not applicable";
correctQ = TrueQ[#answer == #response]
];
<|
"command" -> "eval"
,
"result" ->
{
"is_correct" -> correctQ
,
"feedback" ->
If[correctQ,
#params["correct_response_feedback"]
,
#params["incorrect_response_feedback"
]
]
,
"error" -> error
}
|>
]
];
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output as
JSON strings
Calls equalQAssociation *)
equalQJSON = Function[ExportString[equalQAssociation[ImportString[#,
"JSON"] //. List :> Association], "JSON", "Compact" -> True]];
(* A function to test whether a response is equal to an answer, \
including to within a given tolerance; input and output read in from \
external JSON files
Calls equalQAssociation *)
equalQIO = Function[Export[#2, equalQAssociation[Import[#1, "JSON"] //.
List :> Association], "JSON", "Compact" -> True]];
argv = Rest[$ScriptCommandLine]
equalQIO[argv[[1]], argv[[2]]]