Search in sources :

Example 1 with GradeStep

use of de.tum.in.www1.artemis.domain.GradeStep 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 GradeStep

use of de.tum.in.www1.artemis.domain.GradeStep 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 GradeStep

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

the class GradeStepIntegrationTest method testGetGradeStepByPercentageForExam.

/**
 * Test get request for a single grade by grade percentage
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetGradeStepByPercentageForExam() throws Exception {
    GradeStep gradeStep = new GradeStep();
    gradeStep.setGradeName("Test grade");
    gradeStep.setLowerBoundPercentage(0);
    gradeStep.setUpperBoundPercentage(40);
    gradeStep.setIsPassingGrade(false);
    gradeStep.setGradingScale(examGradingScale);
    gradeSteps = Set.of(gradeStep);
    examGradingScale.setGradeSteps(gradeSteps);
    examGradingScale.setGradeType(GradeType.BONUS);
    gradingScaleRepository.save(examGradingScale);
    exam.setPublishResultsDate(ZonedDateTime.now());
    examRepository.save(exam);
    GradeDTO foundGrade = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/match-grade-step?gradePercentage=35", HttpStatus.OK, GradeDTO.class);
    assertThat(foundGrade.gradeName).isEqualTo("Test grade");
    assertThat(foundGrade.gradeType).isEqualTo(GradeType.BONUS);
    assertThat(foundGrade.isPassingGrade).isFalse();
}
Also used : GradeDTO(de.tum.in.www1.artemis.web.rest.dto.GradeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with GradeStep

use of de.tum.in.www1.artemis.domain.GradeStep 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 GradeStep

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

the class GradingScaleIntegrationTest method testSaveGradingScaleForCourse.

/**
 * Test post request for grading scale
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSaveGradingScaleForCourse() throws Exception {
    gradeSteps = database.generateGradeStepSet(courseGradingScale, true);
    courseGradingScale.setGradeSteps(gradeSteps);
    GradingScale savedGradingScale = request.postWithResponseBody("/api/courses/" + course.getId() + "/grading-scale", courseGradingScale, GradingScale.class, HttpStatus.CREATED);
    assertThat(savedGradingScale.getGradeSteps()).hasSameSizeAs(courseGradingScale.getGradeSteps());
    assertThat(savedGradingScale.getGradeSteps()).allMatch(gradeStep -> isGradeStepInSet(courseGradingScale.getGradeSteps(), gradeStep));
    assertThat(savedGradingScale).usingRecursiveComparison().ignoringFields("id", "exam", "course", "gradeSteps").ignoringCollectionOrder().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

WithMockUser (org.springframework.security.test.context.support.WithMockUser)52 Test (org.junit.jupiter.api.Test)48 GradeStep (de.tum.in.www1.artemis.domain.GradeStep)38 GradingScale (de.tum.in.www1.artemis.domain.GradingScale)38 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)38 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)34 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)12 Course (de.tum.in.www1.artemis.domain.Course)8 GradeDTO (de.tum.in.www1.artemis.web.rest.dto.GradeDTO)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Exam (de.tum.in.www1.artemis.domain.exam.Exam)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Constants (de.tum.in.www1.artemis.config.Constants)2 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2 User (de.tum.in.www1.artemis.domain.User)2 de.tum.in.www1.artemis.domain.enumeration (de.tum.in.www1.artemis.domain.enumeration)2 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)2 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)2 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)2