Search in sources :

Example 1 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class DatabaseUtilService method generateGradingScale.

public GradingScale generateGradingScale(int gradeStepCount, double[] intervals, boolean lowerBoundInclusivity, int firstPassingIndex, Optional<String[]> gradeNames) {
    if (gradeStepCount != intervals.length - 1 || firstPassingIndex >= gradeStepCount || firstPassingIndex < 0) {
        fail("Invalid grading scale parameters");
    }
    GradingScale gradingScale = new GradingScale();
    Set<GradeStep> gradeSteps = new HashSet<>();
    for (int i = 0; i < gradeStepCount; i++) {
        GradeStep gradeStep = new GradeStep();
        gradeStep.setLowerBoundPercentage(intervals[i]);
        gradeStep.setUpperBoundPercentage(intervals[i + 1]);
        gradeStep.setLowerBoundInclusive(i == 0 || lowerBoundInclusivity);
        gradeStep.setUpperBoundInclusive(i + 1 == gradeStepCount || !lowerBoundInclusivity);
        gradeStep.setIsPassingGrade(i >= firstPassingIndex);
        gradeStep.setGradeName(gradeNames.isPresent() ? gradeNames.get()[i] : "Step" + i);
        gradeStep.setGradingScale(gradingScale);
        gradeSteps.add(gradeStep);
    }
    gradingScale.setGradeSteps(gradeSteps);
    gradingScale.setGradeType(GradeType.GRADE);
    return gradingScale;
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Example 2 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleService method saveGradingScale.

/**
 * Saves a grading scale to the database if it is valid
 * - grading scale can't have both course and exam set
 * - other checks performed in {@link GradingScaleService#checkGradeStepValidity(Set)}
 *
 * @param gradingScale the grading scale to be saved
 * @return the saved grading scale
 */
public GradingScale saveGradingScale(GradingScale gradingScale) {
    if (gradingScale.getCourse() != null && gradingScale.getExam() != null) {
        throw new BadRequestAlertException("Grading scales can't belong both to a course and an exam", "gradingScale", "gradingScaleBelongsToCourseAndExam");
    }
    Set<GradeStep> gradeSteps = gradingScale.getGradeSteps();
    checkGradeStepValidity(gradeSteps);
    for (GradeStep gradeStep : gradeSteps) {
        gradeStep.setGradingScale(gradingScale);
    }
    gradingScale.setGradeSteps(gradeSteps);
    return gradingScaleRepository.save(gradingScale);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) GradeStep(de.tum.in.www1.artemis.domain.GradeStep)

Example 3 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForCourse.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForCourse() throws Exception {
    createGradeScale();
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.GRADE);
    assertThat(gradeStepsDTO.title).isEqualTo(course.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForExam.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForExam() throws Exception {
    exam.setPublishResultsDate(ZonedDateTime.now());
    examRepository.save(exam);
    GradeStep gradeStep1 = new GradeStep();
    GradeStep gradeStep2 = new GradeStep();
    gradeStep1.setGradeName("Name1");
    gradeStep2.setGradeName("Name2");
    gradeStep1.setLowerBoundPercentage(0);
    gradeStep1.setUpperBoundPercentage(60);
    gradeStep2.setUpperBoundInclusive(true);
    gradeStep2.setLowerBoundPercentage(60);
    gradeStep2.setUpperBoundPercentage(100);
    gradeStep1.setGradingScale(examGradingScale);
    gradeStep2.setGradingScale(examGradingScale);
    gradeSteps = Set.of(gradeStep1, gradeStep2);
    examGradingScale.setGradeSteps(gradeSteps);
    examGradingScale.setGradeType(GradeType.BONUS);
    gradingScaleRepository.save(examGradingScale);
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.BONUS);
    assertThat(gradeStepsDTO.title).isEqualTo(exam.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 5 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleIntegrationTest method testGetGradingScaleForCourse.

/**
 * Test get request for grading scale
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGetGradingScaleForCourse() throws Exception {
    courseGradingScale.setGradeSteps(Set.of());
    gradingScaleRepository.save(courseGradingScale);
    GradingScale foundGradingScale = request.get("/api/courses/" + course.getId() + "/grading-scale", HttpStatus.OK, GradingScale.class);
    assertThat(foundGradingScale).usingRecursiveComparison().ignoringFields("id", "course", "exam").isEqualTo(courseGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

GradingScale (de.tum.in.www1.artemis.domain.GradingScale)72 WithMockUser (org.springframework.security.test.context.support.WithMockUser)62 Test (org.junit.jupiter.api.Test)60 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)42 GradeStep (de.tum.in.www1.artemis.domain.GradeStep)38 Course (de.tum.in.www1.artemis.domain.Course)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)14 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)10 GradeStepsDTO (de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO)8 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 User (de.tum.in.www1.artemis.domain.User)4 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)4 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)4 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)4 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4