Search in sources :

Example 1 with ScoreDTO

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

the class ParticipantScoreResource method getScoresOfExam.

/**
 * GET /exams/:examId/exam-scores gets the exam scores of the exam
 * <p>
 * This method represents a server based way to calculate a students achieved points / score in an exam.
 * <p>
 * Currently both this server based calculation method and the traditional client side calculation method is used
 * side-by-side in exam-scores.component.ts.
 * <p>
 * The goal is to switch completely to this much faster server based calculation if the {@link de.tum.in.www1.artemis.service.listeners.ResultListener}
 * has been battle tested enough.
 *
 * @param examId the id of the exam for which to calculate the exam scores
 * @return list of scores for every registered user in the xam
 */
@GetMapping("/exams/{examId}/exam-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ScoreDTO>> getScoresOfExam(@PathVariable Long examId) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get exam scores for exam : {}", examId);
    Exam exam = examRepository.findByIdWithRegisteredUsersExerciseGroupsAndExercisesElseThrow(examId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, exam.getCourse(), null);
    List<ScoreDTO> scoreDTOS = participantScoreService.calculateExamScores(exam);
    log.info("getScoresOfExam took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(scoreDTOS);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ScoreDTO

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

the class ParticipantScoreIntegrationTest method getCourseScores_asInstructorOfCourse_shouldReturnCourseScores.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getCourseScores_asInstructorOfCourse_shouldReturnCourseScores() throws Exception {
    List<ScoreDTO> courseScores = request.getList("/api/courses/" + idOfCourse + "/course-scores", HttpStatus.OK, ScoreDTO.class);
    assertThat(courseScores).hasSize(25);
    ScoreDTO scoreOfStudent1 = courseScores.stream().filter(scoreDTO -> scoreDTO.studentId.equals(idOfStudent1)).findFirst().get();
    assertThat(scoreOfStudent1.studentLogin).isEqualTo("student1");
    assertThat(scoreOfStudent1.pointsAchieved).isEqualTo(10.0);
    assertThat(scoreOfStudent1.scoreAchieved).isEqualTo(50.0);
    assertThat(scoreOfStudent1.regularPointsAchievable).isEqualTo(20.0);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with ScoreDTO

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

the class ParticipantScoreService method calculateScores.

private List<ScoreDTO> calculateScores(Set<Exercise> exercises, Set<User> users, Double scoreCalculationDenominator) {
    // 0.0 means we can not reasonably calculate the achieved points / scores
    if (scoreCalculationDenominator.equals(0.0)) {
        return List.of();
    }
    Set<Exercise> individualExercises = exercises.stream().filter(exercise -> !exercise.isTeamMode()).collect(Collectors.toSet());
    Set<Exercise> teamExercises = exercises.stream().filter(Exercise::isTeamMode).collect(Collectors.toSet());
    Course course = exercises.stream().findAny().get().getCourseViaExerciseGroupOrCourseMember();
    // For every student we want to calculate the score
    Map<Long, ScoreDTO> userIdToScores = users.stream().collect(Collectors.toMap(User::getId, ScoreDTO::new));
    // individual exercises
    // [0] -> User
    // [1] -> sum of achieved points in exercises
    List<Object[]> studentAndAchievedPoints = studentScoreRepository.getAchievedPointsOfStudents(individualExercises);
    for (Object[] rawData : studentAndAchievedPoints) {
        User user = (User) rawData[0];
        double achievedPoints = rawData[1] != null ? ((Number) rawData[1]).doubleValue() : 0.0;
        if (userIdToScores.containsKey(user.getId())) {
            userIdToScores.get(user.getId()).pointsAchieved += achievedPoints;
        }
    }
    // team exercises
    // [0] -> Team
    // [1] -> sum of achieved points in exercises
    List<Object[]> teamAndAchievedPoints = teamScoreRepository.getAchievedPointsOfTeams(teamExercises);
    for (Object[] rawData : teamAndAchievedPoints) {
        Team team = (Team) rawData[0];
        double achievedPoints = rawData[1] != null ? ((Number) rawData[1]).doubleValue() : 0.0;
        for (User student : team.getStudents()) {
            if (userIdToScores.containsKey(student.getId())) {
                userIdToScores.get(student.getId()).pointsAchieved += achievedPoints;
            }
        }
    }
    // calculating achieved score
    for (ScoreDTO scoreDTO : userIdToScores.values()) {
        scoreDTO.scoreAchieved = roundScoreSpecifiedByCourseSettings((scoreDTO.pointsAchieved / scoreCalculationDenominator) * 100.0, course);
        // sending this for debugging purposes to find out why the scores' calculation could be wrong
        scoreDTO.regularPointsAchievable = scoreCalculationDenominator;
    }
    return new ArrayList<>(userIdToScores.values());
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) java.util(java.util) RequestParam(org.springframework.web.bind.annotation.RequestParam) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) ZonedDateTime(java.time.ZonedDateTime) ExerciseMode(de.tum.in.www1.artemis.domain.enumeration.ExerciseMode) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) Collectors(java.util.stream.Collectors) RoundingUtil.roundScoreSpecifiedByCourseSettings(de.tum.in.www1.artemis.service.util.RoundingUtil.roundScoreSpecifiedByCourseSettings) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Service(org.springframework.stereotype.Service) Pageable(org.springframework.data.domain.Pageable) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO)

