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