Search in sources :

Example 21 with StudentParticipation

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

the class AssessmentServiceTest method createModelingExerciseSubmissionAndCalculateScore.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createModelingExerciseSubmissionAndCalculateScore() {
    ModelingExercise exercise = createModelingExerciseWithSGI(course1);
    Submission submissionWithoutResult = new ModelingSubmission();
    submissionWithoutResult.setSubmissionDate(pastTimestamp.plusMinutes(3L));
    submissionWithoutResult = database.addSubmission(exercise, submissionWithoutResult, "student1");
    database.addSubmission((StudentParticipation) submissionWithoutResult.getParticipation(), submissionWithoutResult);
    List<Feedback> feedbacks = createFeedback(exercise);
    var result = new Result();
    result.setSubmission(submissionWithoutResult);
    result.setFeedbacks(feedbacks);
    result.setParticipation(submissionWithoutResult.getParticipation());
    submissionWithoutResult.addResult(result);
    resultRepository.submitResult(result, exercise, exerciseDateService.getDueDate(result.getParticipation()));
    resultRepository.save(result);
    assertThat(result.getResultString()).isEqualTo("6 of 7 points");
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with StudentParticipation

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

the class AssessmentServiceTest method testRatedAfterSubmitResultWithDueDateBeforeSubmissionDateOfResult.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testRatedAfterSubmitResultWithDueDateBeforeSubmissionDateOfResult() {
    TextExercise exercise = createTextExerciseWithSGI(course1);
    Submission submissionWithoutResult = new TextSubmission();
    submissionWithoutResult.setSubmissionDate(pastTimestamp);
    submissionWithoutResult = database.addSubmission(exercise, submissionWithoutResult, "student1");
    database.addSubmission((StudentParticipation) submissionWithoutResult.getParticipation(), submissionWithoutResult);
    List<Feedback> feedbacks = createFeedback(exercise);
    var result = new Result();
    result.setSubmission(submissionWithoutResult);
    result.setFeedbacks(feedbacks);
    result.setParticipation(submissionWithoutResult.getParticipation());
    submissionWithoutResult.addResult(result);
    resultRepository.submitResult(result, exercise, exerciseDateService.getDueDate(result.getParticipation()));
    resultRepository.save(result);
    assertThat(result.isRated()).isTrue();
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with StudentParticipation

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

the class ScoreService method updateOrCreateParticipantScore.

/**
 * Either updates an existing participant score or creates a new participant score if a new result comes in
 * The annotation "@Transactional" is ok because it means that this method does not support run in an outer transactional context, instead the outer transaction is paused
 *
 * @param createdOrUpdatedResult newly created or updated result
 */
// ok (see JavaDoc)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void updateOrCreateParticipantScore(Result createdOrUpdatedResult) {
    if (createdOrUpdatedResult.getScore() == null || createdOrUpdatedResult.getCompletionDate() == null) {
        return;
    }
    // There is a deadlock problem with programming exercises here if we use the participation from the result (reason unknown at the moment)
    // therefore we get the participation from the database
    Optional<StudentParticipation> studentParticipationOptional = getStudentParticipationForResult(createdOrUpdatedResult);
    if (studentParticipationOptional.isEmpty()) {
        return;
    }
    StudentParticipation studentParticipation = studentParticipationOptional.get();
    // we ignore test runs of exams
    if (studentParticipation.isTestRun()) {
        return;
    }
    Exercise exercise = studentParticipation.getExercise();
    ParticipantScore existingParticipationScoreForExerciseAndParticipant = getExistingParticipationScore(studentParticipation, exercise);
    // there already exists a participant score -> we need to update it
    if (existingParticipationScoreForExerciseAndParticipant != null) {
        updateExistingParticipantScore(existingParticipationScoreForExerciseAndParticipant, createdOrUpdatedResult, exercise);
    } else {
        // there does not already exist a participant score -> we need to create it
        createNewParticipantScore(createdOrUpdatedResult, studentParticipation, exercise);
    }
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with StudentParticipation

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

the class ScoreService method getExistingParticipationScore.

/**
 * Gets the existing participation score for an exercise and a participant or null if none can be found
 *
 * @param studentParticipation participation containing the information about the participant
 * @param exercise             exercise for which to find the participation score of the participant
 * @return existing participation score or null if none can be found
 */
private ParticipantScore getExistingParticipationScore(StudentParticipation studentParticipation, Exercise exercise) {
    ParticipantScore existingParticipationScoreForExerciseAndParticipant = null;
    if (exercise.isTeamMode()) {
        Team team = studentParticipation.getTeam().get();
        Optional<TeamScore> teamScoreOptional = teamScoreRepository.findTeamScoreByExerciseAndTeam(exercise, team);
        if (teamScoreOptional.isPresent()) {
            existingParticipationScoreForExerciseAndParticipant = teamScoreOptional.get();
        }
    } else {
        User user = studentParticipation.getStudent().get();
        Optional<StudentScore> studentScoreOptional = studentScoreRepository.findStudentScoreByExerciseAndUser(exercise, user);
        if (studentScoreOptional.isPresent()) {
            existingParticipationScoreForExerciseAndParticipant = studentScoreOptional.get();
        }
    }
    return existingParticipationScoreForExerciseAndParticipant;
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 25 with StudentParticipation

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

the class ScoreService method createNewStudentScore.

private void createNewStudentScore(Result newResult, StudentParticipation studentParticipation, Exercise exercise) {
    StudentScore newStudentScore = new StudentScore();
    newStudentScore.setExercise(exercise);
    newStudentScore.setUser(studentParticipation.getStudent().get());
    setLastAttributes(newStudentScore, newResult, exercise);
    if (newResult.isRated() != null && newResult.isRated()) {
        setLastRatedAttributes(newStudentScore, newResult, exercise);
    }
    StudentScore studentScore = studentScoreRepository.saveAndFlush(newStudentScore);
    logger.info("Saved a new student score: " + studentScore);
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)217 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)43 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)40 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)27 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24