Search in sources :

Example 1 with Submission

use of de.tum.in.www1.artemis.domain.Submission 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();
    }
}
Also used : QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission) QuizSubmissionException(de.tum.in.www1.artemis.exception.QuizSubmissionException) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

Example 2 with Submission

use of de.tum.in.www1.artemis.domain.Submission in project Artemis by ls1intum.

the class AbstractContinuousIntegrationService method createFallbackSubmission.

/**
 * There can be two reasons for the case that there is no programmingSubmission:
 * 1) Manual build triggered from CI (e.g. by the instructor)
 * 2) An unknown error that caused the programming submission not to be created when the code commits have been pushed.
 * we can still get the commit hash from the payload of the CI build result and "reverse engineer" the programming submission object to be consistent
 */
@NotNull
protected ProgrammingSubmission createFallbackSubmission(ProgrammingExerciseParticipation participation, ZonedDateTime submissionDate, String commitHash) {
    ProgrammingSubmission submission = new ProgrammingSubmission();
    submission.setParticipation((Participation) participation);
    submission.setSubmitted(true);
    // We set this to manual because all programming submissions should correspond to a student commit in the git history.
    // In case we cannot find the appropriate submission, it means something has not worked before, but there will still be a commit in the student repository
    submission.setType(SubmissionType.MANUAL);
    submission.setCommitHash(commitHash);
    submission.setSubmissionDate(submissionDate);
    return submission;
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) NotNull(javax.validation.constraints.NotNull)

Example 3 with Submission

use of de.tum.in.www1.artemis.domain.Submission in project Artemis by ls1intum.

the class LearningGoalService method calculateLearningGoalCourseProgress.

/**
 * Calculate the progress in a learning goal for a whole course
 *
 * @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
 * @param learningGoal             learning goal to get the progress for
 * @return progress of the course in the learning goal
 */
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
    CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
    courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
    courseLearningGoalProgress.learningGoalId = learningGoal.getId();
    courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
    // The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
    List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
    Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
    // updating learningGoalPerformance by summing up the points of the individual lecture unit progress
    courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
    courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
    return courseLearningGoalProgress;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 4 with Submission

use of de.tum.in.www1.artemis.domain.Submission in project Artemis by ls1intum.

the class ModelingExerciseImportService method copyExampleSubmission.

/**
 * This functions does a hard copy of the example submissions contained in {@code templateExercise}.
 * To copy the corresponding Submission entity this function calls {@link #copySubmission(Submission)}
 *
 * @param templateExercise {TextExercise} The original exercise from which to fetch the example submissions
 * @param newExercise The new exercise in which we will insert the example submissions
 * @return The cloned set of example submissions
 */
@Override
Set<ExampleSubmission> copyExampleSubmission(Exercise templateExercise, Exercise newExercise) {
    log.debug("Copying the ExampleSubmissions to new Exercise: {}", newExercise);
    Set<ExampleSubmission> newExampleSubmissions = new HashSet<>();
    for (ExampleSubmission originalExampleSubmission : templateExercise.getExampleSubmissions()) {
        ModelingSubmission originalSubmission = (ModelingSubmission) originalExampleSubmission.getSubmission();
        ModelingSubmission newSubmission = (ModelingSubmission) copySubmission(originalSubmission);
        ExampleSubmission newExampleSubmission = new ExampleSubmission();
        newExampleSubmission.setExercise(newExercise);
        newExampleSubmission.setSubmission(newSubmission);
        newExampleSubmission.setAssessmentExplanation(originalExampleSubmission.getAssessmentExplanation());
        exampleSubmissionRepository.save(newExampleSubmission);
        newExampleSubmissions.add(newExampleSubmission);
    }
    return newExampleSubmissions;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) HashSet(java.util.HashSet)

Example 5 with Submission

use of de.tum.in.www1.artemis.domain.Submission in project Artemis by ls1intum.

the class DatabaseUtilService method generateExampleSubmission.

/**
 * Generates an example submission for a given model and exercise
 *
 * @param modelOrText             given uml model for the example submission
 * @param exercise                exercise for which the example submission is created
 * @param flagAsExampleSubmission true if the submission is an example submission
 * @param usedForTutorial         true if the example submission is used for tutorial
 * @return created example submission
 */
public ExampleSubmission generateExampleSubmission(String modelOrText, Exercise exercise, boolean flagAsExampleSubmission, boolean usedForTutorial) {
    Submission submission;
    if (exercise instanceof ModelingExercise) {
        submission = ModelFactory.generateModelingSubmission(modelOrText, false);
    } else {
        submission = ModelFactory.generateTextSubmission(modelOrText, Language.ENGLISH, false);
        saveSubmissionToRepo(submission);
    }
    submission.setExampleSubmission(flagAsExampleSubmission);
    return ModelFactory.generateExampleSubmission(submission, exercise, usedForTutorial);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Aggregations

Test (org.junit.jupiter.api.Test)226 WithMockUser (org.springframework.security.test.context.support.WithMockUser)216 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)178 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)153 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)72 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)56 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)52 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)48 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)44 Collectors (java.util.stream.Collectors)42 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)40 ZonedDateTime (java.time.ZonedDateTime)40 java.util (java.util)40 HttpHeaders (org.springframework.http.HttpHeaders)40 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)40 Participation (de.tum.in.www1.artemis.domain.participation.Participation)38 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)34 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)34 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)32 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)30