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");
}
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();
}
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);
}
}
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;
}
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);
}
Aggregations