use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreResource method getAverageScoreOfParticipantInCourse.
/**
* GET /courses/:courseId/participant-scores/average-participant gets the average scores of the participants in the course
* <p>
* Important: Exercises with {@link de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore#NOT_INCLUDED} will be not taken into account!
*
* @param courseId the id of the course for which to get the average scores of the participants
* @return the ResponseEntity with status 200 (OK) and with the average scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores/average-participant")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreAverageDTO>> getAverageScoreOfParticipantInCourse(@PathVariable Long courseId) {
long start = System.currentTimeMillis();
log.debug("REST request to get average participant scores of participants for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
List<ParticipantScoreAverageDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreAverageDTOs(exercisesOfCourse);
log.info("getAverageScoreOfStudentInCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreIntegrationTest method getAverageScoreOfParticipantInCourse_asInstructorOfCourse_shouldReturnAverageParticipantScores.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getAverageScoreOfParticipantInCourse_asInstructorOfCourse_shouldReturnAverageParticipantScores() throws Exception {
List<ParticipantScoreAverageDTO> participantScoreAverageDTOS = request.getList("/api/courses/" + idOfCourse + "/participant-scores/average-participant", HttpStatus.OK, ParticipantScoreAverageDTO.class);
assertThat(participantScoreAverageDTOS).hasSize(2);
ParticipantScoreAverageDTO student1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.userName != null).findFirst().get();
ParticipantScoreAverageDTO team1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.teamName != null).findFirst().get();
assertAverageParticipantScoreDTOStructure(student1Result, "student1", null, 50.0, 50.0, 5.0, 5.0);
assertAverageParticipantScoreDTOStructure(team1Result, null, "team1", 50.0, 50.0, 5.0, 5.0);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO in project Artemis by ls1intum.
the class ParticipantScoreIntegrationTest method getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores() throws Exception {
List<ParticipantScoreAverageDTO> participantScoreAverageDTOS = request.getList("/api/exams/" + idOfExam + "/participant-scores/average-participant", HttpStatus.OK, ParticipantScoreAverageDTO.class);
assertThat(participantScoreAverageDTOS).hasSize(1);
ParticipantScoreAverageDTO student1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.userName != null).findFirst().get();
assertAverageParticipantScoreDTOStructure(student1Result, "student1", null, 50.0, 50.0, 5.0, 5.0);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreIntegrationTest method getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores() throws Exception {
List<ParticipantScoreAverageDTO> participantScoreAverageDTOS = request.getList("/api/exams/" + idOfExam + "/participant-scores/average-participant", HttpStatus.OK, ParticipantScoreAverageDTO.class);
assertThat(participantScoreAverageDTOS).hasSize(1);
ParticipantScoreAverageDTO student1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.userName != null).findFirst().get();
assertAverageParticipantScoreDTOStructure(student1Result, "student1", null, 50.0, 50.0, 5.0, 5.0);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO in project Artemis by ls1intum.
the class ParticipantScoreResource method getAverageScoreOfParticipantInCourse.
/**
* GET /courses/:courseId/participant-scores/average-participant gets the average scores of the participants in the course
* <p>
* Important: Exercises with {@link de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore#NOT_INCLUDED} will be not taken into account!
*
* @param courseId the id of the course for which to get the average scores of the participants
* @return the ResponseEntity with status 200 (OK) and with the average scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores/average-participant")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreAverageDTO>> getAverageScoreOfParticipantInCourse(@PathVariable Long courseId) {
long start = System.currentTimeMillis();
log.debug("REST request to get average participant scores of participants for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
List<ParticipantScoreAverageDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreAverageDTOs(exercisesOfCourse);
log.info("getAverageScoreOfStudentInCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
Aggregations