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