Search in sources :

Example 1 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO in project ArTEMiS by ls1intum.

the class ExerciseScoresChartResource method getCourseExerciseScores.

/**
 * GET /courses/:courseId/charts/exercise-scores
 * <p>
 * This call returns the information used for the exercise-scores-chart. It will get the score of
 * the requesting user,the average score and the best score in course exercises
 * <p>
 * Note: Only released course exercises with assessment due date over are considered!
 * <p>
 *
 * @param courseId id of the course for which to get the exercise scores
 * @return the ResponseEntity with status 200 (OK) and with the exercise scores in the body
 */
@GetMapping("courses/{courseId}/charts/exercise-scores")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<ExerciseScoresDTO>> getCourseExerciseScores(@PathVariable Long courseId) {
    log.debug("REST request to get exercise scores for course with id: {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    // we only consider exercises in which the student had a chance to earn a score (released and due date over)
    List<ExerciseScoresDTO> exerciseScoresDTOList = exerciseScoresChartService.getExerciseScores(filterExercises(course.getExercises()), user);
    return ResponseEntity.ok(exerciseScoresDTOList);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO) Course(de.tum.in.www1.artemis.domain.Course) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO in project Artemis by ls1intum.

the class ExerciseScoresChartIntegrationTest method getCourseExerciseScores_asStudent_shouldReturnCorrectIndividualAverageAndMaxScores.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void getCourseExerciseScores_asStudent_shouldReturnCorrectIndividualAverageAndMaxScores() throws Exception {
    List<ExerciseScoresDTO> exerciseScores = request.getList(getEndpointUrl(idOfCourse), HttpStatus.OK, ExerciseScoresDTO.class);
    assertThat(exerciseScores).hasSize(3);
    ExerciseScoresDTO individualTextExercise = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfIndividualTextExercise)).findFirst().get();
    ExerciseScoresDTO teamTextExercise = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfTeamTextExercise)).findFirst().get();
    ExerciseScoresDTO individualTextExerciseWithoutParticipants = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfIndividualTextExerciseWithoutParticipants)).findFirst().get();
    assertThat(individualTextExercise.scoreOfStudent).isEqualTo(50.0);
    assertThat(individualTextExercise.averageScoreAchieved).isEqualTo(40.0);
    assertThat(individualTextExercise.maxScoreAchieved).isEqualTo(50);
    assertThat(teamTextExercise.scoreOfStudent).isEqualTo(50.0);
    assertThat(teamTextExercise.averageScoreAchieved).isEqualTo(70.0);
    assertThat(teamTextExercise.maxScoreAchieved).isEqualTo(90.0);
    assertThat(individualTextExerciseWithoutParticipants.scoreOfStudent).isEqualTo(0.0);
    assertThat(individualTextExerciseWithoutParticipants.averageScoreAchieved).isEqualTo(0.0);
    assertThat(individualTextExerciseWithoutParticipants.maxScoreAchieved).isEqualTo(0.0);
}
Also used : ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO 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;
}
Also used : ExerciseScoresAggregatedInformation(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)

Example 4 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO 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;
}
Also used : ExerciseScoresAggregatedInformation(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)

Example 5 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO in project ArTEMiS by ls1intum.

the class ExerciseScoresChartIntegrationTest method getCourseExerciseScores_asStudent_shouldReturnCorrectIndividualAverageAndMaxScores.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void getCourseExerciseScores_asStudent_shouldReturnCorrectIndividualAverageAndMaxScores() throws Exception {
    List<ExerciseScoresDTO> exerciseScores = request.getList(getEndpointUrl(idOfCourse), HttpStatus.OK, ExerciseScoresDTO.class);
    assertThat(exerciseScores).hasSize(3);
    ExerciseScoresDTO individualTextExercise = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfIndividualTextExercise)).findFirst().get();
    ExerciseScoresDTO teamTextExercise = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfTeamTextExercise)).findFirst().get();
    ExerciseScoresDTO individualTextExerciseWithoutParticipants = exerciseScores.stream().filter(exerciseScoresDTO -> exerciseScoresDTO.exerciseId.equals(idOfIndividualTextExerciseWithoutParticipants)).findFirst().get();
    assertThat(individualTextExercise.scoreOfStudent).isEqualTo(50.0);
    assertThat(individualTextExercise.averageScoreAchieved).isEqualTo(40.0);
    assertThat(individualTextExercise.maxScoreAchieved).isEqualTo(50);
    assertThat(teamTextExercise.scoreOfStudent).isEqualTo(50.0);
    assertThat(teamTextExercise.averageScoreAchieved).isEqualTo(70.0);
    assertThat(teamTextExercise.maxScoreAchieved).isEqualTo(90.0);
    assertThat(individualTextExerciseWithoutParticipants.scoreOfStudent).isEqualTo(0.0);
    assertThat(individualTextExerciseWithoutParticipants.averageScoreAchieved).isEqualTo(0.0);
    assertThat(individualTextExerciseWithoutParticipants.maxScoreAchieved).isEqualTo(0.0);
}
Also used : ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

ExerciseScoresDTO (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)6 Course (de.tum.in.www1.artemis.domain.Course)2 User (de.tum.in.www1.artemis.domain.User)2 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)2 ExerciseScoresAggregatedInformation (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation)2 Test (org.junit.jupiter.api.Test)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2