Search in sources :

Example 11 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ProgrammingSubmissionResultSimulationService method createSubmission.

/**
 * This method creates a new submission for the provided user
 * @param exerciseId the exerciseId of the exercise for which a submission should be created
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 * @return the newly created and stored submission
 */
public ProgrammingSubmission createSubmission(Long exerciseId) {
    User user = userRepository.getUserWithGroupsAndAuthorities();
    Participant participant = user;
    ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation;
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
    Optional<StudentParticipation> optionalStudentParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(programmingExercise, user.getLogin());
    if (optionalStudentParticipation.isEmpty()) {
        programmingExerciseStudentParticipation = createParticipation(programmingExercise, participant, user);
    } else {
        programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) optionalStudentParticipation.get();
    }
    ProgrammingSubmission programmingSubmission = new ProgrammingSubmission();
    programmingSubmission.setCommitHash(VCSSimulationUtils.simulateCommitHash());
    programmingSubmission.setSubmitted(true);
    programmingSubmission.setSubmissionDate(ZonedDateTime.now());
    programmingSubmission.setType(SubmissionType.MANUAL);
    programmingExerciseStudentParticipation.addSubmission(programmingSubmission);
    programmingSubmissionRepository.save(programmingSubmission);
    return programmingSubmission;
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 12 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ExamQuizService method evaluateSubmissions.

/**
 * // @formatter:off
 * Evaluate the given quiz exercise by performing the following actions for each participation:
 * 1. Get the submission for each participation (there should be only one as in exam mode, the submission gets created upfront and will be updated)
 * - If no submission is found, print a warning and continue as we cannot evaluate that submission
 * - If more than one submission is found, select one of them
 * 2. mark submission and participation as evaluated
 * 3. Create a new result for the selected submission and calculate scores
 * 4. Save the updated submission & participation and the newly created result
 *
 * After processing all participations, the created results will be returned for further processing
 * Note: We ignore test run participations
 * // @formatter:on
 * @param quizExercise the id of the QuizExercise that should be evaluated
 * @return the newly generated results
 */
private Set<Result> evaluateSubmissions(@NotNull QuizExercise quizExercise) {
    Set<Result> createdResults = new HashSet<>();
    List<StudentParticipation> studentParticipations = studentParticipationRepository.findAllWithEagerLegalSubmissionsAndEagerResultsByExerciseId(quizExercise.getId());
    for (var participation : studentParticipations) {
        if (!participation.isTestRun()) {
            try {
                // reconnect so that the quiz questions are available later on (otherwise there will be a org.hibernate.LazyInitializationException)
                participation.setExercise(quizExercise);
                Set<Submission> submissions = participation.getSubmissions();
                QuizSubmission quizSubmission;
                if (submissions.isEmpty()) {
                    log.warn("Found no submissions for participation {} (Participant {}) in quiz {}", participation.getId(), participation.getParticipant().getName(), quizExercise.getId());
                    continue;
                } else if (submissions.size() > 1) {
                    log.warn("Found multiple ({}) submissions for participation {} (Participant {}) in quiz {}, taking the one with highest id", submissions.size(), participation.getId(), participation.getParticipant().getName(), quizExercise.getId());
                    List<Submission> submissionsList = new ArrayList<>(submissions);
                    // Load submission with highest id
                    submissionsList.sort(Comparator.comparing(Submission::getId).reversed());
                    quizSubmission = (QuizSubmission) submissionsList.get(0);
                } else {
                    quizSubmission = (QuizSubmission) submissions.iterator().next();
                }
                participation.setInitializationState(InitializationState.FINISHED);
                boolean resultExisting = false;
                // create new result if none is existing
                Result result;
                if (participation.getResults().isEmpty()) {
                    result = new Result().participation(participation);
                } else {
                    resultExisting = true;
                    result = participation.getResults().iterator().next();
                }
                // Only create Results once after the first evaluation
                if (!resultExisting) {
                    // delete result from quizSubmission, to be able to set a new one
                    if (quizSubmission.getLatestResult() != null) {
                        resultService.deleteResultWithComplaint(quizSubmission.getLatestResult().getId());
                    }
                    result.setRated(true);
                    result.setAssessmentType(AssessmentType.AUTOMATIC);
                    result.setCompletionDate(ZonedDateTime.now());
                    // set submission to calculate scores
                    result.setSubmission(quizSubmission);
                    // calculate scores and update result and submission accordingly
                    quizSubmission.calculateAndUpdateScores(quizExercise);
                    result.evaluateQuizSubmission();
                    // remove submission to follow save order for ordered collections
                    result.setSubmission(null);
                    // NOTE: we save participation, submission and result here individually so that one exception (e.g. duplicated key) cannot destroy multiple student answers
                    submissionRepository.save(quizSubmission);
                    result = resultRepository.save(result);
                    // add result to participation
                    participation.addResult(result);
                    studentParticipationRepository.save(participation);
                    // add result to submission
                    result.setSubmission(quizSubmission);
                    quizSubmission.addResult(result);
                    submissionRepository.save(quizSubmission);
                    // Add result so that it can be returned (and processed later)
                    createdResults.add(result);
                }
            } catch (Exception e) {
                log.error("Exception in evaluateExamQuizExercise() for user {} in quiz {}: {}", participation.getParticipantIdentifier(), quizExercise.getId(), e.getMessage(), e);
            }
        }
    }
    return createdResults;
}
Also used : QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission) Submission(de.tum.in.www1.artemis.domain.Submission) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Result(de.tum.in.www1.artemis.domain.Result) QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission)

