Search in sources :

Example 1 with StudentScore

use of de.tum.in.www1.artemis.domain.scores.StudentScore 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));
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 2 with StudentScore

use of de.tum.in.www1.artemis.domain.scores.StudentScore 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));
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 3 with StudentScore

use of de.tum.in.www1.artemis.domain.scores.StudentScore in project ArTEMiS by ls1intum.

the class ParticipantScoreDTO method generateFromParticipantScore.

/**
 * Generates a {@link ParticipantScoreDTO} from a {@link ParticipantScore}
 *
 * @param participantScore ParticipantScore input
 * @return {@link ParticipantScoreDTO}
 */
public static ParticipantScoreDTO generateFromParticipantScore(ParticipantScore participantScore) {
    String userName = null;
    Long userId = null;
    String teamName = null;
    Long teamId = null;
    if (participantScore.getClass().equals(StudentScore.class)) {
        StudentScore studentScore = (StudentScore) participantScore;
        if (studentScore.getUser() != null) {
            userName = studentScore.getUser().getLogin();
            userId = studentScore.getUser().getId();
        }
    } else {
        TeamScore teamScore = (TeamScore) participantScore;
        if (teamScore.getTeam() != null) {
            teamName = teamScore.getTeam().getName();
            teamId = teamScore.getTeam().getId();
        }
    }
    Long id = participantScore.getId();
    String exerciseTitle = participantScore.getExercise() != null && participantScore.getExercise().getTitle() != null ? participantScore.getExercise().getTitle() : null;
    Long exerciseId = participantScore.getExercise() != null ? participantScore.getExercise().getId() : null;
    Long lastResultId = participantScore.getLastResult() != null ? participantScore.getLastResult().getId() : null;
    Double lastResultScore = participantScore.getLastScore();
    Long lastRatedResultId = participantScore.getLastRatedResult() != null ? participantScore.getLastRatedResult().getId() : null;
    Double lastRatedResultScore = participantScore.getLastRatedScore();
    Double lastPoints = participantScore.getLastPoints();
    Double lastRatedPoints = participantScore.getLastRatedPoints();
    return new ParticipantScoreDTO(id, userId, userName, teamId, teamName, exerciseId, exerciseTitle, lastResultId, lastResultScore, lastRatedResultId, lastRatedResultScore, lastPoints, lastRatedPoints);
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 4 with StudentScore

use of de.tum.in.www1.artemis.domain.scores.StudentScore in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method saveRatedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(true, isTeamTest);
    Result persistedResult = originalParticipantScore.getLastResult();
    // removing the result should trigger the entity listener and remove the associated student score
    resultRepository.deleteById(persistedResult.getId());
    List<StudentScore> savedStudentScores = studentScoreRepository.findAll();
    List<Result> savedResults = resultRepository.findAll();
    assertThat(savedStudentScores).isEmpty();
    assertThat(savedResults).isEmpty();
    verify(scoreService, times(1)).removeOrUpdateAssociatedParticipantScore(any(Result.class));
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with StudentScore

use of de.tum.in.www1.artemis.domain.scores.StudentScore 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

StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)16 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 ExerciseScoresAggregatedInformation (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation)2 ExerciseScoresDTO (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)2