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