Skip to content

Commit 8a59145

Browse files
committed
Implemented preview and changed packaging strategy
1 parent c5535bb commit 8a59145

File tree

4 files changed

+86
-60
lines changed

4 files changed

+86
-60
lines changed

evaluate.m

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,28 @@
1414

1515
(* For new style packages see: https://mathematica.stackexchange.com/a/176489) *)
1616
(* Declare package context *)
17-
Package["evaluate`"]
17+
BeginPackage["evaluate`"]
1818

19+
EvaluationFunction[type_, answer_, response_, params_] := Module[{result, feedback},
20+
Print["Running Evaluation Function"];
21+
result = evalQ[type, answer, response, params];
22+
Print["Results"];
23+
Print[result];
24+
feedback = If[result["is_correct"],
25+
Lookup[params, "correct_response_feedback", "Correct!"],
26+
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
27+
];
28+
<|
29+
"command" -> "eval",
30+
"result" -> <|
31+
"is_correct" -> result["is_correct"],
32+
"feedback" -> feedback,
33+
"error" -> result["error"]
34+
|>
35+
|>
36+
]
1937

20-
(* Export functions *)
21-
PackageExport["EvaluationFunction"]
38+
Begin["`Private`"]
2239

2340
equalQNumeric[answer_, response_, params_] := Module[{tolerance},
2441
Print["Evaluating Equal Numeric"];
@@ -156,22 +173,5 @@
156173
equalQOther[answer, response, params]
157174
]
158175
];
159-
160-
EvaluationFunction[type_, answer_, response_, params_] := Module[{result, feedback},
161-
Print["Running Evaluation Function"];
162-
result = evalQ[type, answer, response, params];
163-
Print["Results"];
164-
Print[result];
165-
feedback = If[result["is_correct"],
166-
Lookup[params, "correct_response_feedback", "Correct!"],
167-
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
168-
];
169-
<|
170-
"command" -> "eval",
171-
"result" -> <|
172-
"is_correct" -> result["is_correct"],
173-
"feedback" -> feedback,
174-
"error" -> result["error"]
175-
|>
176-
|>
177-
]
176+
End[]
177+
EndPackage[]

evaluation_function.wl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
11
(* ::Package:: *)
22

3-
(* The code that handles incoming messanges and passes them to evaluate or preview accordingly*)
3+
(* The code that handles incoming messages and passes them to evaluate or preview accordingly*)
44

55
<< "evaluate.m";
6+
<< "preview.m";
67

7-
evalQuestionIO = Function[
8-
Module[{jsonData, result},
9-
jsonData = Import[#1, "JSON"] //. List :> Association;
8+
9+
processEvaluate[jsonData_] := Module[{result, requestData, answer, response, params, type},
1010
requestData = jsonData["params"];
1111
answer = requestData["answer"];
1212
response = requestData["response"];
1313
params = requestData["params"];
1414
type = params["comparisonType"];
15+
1516
Print["Evaluating Response Against Answer"];
1617
result = EvaluationFunction[type, answer, response, params];
17-
resultAssoc = result[[4]];
18-
Print["Response"];
18+
Print["Output: ", result];
19+
result
20+
]
21+
22+
processPreview[jsonData_] := Module[{result, requestData, response},
23+
requestData = jsonData["params"];
24+
response = requestData["response"];
25+
26+
Print["Previewing Response"];
27+
28+
result = PreviewFunction[response];
29+
Print["Result: ", result];
30+
result
31+
]
32+
33+
evalQuestionIO = Function[
34+
Module[{jsonData, command, resultAssoc},
35+
jsonData = Import[#1, "JSON"] //. List :> Association;
36+
command = jsonData["method"];
37+
38+
resultAssoc = Which[
39+
command == "eval", processEvaluate[jsonData],
40+
command == "preview", processPreview[jsonData],
41+
True, "Incorrect command"
42+
];
43+
44+
Print["Outputted JSON"];
1945
Print[resultAssoc];
2046
Export[#2, resultAssoc, "JSON", "Compact" -> True]
2147
]

preview.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(* Wolfram Language Package *)
2+
(* Created by the Wolfram Language Plugin for IntelliJ, see http://wlplugin.halirutan.de/ *)
3+
4+
(* :Title: preview *)
5+
(* :Context: preview` *)
6+
(* :Author: marcus *)
7+
(* :Date: 2025-09-26 *)
8+
9+
(* :Package Version: 0.1 *)
10+
(* :Mathematica Version: 14.0 *)
11+
(* :Copyright: (c) 2025 Lambda Feedback *)
12+
(* :Keywords: *)
13+
(* :Discussion: *)
14+
15+
(* For new style packages see: https://mathematica.stackexchange.com/a/176489) *)
16+
(* Declare package context *)
17+
BeginPackage["preview`"]
18+
19+
PreviewFunction[response_] := Module[{result},
20+
Print["Running Preview Function"];
21+
Print["Preview Input:", response];
22+
<|
23+
"command" -> "preview",
24+
"result" -> <|
25+
"preview" -> <|
26+
"message" -> response
27+
|>
28+
|>
29+
|>
30+
]
31+
32+
EndPackage[]

preview_function.wl

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)