use of de.tum.in.www1.artemis.service.exam 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);
}
use of de.tum.in.www1.artemis.service.exam in project ArTEMiS by ls1intum.
the class ParticipantScoreResource method getAverageScoreOfCourse.
/**
* GET /courses/:courseId/participant-scores/average gets the average score of 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 score
* @param onlyConsiderRatedScores if set the method will get the rated average score, if unset the method will get the average score
* @return the ResponseEntity with status 200 (OK) and with average score in the body
*/
@GetMapping("/courses/{courseId}/participant-scores/average")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Double> getAverageScoreOfCourse(@PathVariable Long courseId, @RequestParam(defaultValue = "true", required = false) boolean onlyConsiderRatedScores) {
long start = System.currentTimeMillis();
if (onlyConsiderRatedScores) {
log.debug("REST request to get average rated scores for course : {}", courseId);
} else {
log.debug("REST request to get average scores for course : {}", courseId);
}
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> includedExercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
Double averageScore = participantScoreService.getAverageScore(onlyConsiderRatedScores, includedExercisesOfCourse);
log.info("getAverageScoreOfCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(averageScore);
}
use of de.tum.in.www1.artemis.service.exam in project ArTEMiS by ls1intum.
the class ParticipationServiceTest method testCreateParticipationForExternalSubmission.
/**
* Test for methods of {@link ParticipationService} used by {@link de.tum.in.www1.artemis.web.rest.ResultResource#createResultForExternalSubmission(Long, String, Result)}.
*/
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testCreateParticipationForExternalSubmission() throws Exception {
Optional<User> student = userRepository.findOneWithGroupsAndAuthoritiesByLogin("student1");
var someURL = new VcsRepositoryUrl("http://vcs.fake.fake");
// Copy Repository in ParticipationService#copyRepository(..)
doReturn(someURL).when(versionControlService).copyRepository(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class));
// Configure Repository in ParticipationService#configureRepository(..)
doNothing().when(versionControlService).configureRepository(any(), any(), anyBoolean());
// Configure WebHook in ParticipationService#configureRepositoryWebHook(..)
doNothing().when(versionControlService).addWebHookForParticipation(any());
// Do Nothing when setRepositoryPermissionsToReadOnly in ParticipationService#createParticipationWithEmptySubmissionIfNotExisting
doNothing().when(versionControlService).setRepositoryPermissionsToReadOnly(any(), any(String.class), any());
// Return the default branch for all repositories of the exercise
doReturn(defaultBranch).when(versionControlService).getOrRetrieveBranchOfExercise(programmingExercise);
StudentParticipation participation = participationService.createParticipationWithEmptySubmissionIfNotExisting(programmingExercise, student.get(), SubmissionType.EXTERNAL);
assertThat(participation).isNotNull();
assertThat(participation.getSubmissions()).hasSize(1);
assertThat(participation.getStudent()).contains(student.get());
ProgrammingSubmission programmingSubmission = (ProgrammingSubmission) participation.findLatestSubmission().get();
assertThat(programmingSubmission.getType()).isEqualTo(SubmissionType.EXTERNAL);
// results are not added in the invoked method above
assertThat(programmingSubmission.getResults()).isNullOrEmpty();
}
use of de.tum.in.www1.artemis.service.exam in project ArTEMiS by ls1intum.
the class GitlabRequestMockProvider method mockSetPermissionsForNewGroupMembers.
private void mockSetPermissionsForNewGroupMembers(List<ProgrammingExercise> programmingExercises, Set<de.tum.in.www1.artemis.domain.User> newUsers, Course updatedCourse) {
for (de.tum.in.www1.artemis.domain.User user : newUsers) {
try {
mockGetUserId(user.getLogin(), true, false);
Optional<AccessLevel> accessLevel = getAccessLevelFromUserGroups(user.getGroups(), updatedCourse);
if (accessLevel.isPresent()) {
mockAddUserToGroups(1L, programmingExercises, accessLevel.get());
} else {
mockRemoveMemberFromExercises(programmingExercises);
}
} catch (GitLabApiException e) {
throw new GitLabException("Error while trying to set permission for user in GitLab: " + user, e);
}
}
}
use of de.tum.in.www1.artemis.service.exam 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