Skip to content

Commit d0a08df

Browse files
committed
Merge branch 'feat/add-AI-generated-comments-grading' of github.com:source-academy/backend into feat/add-AI-generated-comments-grading
2 parents 6a141a4 + 7fae27c commit d0a08df

File tree

6 files changed

+46
-26
lines changed

6 files changed

+46
-26
lines changed

lib/cadet/assessments/library.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ defmodule Cadet.Assessments.Library do
1212
field(:variant, :string, default: nil)
1313
field(:exec_time_ms, :integer, default: 1000)
1414
field(:globals, :map, default: %{})
15+
field(:language_options, :map, default: %{})
1516
embeds_one(:external, ExternalLibrary, on_replace: :update)
1617
end
1718

1819
@required_fields ~w(chapter)a
19-
@optional_fields ~w(globals variant exec_time_ms)a
20+
@optional_fields ~w(globals variant language_options exec_time_ms)a
2021
@required_embeds ~w(external)a
2122

2223
def changeset(library, params \\ %{}) do

lib/cadet/jobs/xml_parser.ex

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ defmodule Cadet.Updater.XMLParser do
135135

136136
@spec process_questions(String.t()) :: {:ok, [map()]} | {:error, String.t()}
137137
defp process_questions(xml) do
138-
default_library = xpath(xml, ~x"//TASK/DEPLOYMENT"e)
139-
default_grading_library = xpath(xml, ~x"//TASK/GRADERDEPLOYMENT"e)
138+
default_library = xpath(xml, ~x"//TASK/PROGRAMMINGLANGUAGE"e)
139+
default_grading_library = xpath(xml, ~x"//TASK/GRADERPROGRAMMINGLANGUAGE"e)
140140

141141
questions_params =
142142
xml
@@ -281,22 +281,23 @@ defmodule Cadet.Updater.XMLParser do
281281

282282
@spec process_question_library(map(), any(), any()) :: map() | {:error, String.t()}
283283
defp process_question_library(question, default_library, default_grading_library) do
284-
library = xpath(question[:entity], ~x"./DEPLOYMENT"o) || default_library
284+
library = xpath(question[:entity], ~x"./PROGRAMMINGLANGUAGE"o) || default_library
285285

286286
grading_library =
287-
xpath(question[:entity], ~x"./GRADERDEPLOYMENT"o) || default_grading_library || library
287+
xpath(question[:entity], ~x"./GRADERPROGRAMMINGLANGUAGE"o) || default_grading_library ||
288+
library
288289

289290
if library do
290291
question
291-
|> Map.put(:library, process_question_library(library))
292-
|> Map.put(:grading_library, process_question_library(grading_library))
292+
|> Map.put(:library, parse_programming_language(library))
293+
|> Map.put(:grading_library, parse_programming_language(grading_library))
293294
else
294-
{:error, "Missing DEPLOYMENT"}
295+
{:error, "Missing PROGRAMMINGLANGUAGE"}
295296
end
296297
end
297298

298-
@spec process_question_library(any()) :: map()
299-
defp process_question_library(library_entity) do
299+
@spec parse_programming_language(any()) :: map()
300+
defp parse_programming_language(library_entity) do
300301
globals =
301302
library_entity
302303
|> xpath(
@@ -316,6 +317,13 @@ defmodule Cadet.Updater.XMLParser do
316317
symbols: ~x"./SYMBOL/text()"sl
317318
)
318319

320+
options_list =
321+
library_entity
322+
|> xpath(~x"./OPTION"el, key: ~x"./@key"s, value: ~x"./@value"s)
323+
324+
options_map =
325+
options_list |> Map.new(&{&1.key, &1.value})
326+
319327
library_entity
320328
|> xpath(
321329
~x"."e,
@@ -325,6 +333,7 @@ defmodule Cadet.Updater.XMLParser do
325333
)
326334
|> Map.put(:globals, globals)
327335
|> Map.put(:external, external)
336+
|> Map.put(:language_options, options_map)
328337
end
329338

330339
@spec process_charlist(charlist() | nil) :: String.t() | nil

lib/cadet_web/helpers/assessments_helpers.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ defmodule CadetWeb.AssessmentsHelpers do
1010
variant: :variant,
1111
execTimeMs: :exec_time_ms,
1212
globals: :globals,
13-
external: &build_external_library(%{external_library: &1.external})
13+
external: &build_external_library(%{external_library: &1.external}),
14+
languageOptions: :language_options
1415
})
1516
end
1617

test/cadet/updater/xml_parser_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,21 @@ defmodule Cadet.Updater.XMLParserTest do
221221
end
222222
end
223223

