Search in sources :

Example 16 with GradingScale

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

the class GradingScaleResource method updateGradingScaleForExam.

/**
 * PUT /courses/{courseId}/exams/{examId}/grading-scale : Update grading scale for exam
 *
 * @param courseId the course to which the exam belongs
 * @param examId the exam to which the grading scale belongs
 * @param gradingScale the grading scale which will be updated
 * @return ResponseEntity with status 200 (Ok) with body the newly updated grading scale if it is correctly formatted and 400 (Bad request) otherwise
 */
@PutMapping("/courses/{courseId}/exams/{examId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<GradingScale> updateGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestBody GradingScale gradingScale) {
    log.debug("REST request to update a grading scale for exam: {}", examId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    Exam exam = examRepository.findByIdElseThrow(examId);
    GradingScale oldGradingScale = gradingScaleRepository.findByExamIdOrElseThrow(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    gradingScale.setId(oldGradingScale.getId());
    if (gradingScale.getExam().getMaxPoints() != exam.getMaxPoints()) {
        exam.setMaxPoints(gradingScale.getExam().getMaxPoints());
        examRepository.save(exam);
    }
    gradingScale.setExam(exam);
    GradingScale savedGradingScale = gradingScaleService.saveGradingScale(gradingScale);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, "")).body(savedGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with GradingScale

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

the class GradingScaleServiceTest method testSaveGradingScaleInvalidGradeStepsNoGradeName.

/**
 * Test saving of an invalid grading scale - missing grade names
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSaveGradingScaleInvalidGradeStepsNoGradeName() {
    createCustomGradeStep("", 70, 95);
    BadRequestAlertException exception = assertThrows(BadRequestAlertException.class, () -> gradingScaleService.saveGradingScale(gradingScale));
    assertThat(exception.getEntityName()).isEqualTo("gradeStep");
    assertThat(exception.getErrorKey()).isEqualTo("invalidGradeStepFormat");
    assertThat(exception.getMessage()).isEqualTo("Not all grade steps are following the correct format.");
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 18 with GradingScale

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

the class GradingScaleServiceTest method testMatchPercentageToGradeStepWithBonusPoints.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(doubles = { 125, 160 })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testMatchPercentageToGradeStepWithBonusPoints(double bonusPercentage) {
    GradeStep expectedGradeStep = createCustomGradeStep("🐧", 100, 150);
    gradingScaleRepository.save(gradingScale);
    Long gradingScaleId = gradingScaleRepository.findAll().get(0).getId();
    GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(bonusPercentage, gradingScaleId);
    assertThat(gradeStep).usingRecursiveComparison().ignoringFields("gradingScale", "id").isEqualTo(expectedGradeStep);
}
Also used : GradeStep(de.tum.in.www1.artemis.domain.GradeStep) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with GradingScale

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

the class GradingScaleServiceTest method createCustomGradeStep.

private GradeStep createCustomGradeStep(String gradeName, double lowerBound, double upperBound) {
    GradeStep gradeStep = new GradeStep();
    gradeStep.setIsPassingGrade(true);
    gradeStep.setGradeName(gradeName);
    gradeStep.setLowerBoundPercentage(lowerBound);
    gradeStep.setUpperBoundPercentage(upperBound);
    gradeStep.setGradingScale(gradingScale);
    gradingScale.setGradeSteps(Set.of(gradeStep));
    gradingScale.setCourse(course);
    return gradeStep;
}
Also used : GradeStep(de.tum.in.www1.artemis.domain.GradeStep)

Example 20 with GradingScale

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

the class GradingScaleServiceTest method testGradeStepMatchingForRoundingErrors5.

/**
 * Test grade step matching for rounding errors
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGradeStepMatchingForRoundingErrors5() {
    double boundary = 33 + 1d / 3d;
    GradingScale gradingScale = database.generateGradingScale(2, new double[] { 0, boundary, 100 }, true, 1, Optional.empty());
    gradingScaleRepository.save(gradingScale);
    Long id = gradingScaleRepository.findAll().get(0).getId();
    GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(33.33, id);
    assertThat(gradeStep.getGradeName()).isEqualTo("Step1");
    gradeStep = gradingScaleRepository.matchPercentageToGradeStep(33, id);
    assertThat(gradeStep.getGradeName()).isEqualTo("Step0");
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) GradeStep(de.tum.in.www1.artemis.domain.GradeStep) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

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