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