Search in sources :

Example 6 with de.tum.in.www1.artemis.service.exam

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

Example 7 with de.tum.in.www1.artemis.service.exam

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);
}
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) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with de.tum.in.www1.artemis.service.exam

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

Example 9 with de.tum.in.www1.artemis.service.exam

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);
        }
    }
}
Also used : GitLabException(de.tum.in.www1.artemis.service.connectors.gitlab.GitLabException) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 10 with de.tum.in.www1.artemis.service.exam

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

ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)8 ScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ScoreDTO)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Course (de.tum.in.www1.artemis.domain.Course)6 Exam (de.tum.in.www1.artemis.domain.exam.Exam)6 Exercise (de.tum.in.www1.artemis.domain.Exercise)4 IncludedInOverallScore (de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore)4 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)4 CourseRepository (de.tum.in.www1.artemis.repository.CourseRepository)4 ExamRepository (de.tum.in.www1.artemis.repository.ExamRepository)4 Role (de.tum.in.www1.artemis.security.Role)4 AuthorizationCheckService (de.tum.in.www1.artemis.service.AuthorizationCheckService)4 ParticipantScoreService (de.tum.in.www1.artemis.service.ParticipantScoreService)4 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Collectors.toSet (java.util.stream.Collectors.toSet)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4