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