Example 4 with ScoreDTO

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

the class ParticipantScoreResource method getScoresOfExam.

/**
 * GET /exams/:examId/exam-scores gets the exam scores of the exam
 * <p>
 * This method represents a server based way to calculate a students achieved points / score in an exam.
 * <p>
 * Currently both this server based calculation method and the traditional client side calculation method is used
 * side-by-side in exam-scores.component.ts.
 * <p>
 * The goal is to switch completely to this much faster server based calculation if the {@link de.tum.in.www1.artemis.service.listeners.ResultListener}
 * has been battle tested enough.
 *
 * @param examId the id of the exam for which to calculate the exam scores
 * @return list of scores for every registered user in the xam
 */
@GetMapping("/exams/{examId}/exam-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ScoreDTO>> getScoresOfExam(@PathVariable Long examId) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get exam scores for exam : {}", examId);
    Exam exam = examRepository.findByIdWithRegisteredUsersExerciseGroupsAndExercisesElseThrow(examId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, exam.getCourse(), null);
    List<ScoreDTO> scoreDTOS = participantScoreService.calculateExamScores(exam);
    log.info("getScoresOfExam took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(scoreDTOS);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with ScoreDTO

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

the class ParticipantScoreResource method getScoresOfCourse.

/**
 * GET /courses/:courseId/course-scores gets the course scores of the course
 * <p>
 * This method represents a server based way to calculate a students achieved points / score in a course.
 * <p>
 * Currently both this server based calculation method and the traditional client side calculation method is used
 * side-by-side in course-scores.component.ts.
 * <p>
 * The goal is to switch completely to this much faster server based calculation if the {@link de.tum.in.www1.artemis.service.listeners.ResultListener}
 * has been battle tested enough.
 *
 * @param courseId the id of the course for which to calculate the course scores
 * @return list of scores for every member of the course
 */
@GetMapping("/courses/{courseId}/course-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ScoreDTO>> getScoresOfCourse(@PathVariable Long courseId) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get course scores for course : {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    List<ScoreDTO> scoreDTOS = participantScoreService.calculateCourseScores(course);
    log.info("getScoresOfCourse took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(scoreDTOS);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)10 ScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ScoreDTO)10 Exam (de.tum.in.www1.artemis.domain.exam.Exam)4 Test (org.junit.jupiter.api.Test)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2 Course (de.tum.in.www1.artemis.domain.Course)2 ExerciseMode (de.tum.in.www1.artemis.domain.enumeration.ExerciseMode)2 IncludedInOverallScore (de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore)2 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)2 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)2 RoundingUtil.roundScoreSpecifiedByCourseSettings (de.tum.in.www1.artemis.service.util.RoundingUtil.roundScoreSpecifiedByCourseSettings)2 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)2 ZonedDateTime (java.time.ZonedDateTime)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Pageable (org.springframework.data.domain.Pageable)2 Service (org.springframework.stereotype.Service)2