use of de.tum.in.www1.artemis.domain.quiz.QuizExercise in project Artemis by ls1intum.
the class DatabaseUtilService method createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults.
public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults(boolean hasAssessmentDueDatePassed) {
Course course = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course);
ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course);
QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course);
// Set assessment due dates
if (hasAssessmentDueDatePassed) {
modelingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
textExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
programmingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
quizExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
} else {
modelingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
textExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
programmingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
quizExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
}
// Add exercises to course
course.addExercises(modelingExercise);
course.addExercises(textExercise);
course.addExercises(fileUploadExercise);
course.addExercises(programmingExercise);
course.addExercises(quizExercise);
// Save course and exercises to database
Course courseSaved = courseRepo.save(course);
modelingExercise = exerciseRepo.save(modelingExercise);
textExercise = exerciseRepo.save(textExercise);
fileUploadExercise = exerciseRepo.save(fileUploadExercise);
programmingExercise = exerciseRepo.save(programmingExercise);
quizExercise = exerciseRepo.save(quizExercise);
// Get user and setup participations
User user = (userRepo.findOneByLogin("student1")).get();
StudentParticipation participationModeling = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, modelingExercise, user);
StudentParticipation participationText = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
StudentParticipation participationFileUpload = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, fileUploadExercise, user);
StudentParticipation participationQuiz = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, quizExercise, user);
StudentParticipation participationProgramming = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, programmingExercise, user);
// Save participations
participationModeling = studentParticipationRepo.save(participationModeling);
participationText = studentParticipationRepo.save(participationText);
participationFileUpload = studentParticipationRepo.save(participationFileUpload);
participationQuiz = studentParticipationRepo.save(participationQuiz);
participationProgramming = studentParticipationRepo.save(participationProgramming);
// Setup results
Result resultModeling = ModelFactory.generateResult(true, 10D);
resultModeling.setAssessmentType(AssessmentType.MANUAL);
resultModeling.setCompletionDate(ZonedDateTime.now());
Result resultText = ModelFactory.generateResult(true, 12D);
resultText.setAssessmentType(AssessmentType.MANUAL);
resultText.setCompletionDate(ZonedDateTime.now());
Result resultFileUpload = ModelFactory.generateResult(true, 0D);
resultFileUpload.setAssessmentType(AssessmentType.MANUAL);
resultFileUpload.setCompletionDate(ZonedDateTime.now());
Result resultQuiz = ModelFactory.generateResult(true, 0D);
resultQuiz.setAssessmentType(AssessmentType.AUTOMATIC);
resultQuiz.setCompletionDate(ZonedDateTime.now());
Result resultProgramming = ModelFactory.generateResult(true, 20D);
resultProgramming.setAssessmentType(AssessmentType.AUTOMATIC);
resultProgramming.setCompletionDate(ZonedDateTime.now());
// Connect participations to results and vice versa
resultModeling.setParticipation(participationModeling);
resultText.setParticipation(participationText);
resultFileUpload.setParticipation(participationFileUpload);
resultQuiz.setParticipation(participationQuiz);
resultProgramming.setParticipation(participationProgramming);
participationModeling.addResult(resultModeling);
participationText.addResult(resultText);
participationFileUpload.addResult(resultFileUpload);
participationQuiz.addResult(resultQuiz);
participationProgramming.addResult(resultProgramming);
// Save results and participations
resultModeling = resultRepo.save(resultModeling);
resultText = resultRepo.save(resultText);
resultFileUpload = resultRepo.save(resultFileUpload);
resultQuiz = resultRepo.save(resultQuiz);
resultProgramming = resultRepo.save(resultProgramming);
participationModeling = studentParticipationRepo.save(participationModeling);
participationText = studentParticipationRepo.save(participationText);
participationFileUpload = studentParticipationRepo.save(participationFileUpload);
participationQuiz = studentParticipationRepo.save(participationQuiz);
participationProgramming = studentParticipationRepo.save(participationProgramming);
// Connect exercises with participations
modelingExercise.addParticipation(participationModeling);
textExercise.addParticipation(participationText);
fileUploadExercise.addParticipation(participationFileUpload);
quizExercise.addParticipation(participationQuiz);
programmingExercise.addParticipation(participationProgramming);
// Setup submissions and connect with participations
ModelingSubmission modelingSubmission = ModelFactory.generateModelingSubmission("model1", true);
TextSubmission textSubmission = ModelFactory.generateTextSubmission("text of text submission", Language.ENGLISH, true);
FileUploadSubmission fileUploadSubmission = ModelFactory.generateFileUploadSubmission(true);
QuizSubmission quizSubmission = ModelFactory.generateQuizSubmission(true);
ProgrammingSubmission programmingSubmission = ModelFactory.generateProgrammingSubmission(true);
// Save submissions
modelingSubmission = submissionRepository.save(modelingSubmission);
textSubmission = submissionRepository.save(textSubmission);
fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
quizSubmission = submissionRepository.save(quizSubmission);
programmingSubmission = submissionRepository.save(programmingSubmission);
modelingSubmission.setParticipation(participationModeling);
modelingSubmission.addResult(resultModeling);
textSubmission.setParticipation(participationText);
textSubmission.addResult(resultText);
fileUploadSubmission.setParticipation(participationFileUpload);
fileUploadSubmission.addResult(resultFileUpload);
quizSubmission.setParticipation(participationQuiz);
quizSubmission.addResult(resultQuiz);
programmingSubmission.setParticipation(participationProgramming);
programmingSubmission.addResult(resultProgramming);
// Save submissions
modelingSubmission = submissionRepository.save(modelingSubmission);
textSubmission = submissionRepository.save(textSubmission);
fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
quizSubmission = submissionRepository.save(quizSubmission);
programmingSubmission = submissionRepository.save(programmingSubmission);
// Save exercises
exerciseRepo.save(modelingExercise);
exerciseRepo.save(textExercise);
exerciseRepo.save(fileUploadExercise);
exerciseRepo.save(programmingExercise);
exerciseRepo.save(quizExercise);
// Connect participations with submissions
participationModeling.setSubmissions(Set.of(modelingSubmission));
participationText.setSubmissions(Set.of(textSubmission));
participationFileUpload.setSubmissions(Set.of(fileUploadSubmission));
participationQuiz.setSubmissions(Set.of(quizSubmission));
participationProgramming.setSubmissions(Set.of(programmingSubmission));
// Save participations
studentParticipationRepo.save(participationModeling);
studentParticipationRepo.save(participationText);
studentParticipationRepo.save(participationFileUpload);
studentParticipationRepo.save(participationQuiz);
studentParticipationRepo.save(participationProgramming);
return courseSaved;
}
use of de.tum.in.www1.artemis.domain.quiz.QuizExercise in project ArTEMiS by ls1intum.
the class QuizSubmissionWebsocketService method saveSubmission.
// TODO it would be nice to have some kind of startQuiz call that creates the participation with an initialization date. This should happen when the quiz is first shown
// to the user. Then we also could find out how long students work on the quiz on average
/**
* Saves a quiz submission into the hash maps. Submitted quizzes are marked to be saved into the database in the QuizScheduleService
*
* @param exerciseId the exerciseID to the corresponding QuizExercise
* @param quizSubmission the submission which should be saved
* @param principal refers to the user who initiated the request
*/
@MessageMapping("/topic/quizExercise/{exerciseId}/submission")
public void saveSubmission(@DestinationVariable Long exerciseId, @Payload QuizSubmission quizSubmission, Principal principal) {
// Without this, custom jpa repository methods don't work in websocket channel.
SecurityUtils.setAuthorizationObject();
String username = principal.getName();
try {
QuizSubmission updatedQuizSubmission = quizSubmissionService.saveSubmissionForLiveMode(exerciseId, quizSubmission, username, false);
// send updated submission over websocket (use a thread to prevent that the outbound channel blocks the inbound channel (e.g. due a slow client))
// to improve the performance, this is currently deactivated: slow clients might lead to bottlenecks so that more important messages can not be distributed any more
// new Thread(() -> sendSubmissionToUser(username, exerciseId, quizSubmission)).start();
// log.info("WS.Inbound: Sent quiz submission (async) back to user {} in quiz {} after {} µs ", principal.getName(), exerciseId, (System.nanoTime() - start) / 1000);
} catch (QuizSubmissionException ex) {
// send error message over websocket (use a thread to prevent that the outbound channel blocks the inbound channel (e.g. due a slow client))
new Thread(() -> messagingTemplate.convertAndSendToUser(username, "/topic/quizExercise/" + exerciseId + "/submission", new WebsocketError(ex.getMessage()))).start();
}
}
use of de.tum.in.www1.artemis.domain.quiz.QuizExercise in project ArTEMiS by ls1intum.
the class DatabaseUtilService method createCoursesWithExercisesAndLectures.
public List<Course> createCoursesWithExercisesAndLectures(boolean withParticipations) throws Exception {
ZonedDateTime pastTimestamp = ZonedDateTime.now().minusDays(5);
ZonedDateTime futureTimestamp = ZonedDateTime.now().plusDays(5);
ZonedDateTime futureFutureTimestamp = ZonedDateTime.now().plusDays(8);
Course course1 = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
Course course2 = ModelFactory.generateCourse(null, ZonedDateTime.now().minusDays(8), pastTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course1);
modelingExercise.setGradingInstructions("some grading instructions");
modelingExercise.setExampleSolutionModel("Example solution model");
modelingExercise.setExampleSolutionExplanation("Example Solution");
addGradingInstructionsToExercise(modelingExercise);
modelingExercise.getCategories().add("Modeling");
modelingExercise.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
course1.addExercises(modelingExercise);
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course1);
textExercise.setGradingInstructions("some grading instructions");
textExercise.setExampleSolution("Example Solution");
addGradingInstructionsToExercise(textExercise);
textExercise.getCategories().add("Text");
textExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
course1.addExercises(textExercise);
FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course1);
fileUploadExercise.setGradingInstructions("some grading instructions");
fileUploadExercise.setExampleSolution("Example Solution");
addGradingInstructionsToExercise(fileUploadExercise);
fileUploadExercise.getCategories().add("File");
course1.addExercises(fileUploadExercise);
ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course1);
programmingExercise.setGradingInstructions("some grading instructions");
addGradingInstructionsToExercise(programmingExercise);
programmingExercise.getCategories().add("Programming");
course1.addExercises(programmingExercise);
QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course1);
programmingExercise.getCategories().add("Quiz");
course1.addExercises(quizExercise);
Lecture lecture1 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
Attachment attachment1 = ModelFactory.generateAttachment(pastTimestamp, lecture1);
lecture1.addAttachments(attachment1);
course1.addLectures(lecture1);
Lecture lecture2 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
Attachment attachment2 = ModelFactory.generateAttachment(pastTimestamp, lecture2);
lecture2.addAttachments(attachment2);
course1.addLectures(lecture2);
course1 = courseRepo.save(course1);
course2 = courseRepo.save(course2);
lectureRepo.save(lecture1);
lectureRepo.save(lecture2);
attachmentRepo.save(attachment1);
attachmentRepo.save(attachment2);
modelingExercise = exerciseRepo.save(modelingExercise);
textExercise = exerciseRepo.save(textExercise);
exerciseRepo.save(fileUploadExercise);
exerciseRepo.save(programmingExercise);
exerciseRepo.save(quizExercise);
if (withParticipations) {
// create 5 tutor participations and 5 example submissions and connect all of them (to test the many-to-many relationship)
var tutorParticipations = new ArrayList<TutorParticipation>();
for (int i = 1; i < 6; i++) {
var tutorParticipation = new TutorParticipation().tutor(getUserByLogin("tutor" + i));
tutorParticipationRepo.save(tutorParticipation);
tutorParticipations.add(tutorParticipation);
}
for (int i = 0; i < 5; i++) {
String validModel = FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json");
var exampleSubmission = addExampleSubmission(generateExampleSubmission(validModel, modelingExercise, true));
exampleSubmission.assessmentExplanation("exp");
for (var tutorParticipation : tutorParticipations) {
exampleSubmission.addTutorParticipations(tutorParticipation);
}
exampleSubmissionRepo.save(exampleSubmission);
}
User user = (userRepo.findOneByLogin("student1")).get();
StudentParticipation participation1 = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, modelingExercise, user);
StudentParticipation participation2 = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
StudentParticipation participation3 = ModelFactory.generateStudentParticipation(InitializationState.UNINITIALIZED, modelingExercise, user);
Submission modelingSubmission1 = ModelFactory.generateModelingSubmission("model1", true);
Submission modelingSubmission2 = ModelFactory.generateModelingSubmission("model2", true);
Submission textSubmission = ModelFactory.generateTextSubmission("text", Language.ENGLISH, true);
Result result1 = ModelFactory.generateResult(true, 10D);
Result result2 = ModelFactory.generateResult(true, 12D);
Result result3 = ModelFactory.generateResult(false, 0D);
participation1 = studentParticipationRepo.save(participation1);
participation2 = studentParticipationRepo.save(participation2);
participation3 = studentParticipationRepo.save(participation3);
submissionRepository.save(modelingSubmission1);
submissionRepository.save(modelingSubmission2);
submissionRepository.save(textSubmission);
modelingSubmission1.setParticipation(participation1);
textSubmission.setParticipation(participation2);
modelingSubmission2.setParticipation(participation3);
result1.setParticipation(participation1);
result2.setParticipation(participation3);
result3.setParticipation(participation2);
result1 = resultRepo.save(result1);
result2 = resultRepo.save(result2);
result3 = resultRepo.save(result3);
result1.setSubmission(modelingSubmission1);
result2.setSubmission(modelingSubmission2);
result3.setSubmission(textSubmission);
modelingSubmission1.addResult(result1);
modelingSubmission2.addResult(result2);
textSubmission.addResult(result3);
submissionRepository.save(modelingSubmission1);
submissionRepository.save(modelingSubmission2);
submissionRepository.save(textSubmission);
}
return Arrays.asList(course1, course2);
}
use of de.tum.in.www1.artemis.domain.quiz.QuizExercise in project ArTEMiS by ls1intum.
the class QuizExerciseResourceIntTest method equalsVerifier.
@Test
@Transactional
public void equalsVerifier() throws Exception {
TestUtil.equalsVerifier(QuizExercise.class);
QuizExercise quizExercise1 = new QuizExercise();
quizExercise1.setId(1L);
QuizExercise quizExercise2 = new QuizExercise();
quizExercise2.setId(quizExercise1.getId());
assertThat(quizExercise1).isEqualTo(quizExercise2);
quizExercise2.setId(2L);
assertThat(quizExercise1).isNotEqualTo(quizExercise2);
quizExercise1.setId(null);
assertThat(quizExercise1).isNotEqualTo(quizExercise2);
}
use of de.tum.in.www1.artemis.domain.quiz.QuizExercise in project ArTEMiS by ls1intum.
the class QuizExerciseResourceIntTest method updateQuizExercise.
@Test
@Transactional
public void updateQuizExercise() throws Exception {
// Initialize the database
quizExerciseRepository.saveAndFlush(quizExercise);
int databaseSizeBeforeUpdate = quizExerciseRepository.findAll().size();
// Update the quizExercise
QuizExercise updatedQuizExercise = quizExerciseRepository.findOne(quizExercise.getId());
updatedQuizExercise.description(UPDATED_DESCRIPTION).explanation(UPDATED_EXPLANATION).randomizeQuestionOrder(UPDATED_RANDOMIZE_QUESTION_ORDER).allowedNumberOfAttempts(UPDATED_ALLOWED_NUMBER_OF_ATTEMPTS).isVisibleBeforeStart(UPDATED_IS_VISIBLE_BEFORE_START).isOpenForPractice(UPDATED_IS_OPEN_FOR_PRACTICE).isPlannedToStart(UPDATED_IS_PLANNED_TO_START).duration(UPDATED_DURATION);
restQuizExerciseMockMvc.perform(put("/api/quiz-exercises").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedQuizExercise))).andExpect(status().isOk());
// Validate the QuizExercise in the database
List<QuizExercise> quizExerciseList = quizExerciseRepository.findAll();
assertThat(quizExerciseList).hasSize(databaseSizeBeforeUpdate);
QuizExercise testQuizExercise = quizExerciseList.get(quizExerciseList.size() - 1);
assertThat(testQuizExercise.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
assertThat(testQuizExercise.getExplanation()).isEqualTo(UPDATED_EXPLANATION);
assertThat(testQuizExercise.isRandomizeQuestionOrder()).isEqualTo(UPDATED_RANDOMIZE_QUESTION_ORDER);
assertThat(testQuizExercise.getAllowedNumberOfAttempts()).isEqualTo(UPDATED_ALLOWED_NUMBER_OF_ATTEMPTS);
assertThat(testQuizExercise.isIsVisibleBeforeStart()).isEqualTo(UPDATED_IS_VISIBLE_BEFORE_START);
assertThat(testQuizExercise.isIsOpenForPractice()).isEqualTo(UPDATED_IS_OPEN_FOR_PRACTICE);
assertThat(testQuizExercise.isIsPlannedToStart()).isEqualTo(UPDATED_IS_PLANNED_TO_START);
assertThat(testQuizExercise.getDuration()).isEqualTo(UPDATED_DURATION);
}
Aggregations