diff --git a/mc_backend/mcserver/app/api/exerciseAPI.py b/mc_backend/mcserver/app/api/exerciseAPI.py index 1ac4bcd9148dc3097c26fe48e72b9679d437859b..67c54ca70dbac9977c49ef996f95a9d017d804de 100644 --- a/mc_backend/mcserver/app/api/exerciseAPI.py +++ b/mc_backend/mcserver/app/api/exerciseAPI.py @@ -57,27 +57,24 @@ def get_graph_data(title: str, conll_string_or_urn: str, aqls: List[str], exerci def make_new_exercise(conll: str, correct_feedback: str, exercise_type: str, general_feedback: str, - graph_data_raw: dict, incorrect_feedback: str, instructions: str, partially_correct_feedback: str, - search_values: str, solutions: List[Solution], type_translation: str, urn: str, - work_author: str, work_title: str) -> AnnisResponse: + graph_data_raw: dict, incorrect_feedback: str, instructions: str, language: str, + partially_correct_feedback: str, search_values: str, solutions: List[Solution], + type_translation: str, urn: str, work_author: str, work_title: str) -> AnnisResponse: """ Creates a new exercise and makes it JSON serializable. """ # generate a GUID so we can offer the exercise XML as a file download xml_guid = str(uuid.uuid4()) # assemble the mapped exercise data - ed: ExerciseData = AnnotationService.map_graph_data_to_exercise(graph_data_raw=graph_data_raw, solutions=solutions, - xml_guid=xml_guid) + ed: ExerciseData = AnnotationService.map_graph_data_to_exercise( + graph_data_raw=graph_data_raw, solutions=solutions, xml_guid=xml_guid) # for markWords exercises, add the maximum number of correct solutions to the description instructions += (f"({len(solutions)})" if exercise_type == ExerciseType.markWords.value else "") # map the exercise data to our database data model - new_exercise: Exercise = map_exercise_data_to_database(solutions=solutions, exercise_data=ed, - exercise_type=exercise_type, instructions=instructions, - xml_guid=xml_guid, correct_feedback=correct_feedback, - partially_correct_feedback=partially_correct_feedback, - incorrect_feedback=incorrect_feedback, - general_feedback=general_feedback, - exercise_type_translation=type_translation, conll=conll, - work_author=work_author, work_title=work_title, - search_values=search_values, urn=urn) + new_exercise: Exercise = map_exercise_data_to_database( + solutions=solutions, exercise_data=ed, exercise_type=exercise_type, instructions=instructions, + xml_guid=xml_guid, correct_feedback=correct_feedback, partially_correct_feedback=partially_correct_feedback, + incorrect_feedback=incorrect_feedback, general_feedback=general_feedback, + exercise_type_translation=type_translation, conll=conll, work_author=work_author, work_title=work_title, + search_values=search_values, urn=urn, language=language) # create a response return AnnisResponse( solutions=json.loads(new_exercise.solutions), uri=f"{Config.SERVER_URI_FILE}/{new_exercise.eid}", @@ -87,7 +84,8 @@ def make_new_exercise(conll: str, correct_feedback: str, exercise_type: str, gen def map_exercise_data_to_database(exercise_data: ExerciseData, exercise_type: str, instructions: str, xml_guid: str, correct_feedback: str, partially_correct_feedback: str, incorrect_feedback: str, general_feedback: str, exercise_type_translation: str, search_values: str, - solutions: List[Solution], conll: str, work_author: str, work_title: str, urn: str): + solutions: List[Solution], conll: str, work_author: str, work_title: str, urn: str, + language: str): """Maps the exercise data so we can save it to the database.""" # sort the nodes according to the ordering links AnnotationService.sort_nodes(graph_data=exercise_data.graph) @@ -100,7 +98,7 @@ def map_exercise_data_to_database(exercise_data: ExerciseData, exercise_type: st new_exercise: Exercise = ExerciseMC.from_dict( conll=conll, correct_feedback=correct_feedback, eid=xml_guid, exercise_type=exercise_type, exercise_type_translation=exercise_type_translation, general_feedback=general_feedback, - incorrect_feedback=incorrect_feedback, instructions=instructions, + incorrect_feedback=incorrect_feedback, instructions=instructions, language=language, last_access_time=datetime.utcnow().timestamp(), partially_correct_feedback=partially_correct_feedback, search_values=search_values, solutions=quiz_solutions, text_complexity=tc.all, work_author=work_author, work_title=work_title, urn=urn) @@ -136,7 +134,7 @@ def post(exercise_data: dict) -> Union[Response, ConnexionResponse]: conll=response["conll"], correct_feedback=exercise_data.get("correct_feedback", ""), exercise_type=exercise_data["type"], general_feedback=exercise_data.get("general_feedback", ""), graph_data_raw=response["graph_data_raw"], incorrect_feedback=exercise_data.get("incorrect_feedback", ""), - instructions=exercise_data["instructions"], + instructions=exercise_data["instructions"], language=exercise_data.get("language", "de"), partially_correct_feedback=exercise_data.get("partially_correct_feedback", ""), search_values=exercise_data["search_values"], solutions=solutions, type_translation=exercise_data.get("type_translation", ""), urn=urn, diff --git a/mc_backend/mcserver/app/models.py b/mc_backend/mcserver/app/models.py index 90fe8cf0646225142d6ed5423c906ba601a15761..92597662dcb632e86d2ec6d4f813fc2399b365e2 100644 --- a/mc_backend/mcserver/app/models.py +++ b/mc_backend/mcserver/app/models.py @@ -1,11 +1,8 @@ """Models for dealing with text data, both in the database and in the application itself.""" from typing import Dict, List, Union, Any from enum import Enum - import typing from sqlalchemy.orm.state import InstanceState - -from mcserver.app import db from mcserver.config import Config from mcserver.models_auto import TExercise, Corpus, TCorpus, Exercise, TLearningResult, LearningResult diff --git a/mc_backend/tests.py b/mc_backend/tests.py index 23136fbdcf353358e4dedc409d14df85ea7cea27..6666e37e166f19e4bff442d1577dd07f3a322de7 100644 --- a/mc_backend/tests.py +++ b/mc_backend/tests.py @@ -543,7 +543,8 @@ class McTestCase(unittest.TestCase): conll=exercise_expected.conll, correct_feedback=exercise_expected.correct_feedback, partially_correct_feedback=exercise_expected.partially_correct_feedback, urn=Mocks.urn_custom, incorrect_feedback=exercise_expected.incorrect_feedback, search_values=exercise_expected.search_values, - general_feedback=exercise_expected.general_feedback, work_author="", work_title="") + general_feedback=exercise_expected.general_feedback, work_author=exercise_expected.work_author, + work_title=exercise_expected.work_title, language=exercise_expected.language) expected_values: List[str] = [ exercise_expected.conll, exercise_expected.general_feedback, exercise_expected.incorrect_feedback, exercise_expected.search_values, exercise_expected.partially_correct_feedback, diff --git a/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.ts b/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.ts index 79a30dec01e37b1be42c6d8b23a113faa36b468f..8ec79a8a54a9d0a926f01e50492c4da840616b53 100644 --- a/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.ts +++ b/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.ts @@ -108,15 +108,16 @@ export class ExerciseParametersPage implements OnInit { this.corpusService.currentTextRange.pipe(take(1)).subscribe((tr: TextRange) => { // TODO: change the corpus title to something meaningful, e.g. concatenate user ID and wanted exercise title const workTitle: string = cc.title + ', ' + tr.start.filter(x => x).join('.') + '-' + tr.end.filter(x => x).join('.'); - formData.append('work_title', workTitle); - formData.append('type', MoodleExerciseType[this.corpusService.exercise.type]); - formData.append('type_translation', this.corpusService.exercise.typeTranslation); - formData.append('instructions', instructions); formData.append('correct_feedback', this.corpusService.exercise.feedback.correct); - formData.append('partially_correct_feedback', this.corpusService.exercise.feedback.partiallyCorrect); - formData.append('incorrect_feedback', this.corpusService.exercise.feedback.incorrect); + formData.append('instructions', instructions); formData.append('general_feedback', this.corpusService.exercise.feedback.general); + formData.append('incorrect_feedback', this.corpusService.exercise.feedback.incorrect); + formData.append('language', this.translateService.currentLang); + formData.append('partially_correct_feedback', this.corpusService.exercise.feedback.partiallyCorrect); + formData.append('type', MoodleExerciseType[this.corpusService.exercise.type]); + formData.append('type_translation', this.corpusService.exercise.typeTranslation); formData.append('work_author', cc.author); + formData.append('work_title', workTitle); this.getH5Pexercise(formData).then(() => { return resolve(); });