224-
test "missing DEPLOYMENT", %{
224+
test "missing PROGRAMMINGLANGUAGE", %{
225225
questions: questions,
226226
course: course,
227227
assessments_with_config: assessments_with_config
228228
} do
229229
for {assessment, assessment_config} <- assessments_with_config do
230-
xml = XMLGenerator.generate_xml_for(assessment, questions, no_deployment: true)
230+
xml = XMLGenerator.generate_xml_for(assessment, questions, no_programminglanguage: true)
231231

232232
assert capture_log(fn ->
233233
assert(
234234
XMLParser.parse_xml(xml, course.id, assessment_config.id) ==
235-
{:error, {:bad_request, "Missing DEPLOYMENT"}}
235+
{:error, {:bad_request, "Missing PROGRAMMINGLANGUAGE"}}
236236
)
237237
end) =~
238-
"Missing DEPLOYMENT"
238+
"Missing PROGRAMMINGLANGUAGE"
239239
end
240240
end
241241

test/cadet_web/admin_controllers/admin_grading_controller_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
309309
"symbols" => &1.question.library.external.symbols
310310
},
311311
"execTimeMs" => &1.question.library.exec_time_ms,
312+
"languageOptions" => %{},
312313
"variant" => &1.question.library.variant
313314
},
314315
"maxXp" => &1.question.max_xp,
@@ -353,6 +354,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
353354
"symbols" => &1.question.library.external.symbols
354355
},
355356
"execTimeMs" => &1.question.library.exec_time_ms,
357+
"languageOptions" => %{},
356358
"variant" => &1.question.library.variant
357359
},
358360
"maxXp" => &1.question.max_xp,
@@ -407,6 +409,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
407409
"symbols" => &1.question.library.external.symbols
408410
},
409411
"execTimeMs" => &1.question.library.exec_time_ms,
412+
"languageOptions" => %{},
410413
"variant" => &1.question.library.variant
411414
},
412415
"maxXp" => &1.question.max_xp,
@@ -1340,6 +1343,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
13401343
"symbols" => &1.question.library.external.symbols
13411344
},
13421345
"execTimeMs" => &1.question.library.exec_time_ms,
1346+
"languageOptions" => %{},
13431347
"variant" => &1.question.library.variant
13441348
},
13451349
"maxXp" => &1.question.max_xp,
@@ -1384,6 +1388,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
13841388
"symbols" => &1.question.library.external.symbols
13851389
},
13861390
"execTimeMs" => &1.question.library.exec_time_ms,
1391+
"languageOptions" => %{},
13871392
"variant" => &1.question.library.variant
13881393
},
13891394
"content" => &1.question.question.content,
@@ -1438,6 +1443,7 @@ defmodule CadetWeb.AdminGradingControllerTest do
14381443
"symbols" => &1.question.library.external.symbols
14391444
},
14401445
"execTimeMs" => &1.question.library.exec_time_ms,
1446+
"languageOptions" => %{},
14411447
"variant" => &1.question.library.variant
14421448
},
14431449
"maxXp" => &1.question.max_xp,

test/support/xml_generator.ex

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ defmodule Cadet.Test.XMLGenerator do
1919
) do
2020
assessment_wide_library =
2121
if opts[:library] do
22-
process_library(opts[:library], using: &deployment/2, no_deployment: opts[:no_deployment])
22+
process_library(opts[:library],
23+
using: &programminglanguage/2,
24+
no_deployment: opts[:no_programminglanguage]
25+
)
2326
else
2427
[]
2528
end
@@ -28,8 +31,8 @@ defmodule Cadet.Test.XMLGenerator do
2831
if opts[:grading_library] do
2932
process_library(
3033
opts[:grading_library],
31-
using: &graderdeployment/2,
32-
no_deployment: opts[:no_deployment]
34+
using: &graderprogramminglanguage/2,
35+
no_deployment: opts[:no_programminglanguage]
3336
)
3437
else
3538
[]
@@ -63,13 +66,13 @@ defmodule Cadet.Test.XMLGenerator do
6366
process_question_by_question_type(question) ++
6467
process_library(
6568
question.library,
66-
using: &deployment/2,
67-
no_deployment: opts[:no_deployment]
69+
using: &programminglanguage/2,
70+
no_deployment: opts[:no_programminglanguage]
6871
) ++
6972
process_library(
7073
question.grading_library,
71-
using: &graderdeployment/2,
72-
no_deployment: opts[:no_deployment]
74+
using: &graderprogramminglanguage/2,
75+
no_deployment: opts[:no_programminglanguage]
7376
)
7477
)
7578
end
@@ -171,12 +174,12 @@ defmodule Cadet.Test.XMLGenerator do
171174
{"VOTING", map_permit_keys(raw_attr, ~w(assessment_number reveal_hours token_divider)a)}
172175
end
173176

174-
defp deployment(raw_attrs, children) do
175-
{"DEPLOYMENT", map_permit_keys(raw_attrs, ~w(interpreter)a), children}
177+
defp programminglanguage(raw_attrs, children) do
178+
{"PROGRAMMINGLANGUAGE", map_permit_keys(raw_attrs, ~w(interpreter)a), children}
176179
end
177180

178-
defp graderdeployment(raw_attrs, children) do
179-
{"GRADERDEPLOYMENT", map_permit_keys(raw_attrs, ~w(interpreter)a), children}
181+
defp graderprogramminglanguage(raw_attrs, children) do
182+
{"GRADERPROGRAMMINGLANGUAGE", map_permit_keys(raw_attrs, ~w(interpreter)a), children}
180183
end
181184

182185
defp external(raw_attrs, children) do

0 commit comments

Comments
 (0)