Search in sources :

Example 1 with ParticipantScoreAverageDTO

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);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) Logger(org.slf4j.Logger) CourseRepository(de.tum.in.www1.artemis.repository.CourseRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Course(de.tum.in.www1.artemis.domain.Course) Set(java.util.Set) Role(de.tum.in.www1.artemis.security.Role) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) HashSet(java.util.HashSet) List(java.util.List) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Exercise(de.tum.in.www1.artemis.domain.Exercise) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ParticipantScoreService(de.tum.in.www1.artemis.service.ParticipantScoreService) AuthorizationCheckService(de.tum.in.www1.artemis.service.AuthorizationCheckService) Pageable(org.springframework.data.domain.Pageable) ResponseEntity(org.springframework.http.ResponseEntity) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Collectors.toSet(java.util.stream.Collectors.toSet) ExamRepository(de.tum.in.www1.artemis.repository.ExamRepository) Exercise(de.tum.in.www1.artemis.domain.Exercise) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ParticipantScoreAverageDTO

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);
}
Also used : ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with ParticipantScoreAverageDTO

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);
}
Also used : ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with ParticipantScoreAverageDTO

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);
}
Also used : ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 5 with ParticipantScoreAverageDTO

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);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) Logger(org.slf4j.Logger) CourseRepository(de.tum.in.www1.artemis.repository.CourseRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Course(de.tum.in.www1.artemis.domain.Course) Set(java.util.Set) Role(de.tum.in.www1.artemis.security.Role) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) HashSet(java.util.HashSet) List(java.util.List) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Exercise(de.tum.in.www1.artemis.domain.Exercise) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ParticipantScoreService(de.tum.in.www1.artemis.service.ParticipantScoreService) AuthorizationCheckService(de.tum.in.www1.artemis.service.AuthorizationCheckService) Pageable(org.springframework.data.domain.Pageable) ResponseEntity(org.springframework.http.ResponseEntity) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Collectors.toSet(java.util.stream.Collectors.toSet) ExamRepository(de.tum.in.www1.artemis.repository.ExamRepository) Exercise(de.tum.in.www1.artemis.domain.Exercise) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)6 Test (org.junit.jupiter.api.Test)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Course (de.tum.in.www1.artemis.domain.Course)2 Exercise (de.tum.in.www1.artemis.domain.Exercise)2 IncludedInOverallScore (de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore)2 Exam (de.tum.in.www1.artemis.domain.exam.Exam)2 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)2 CourseRepository (de.tum.in.www1.artemis.repository.CourseRepository)2 ExamRepository (de.tum.in.www1.artemis.repository.ExamRepository)2 Role (de.tum.in.www1.artemis.security.Role)2 AuthorizationCheckService (de.tum.in.www1.artemis.service.AuthorizationCheckService)2 ParticipantScoreService (de.tum.in.www1.artemis.service.ParticipantScoreService)2 ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)2 ScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ScoreDTO)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Logger (org.slf4j.Logger)2