Example 13 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class LearningGoalResource method getLearningGoalProgressOfCourse.

/**
 * GET /courses/:courseId/goals/:learningGoalId/course-progress  gets the learning goal progress for the whole course
 *
 * @param courseId                 the id of the course to which the learning goal belongs
 * @param learningGoalId           the id of the learning goal for which to get the progress
 * @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
 * @return the ResponseEntity with status 200 (OK) and with the learning goal course performance in the body
 */
@GetMapping("/courses/{courseId}/goals/{learningGoalId}/course-progress")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<CourseLearningGoalProgress> getLearningGoalProgressOfCourse(@PathVariable Long learningGoalId, @PathVariable Long courseId, @RequestParam(defaultValue = "false", required = false) boolean useParticipantScoreTable) {
    log.debug("REST request to get course progress for LearningGoal : {}", learningGoalId);
    var learningGoal = findLearningGoal(Role.INSTRUCTOR, learningGoalId, courseId);
    CourseLearningGoalProgress courseLearningGoalProgress = learningGoalService.calculateLearningGoalCourseProgress(learningGoal, useParticipantScoreTable);
    return ResponseEntity.ok().body(courseLearningGoalProgress);
}
Also used : CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ParticipantScoreResource method getParticipantScoresOfCourse.

/**
 * GET /courses/:courseId/participant-scores  gets the participant scores of the course
 *
 * @param courseId   the id of the course for which to get the participant score
 * @param pageable   pageable object
 * @param getUnpaged if set all participant scores of the course will be loaded (paging deactivated)
 * @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
 */
@GetMapping("/courses/{courseId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfCourse(@PathVariable Long courseId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get participant scores for course : {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).collect(toSet());
    List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(getUnpaged ? Pageable.unpaged() : pageable, exercisesOfCourse);
    log.info("getParticipantScoresOfCourse took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(resultsOfAllExercises);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Course(de.tum.in.www1.artemis.domain.Course) ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ParticipantScoreResource method getAverageScoreOfParticipantInCourse.

/**
 * GET /courses/:courseId/participant-scores/average-participant  gets the average scores of the participants in the course
 * <p>
 * Important: Exercises with {@link de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore#NOT_INCLUDED} will be not taken into account!
 *
 * @param courseId the id of the course for which to get the average scores of the participants
 * @return the ResponseEntity with status 200 (OK) and with the average scores in the body
 */
@GetMapping("/courses/{courseId}/participant-scores/average-participant")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreAverageDTO>> getAverageScoreOfParticipantInCourse(@PathVariable Long courseId) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get average participant scores of participants for course : {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
    List<ParticipantScoreAverageDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreAverageDTOs(exercisesOfCourse);
    log.info("getAverageScoreOfStudentInCourse took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(resultsOfAllExercises);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) Logger(org.slf4j.Logger) CourseRepository(de.tum.in.www1.artemis.repository.CourseRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Course(de.tum.in.www1.artemis.domain.Course) Set(java.util.Set) Role(de.tum.in.www1.artemis.security.Role) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) HashSet(java.util.HashSet) List(java.util.List) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Exercise(de.tum.in.www1.artemis.domain.Exercise) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ParticipantScoreService(de.tum.in.www1.artemis.service.ParticipantScoreService) AuthorizationCheckService(de.tum.in.www1.artemis.service.AuthorizationCheckService) Pageable(org.springframework.data.domain.Pageable) ResponseEntity(org.springframework.http.ResponseEntity) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Collectors.toSet(java.util.stream.Collectors.toSet) ExamRepository(de.tum.in.www1.artemis.repository.ExamRepository) Exercise(de.tum.in.www1.artemis.domain.Exercise) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)21 Participant (de.tum.in.www1.artemis.domain.participation.Participant)15 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)14 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)12 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)10 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Exercise (de.tum.in.www1.artemis.domain.Exercise)8 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)8 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)7 QuizSubmission (de.tum.in.www1.artemis.domain.quiz.QuizSubmission)7 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)6