use of de.tum.in.www1.artemis.domain.scores.ParticipantScore in project Artemis by ls1intum.
the class ScoreService method getNewLastResultForParticipantScore.
/**
* Get the result that can replace the currently set last result for a participant score
*
* @param participantScore participant score
* @return optional of new result
*/
private Optional<Result> getNewLastResultForParticipantScore(ParticipantScore participantScore) {
List<Result> resultOrdered;
if (participantScore.getClass().equals(StudentScore.class)) {
StudentScore studentScore = (StudentScore) participantScore;
resultOrdered = resultRepository.getResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForStudent(participantScore.getExercise().getId(), studentScore.getUser().getId()).stream().filter(r -> !participantScore.getLastResult().equals(r)).collect(Collectors.toList());
} else {
TeamScore teamScore = (TeamScore) participantScore;
resultOrdered = resultRepository.getResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForTeam(participantScore.getExercise().getId(), teamScore.getTeam().getId()).stream().filter(r -> !participantScore.getLastResult().equals(r)).collect(Collectors.toList());
}
// the new last result (result with the highest id of submission with the highest id) will be at the beginning of the list
return resultOrdered.isEmpty() ? Optional.empty() : Optional.of(resultOrdered.get(0));
}
use of de.tum.in.www1.artemis.domain.scores.ParticipantScore in project Artemis by ls1intum.
the class ScoreService method getNewLastRatedResultForParticipantScore.
/**
* Get the result that can replace the currently set last rated result for a participant score
*
* @param participantScore participant score
* @return optional of new result
*/
private Optional<Result> getNewLastRatedResultForParticipantScore(ParticipantScore participantScore) {
List<Result> ratedResultsOrdered;
if (participantScore.getClass().equals(StudentScore.class)) {
StudentScore studentScore = (StudentScore) participantScore;
ratedResultsOrdered = resultRepository.getRatedResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForStudent(participantScore.getExercise().getId(), studentScore.getUser().getId()).stream().filter(r -> !participantScore.getLastRatedResult().equals(r)).collect(Collectors.toList());
} else {
TeamScore teamScore = (TeamScore) participantScore;
ratedResultsOrdered = resultRepository.getRatedResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForTeam(participantScore.getExercise().getId(), teamScore.getTeam().getId()).stream().filter(r -> !participantScore.getLastRatedResult().equals(r)).collect(Collectors.toList());
}
// the new last rated result (rated result with the highest id of submission with the highest id) will be at the beginning of the list
return ratedResultsOrdered.isEmpty() ? Optional.empty() : Optional.of(ratedResultsOrdered.get(0));
}
use of de.tum.in.www1.artemis.domain.scores.ParticipantScore 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.scores.ParticipantScore 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.scores.ParticipantScore in project Artemis by ls1intum.
the class ExerciseScoresChartService method createExerciseScoreDTO.
private ExerciseScoresDTO createExerciseScoreDTO(Map<Long, ExerciseScoresAggregatedInformation> exerciseIdToAggregatedInformation, Map<Long, StudentScore> individualExerciseIdToStudentScore, Map<Long, TeamScore> teamExerciseIdToTeamScore, Exercise exercise) {
ExerciseScoresDTO exerciseScoresDTO = new ExerciseScoresDTO(exercise);
ExerciseScoresAggregatedInformation aggregatedInformation = exerciseIdToAggregatedInformation.get(exercise.getId());
if (aggregatedInformation == null || aggregatedInformation.getAverageScoreAchieved() == null || aggregatedInformation.getMaxScoreAchieved() == null) {
exerciseScoresDTO.averageScoreAchieved = 0D;
exerciseScoresDTO.maxScoreAchieved = 0D;
} else {
exerciseScoresDTO.averageScoreAchieved = roundScoreSpecifiedByCourseSettings(aggregatedInformation.getAverageScoreAchieved(), exercise.getCourseViaExerciseGroupOrCourseMember());
exerciseScoresDTO.maxScoreAchieved = roundScoreSpecifiedByCourseSettings(aggregatedInformation.getMaxScoreAchieved(), exercise.getCourseViaExerciseGroupOrCourseMember());
}
ParticipantScore participantScore = exercise.getMode().equals(ExerciseMode.INDIVIDUAL) ? individualExerciseIdToStudentScore.get(exercise.getId()) : teamExerciseIdToTeamScore.get(exercise.getId());
exerciseScoresDTO.scoreOfStudent = participantScore == null || participantScore.getLastRatedScore() == null ? 0D : roundScoreSpecifiedByCourseSettings(participantScore.getLastScore(), exercise.getCourseViaExerciseGroupOrCourseMember());
return exerciseScoresDTO;
}
Aggregations