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