update converters and im-/exporters to accommodate for changes in proforma gem
This commit is contained in:
@ -30,14 +30,35 @@ module ProformaService
|
||||
language: DEFAULT_LANGUAGE,
|
||||
model_solutions:,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
public: @exercise.public,
|
||||
hide_file_tree: @exercise.hide_file_tree,
|
||||
allow_file_creation: @exercise.allow_file_creation,
|
||||
allow_auto_completion: @exercise.allow_auto_completion,
|
||||
expected_difficulty: @exercise.expected_difficulty,
|
||||
execution_environment_id: @exercise.execution_environment_id,
|
||||
files: task_files_meta_data,
|
||||
'@@order' => %w[meta-data],
|
||||
'meta-data' => {
|
||||
'@@order' => %w[CodeOcean:public CodeOcean:hide_file_tree CodeOcean:allow_file_creation CodeOcean:allow_auto_completion CodeOcean:expected_difficulty CodeOcean:execution_environment_id CodeOcean:files],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:public' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.public,
|
||||
},
|
||||
'CodeOcean:hide_file_tree' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.hide_file_tree,
|
||||
},
|
||||
'CodeOcean:allow_file_creation' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.allow_file_creation,
|
||||
},
|
||||
'CodeOcean:allow_auto_completion' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.allow_auto_completion,
|
||||
},
|
||||
'CodeOcean:expected_difficulty' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.expected_difficulty,
|
||||
},
|
||||
'CodeOcean:execution_environment_id' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => @exercise.execution_environment_id,
|
||||
},
|
||||
'CodeOcean:files' => task_files_meta_data,
|
||||
},
|
||||
},
|
||||
}.compact
|
||||
@ -86,9 +107,18 @@ module ProformaService
|
||||
|
||||
def test_meta_data(file)
|
||||
{
|
||||
CodeOcean: {
|
||||
'feedback-message': file.feedback_message,
|
||||
weight: file.weight,
|
||||
'@@order' => %w[test-meta-data],
|
||||
'test-meta-data' => {
|
||||
'@@order' => %w[CodeOcean:feedback-message CodeOcean:weight],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:feedback-message' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => file.feedback_message,
|
||||
},
|
||||
'CodeOcean:weight' => {
|
||||
'@@order' => %w[$1],
|
||||
'$1' => file.weight,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
@ -109,10 +139,20 @@ module ProformaService
|
||||
end
|
||||
|
||||
def task_files_meta_data
|
||||
exercise_files.to_h do |file|
|
||||
# added CO- to id, otherwise the key would have CodeOcean as a prefix after export and import (cause unknown)
|
||||
["CO-#{file.id}", {role: file.role}]
|
||||
# TODO: refactor?
|
||||
task_files_hash = {
|
||||
'@@order' => exercise_files.map {|file| "CodeOcean:CO-#{file.id}" },
|
||||
}
|
||||
exercise_files.each do |file|
|
||||
task_files_hash["CodeOcean:CO-#{file.id}"] = {
|
||||
'@@order' => ['CodeOcean:role'],
|
||||
'CodeOcean:role' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => file.role,
|
||||
},
|
||||
}
|
||||
end
|
||||
task_files_hash
|
||||
end
|
||||
|
||||
def task_files
|
||||
|
@ -21,19 +21,25 @@ module ProformaService
|
||||
user: @user,
|
||||
title: @task.title,
|
||||
description: @task.description,
|
||||
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)) || false,
|
||||
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)) || false,
|
||||
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)) || false,
|
||||
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)) || false,
|
||||
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty) || 1,
|
||||
public: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'public')) || false,
|
||||
hide_file_tree: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'hide_file_tree')) || false,
|
||||
allow_file_creation: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'allow_file_creation')) || false,
|
||||
allow_auto_completion: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'allow_auto_completion')) || false,
|
||||
expected_difficulty: extract_meta_data(@task.meta_data&.dig('meta-data'), 'expected_difficulty') || 1,
|
||||
execution_environment_id:,
|
||||
|
||||
files:
|
||||
)
|
||||
end
|
||||
|
||||
def extract_meta_data(meta_data, *path)
|
||||
current_level = meta_data
|
||||
path.each {|attribute| current_level = current_level&.dig("CodeOcean:#{attribute}") }
|
||||
current_level&.dig('$1')
|
||||
end
|
||||
|
||||
def execution_environment_id
|
||||
from_meta_data = @task.meta_data[:CodeOcean]&.dig(:execution_environment_id)
|
||||
from_meta_data = extract_meta_data(@task.meta_data&.dig('meta-data'), 'execution_environment_id')
|
||||
return from_meta_data if from_meta_data
|
||||
return nil unless @task.proglang
|
||||
|
||||
@ -60,8 +66,8 @@ module ProformaService
|
||||
def test_files
|
||||
@task.tests.map do |test_object|
|
||||
task_files.delete(test_object.files.first.id).tap do |file|
|
||||
file.weight = test_object.meta_data[:CodeOcean]&.dig(:weight) || 1.0
|
||||
file.feedback_message = test_object.meta_data[:CodeOcean]&.dig(:'feedback-message').presence || 'Feedback'
|
||||
file.weight = extract_meta_data(test_object.meta_data&.dig('test-meta-data'), 'weight').presence || 1.0
|
||||
file.feedback_message = extract_meta_data(test_object.meta_data&.dig('test-meta-data'), 'feedback-message').presence || 'Feedback'
|
||||
file.role ||= 'teacher_defined_test'
|
||||
end
|
||||
end
|
||||
@ -89,7 +95,7 @@ module ProformaService
|
||||
hidden: file.visible != 'yes', # hides 'delayed' and 'no'
|
||||
name: File.basename(file.filename, '.*'),
|
||||
read_only: file.usage_by_lms != 'edit',
|
||||
role: @task.meta_data[:CodeOcean]&.dig(:files)&.dig("CO-#{file.id}".to_sym)&.dig(:role),
|
||||
role: extract_meta_data(@task.meta_data&.dig('meta-data'), 'files', "CO-#{file.id}", 'role'),
|
||||
path: File.dirname(file.filename).in?(['.', '']) ? nil : File.dirname(file.filename)
|
||||
)
|
||||
if file.binary
|
||||
|
@ -9,8 +9,7 @@ module ProformaService
|
||||
|
||||
def execute
|
||||
@task = ConvertExerciseToTask.call(exercise: @exercise)
|
||||
namespaces = [{prefix: 'CodeOcean', uri: 'codeocean.openhpi.de'}]
|
||||
exporter = ProformaXML::Exporter.new(task: @task, custom_namespaces: namespaces)
|
||||
exporter = ProformaXML::Exporter.new(task: @task)
|
||||
exporter.perform
|
||||
end
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ module ProformaService
|
||||
if single_task?
|
||||
importer = ProformaXML::Importer.new(zip: @zip)
|
||||
import_result = importer.perform
|
||||
@task = import_result[:task]
|
||||
@task = import_result
|
||||
|
||||
exercise = base_exercise
|
||||
exercise_files = exercise&.files&.to_a
|
||||
|
Reference in New Issue
Block a user