Search in sources :

Example 1 with IncludedInOverallScore

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

the class ExamService method validateForStudentExamGeneration.

/**
 * Validates exercise settings.
 *
 * @param exam exam which is validated
 * @throws BadRequestAlertException an exception if the exam is not configured correctly
 */
public void validateForStudentExamGeneration(Exam exam) throws BadRequestAlertException {
    List<ExerciseGroup> exerciseGroups = exam.getExerciseGroups();
    long numberOfExercises = exam.getNumberOfExercisesInExam() != null ? exam.getNumberOfExercisesInExam() : 0;
    long numberOfOptionalExercises = numberOfExercises - exerciseGroups.stream().filter(ExerciseGroup::getIsMandatory).count();
    // Ensure that all exercise groups have at least one exercise
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        if (exerciseGroup.getExercises().isEmpty()) {
            throw new BadRequestAlertException("All exercise groups must have at least one exercise", "Exam", "artemisApp.exam.validation.atLeastOneExercisePerExerciseGroup");
        }
    }
    // Check that numberOfExercisesInExam is set
    if (exam.getNumberOfExercisesInExam() == null) {
        throw new BadRequestAlertException("The number of exercises in the exam is not set.", "Exam", "artemisApp.exam.validation.numberOfExercisesInExamNotSet");
    }
    // Check that there are enough exercise groups
    if (exam.getExerciseGroups().size() < exam.getNumberOfExercisesInExam()) {
        throw new BadRequestAlertException("The number of exercise groups is too small", "Exam", "artemisApp.exam.validation.tooFewExerciseGroups");
    }
    // Check that there are not too much mandatory exercise groups
    if (numberOfOptionalExercises < 0) {
        throw new BadRequestAlertException("The number of mandatory exercise groups is too large", "Exam", "artemisApp.exam.validation.tooManyMandatoryExerciseGroups");
    }
    // Ensure that all exercises in an exercise group have the same meaning for the exam score calculation
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Set<IncludedInOverallScore> meaningsForScoreCalculation = exerciseGroup.getExercises().stream().map(Exercise::getIncludedInOverallScore).collect(Collectors.toSet());
        if (meaningsForScoreCalculation.size() > 1) {
            throw new BadRequestAlertException("All exercises in an exercise group must have the same meaning for the exam score", "Exam", "artemisApp.exam.validation.allExercisesInExerciseGroupOfSameIncludedType");
        }
    }
    // Check that the exam max points is set
    if (exam.getMaxPoints() == 0) {
        throw new BadRequestAlertException("The exam max points can not be 0.", "Exam", "artemisApp.exam.validation.maxPointsNotSet");
    }
    // Ensure that all exercises in an exercise group have the same amount of max points and max bonus points
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Set<Double> allMaxPoints = exerciseGroup.getExercises().stream().map(Exercise::getMaxPoints).collect(Collectors.toSet());
        Set<Double> allBonusPoints = exerciseGroup.getExercises().stream().map(Exercise::getBonusPoints).collect(Collectors.toSet());
        if (allMaxPoints.size() > 1 || allBonusPoints.size() > 1) {
            throw new BadRequestAlertException("All exercises in an exercise group need to give the same amount of points", "Exam", "artemisApp.exam.validation.allExercisesInExerciseGroupGiveSameNumberOfPoints");
        }
    }
    // Ensure that the sum of all max points of mandatory exercise groups is not bigger than the max points set in the exam
    // At this point we are already sure that each exercise group has at least one exercise, all exercises in the group have the same no of points
    // and all are of the same calculation type, therefore we can just use any as representation for the group here
    Double pointsReachableByMandatoryExercises = 0.0;
    Set<ExerciseGroup> mandatoryExerciseGroups = exam.getExerciseGroups().stream().filter(ExerciseGroup::getIsMandatory).collect(Collectors.toSet());
    for (ExerciseGroup exerciseGroup : mandatoryExerciseGroups) {
        Exercise groupRepresentativeExercise = exerciseGroup.getExercises().stream().findAny().get();
        if (groupRepresentativeExercise.getIncludedInOverallScore().equals(IncludedInOverallScore.INCLUDED_COMPLETELY)) {
            pointsReachableByMandatoryExercises += groupRepresentativeExercise.getMaxPoints();
        }
    }
    if (pointsReachableByMandatoryExercises > exam.getMaxPoints()) {
        throw new BadRequestAlertException("Check that you set the exam max points correctly! The max points a student can earn in the mandatory exercise groups is too big", "Exam", "artemisApp.exam.validation.tooManyMaxPoints");
    }
    // Ensure that the sum of all max points of all exercise groups is at least as big as the max points set in the exam
    Double pointsReachable = 0.0;
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Exercise groupRepresentativeExercise = exerciseGroup.getExercises().stream().findAny().get();
        if (groupRepresentativeExercise.getIncludedInOverallScore().equals(IncludedInOverallScore.INCLUDED_COMPLETELY)) {
            pointsReachable += groupRepresentativeExercise.getMaxPoints();
        }
    }
    if (pointsReachable < exam.getMaxPoints()) {
        throw new BadRequestAlertException("Check that you set the exam max points correctly! The max points a student can earn in the exercise groups is too low", "Exam", "artemisApp.exam.validation.tooFewMaxPoints");
    }
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup)

Example 2 with IncludedInOverallScore

use of de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore in project Artemis by ls1intum.

the class ExamServiceTest method addNewTextExerciseToExerciseGroup.

private TextExercise addNewTextExerciseToExerciseGroup(ExerciseGroup exerciseGroup, Long id, Double maxPoints, Double maxBonusPoints, IncludedInOverallScore includedInOverallScore) {
    TextExercise includedTextExercise = new TextExercise();
    includedTextExercise.setId(id);
    includedTextExercise.setMaxPoints(maxPoints);
    includedTextExercise.setBonusPoints(maxBonusPoints);
    includedTextExercise.setIncludedInOverallScore(includedInOverallScore);
    includedTextExercise.setExerciseGroup(exerciseGroup);
    return includedTextExercise;
}
Also used : TextExercise(de.tum.in.www1.artemis.domain.TextExercise)

Example 3 with IncludedInOverallScore

use of de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore in project Artemis by ls1intum.

the class ExamService method validateForStudentExamGeneration.

/**
 * Validates exercise settings.
 *
 * @param exam exam which is validated
 * @throws BadRequestAlertException an exception if the exam is not configured correctly
 */
public void validateForStudentExamGeneration(Exam exam) throws BadRequestAlertException {
    List<ExerciseGroup> exerciseGroups = exam.getExerciseGroups();
    long numberOfExercises = exam.getNumberOfExercisesInExam() != null ? exam.getNumberOfExercisesInExam() : 0;
    long numberOfOptionalExercises = numberOfExercises - exerciseGroups.stream().filter(ExerciseGroup::getIsMandatory).count();
    // Ensure that all exercise groups have at least one exercise
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        if (exerciseGroup.getExercises().isEmpty()) {
            throw new BadRequestAlertException("All exercise groups must have at least one exercise", "Exam", "artemisApp.exam.validation.atLeastOneExercisePerExerciseGroup");
        }
    }
    // Check that numberOfExercisesInExam is set
    if (exam.getNumberOfExercisesInExam() == null) {
        throw new BadRequestAlertException("The number of exercises in the exam is not set.", "Exam", "artemisApp.exam.validation.numberOfExercisesInExamNotSet");
    }
    // Check that there are enough exercise groups
    if (exam.getExerciseGroups().size() < exam.getNumberOfExercisesInExam()) {
        throw new BadRequestAlertException("The number of exercise groups is too small", "Exam", "artemisApp.exam.validation.tooFewExerciseGroups");
    }
    // Check that there are not too much mandatory exercise groups
    if (numberOfOptionalExercises < 0) {
        throw new BadRequestAlertException("The number of mandatory exercise groups is too large", "Exam", "artemisApp.exam.validation.tooManyMandatoryExerciseGroups");
    }
    // Ensure that all exercises in an exercise group have the same meaning for the exam score calculation
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Set<IncludedInOverallScore> meaningsForScoreCalculation = exerciseGroup.getExercises().stream().map(Exercise::getIncludedInOverallScore).collect(Collectors.toSet());
        if (meaningsForScoreCalculation.size() > 1) {
            throw new BadRequestAlertException("All exercises in an exercise group must have the same meaning for the exam score", "Exam", "artemisApp.exam.validation.allExercisesInExerciseGroupOfSameIncludedType");
        }
    }
    // Check that the exam max points is set
    if (exam.getMaxPoints() == 0) {
        throw new BadRequestAlertException("The exam max points can not be 0.", "Exam", "artemisApp.exam.validation.maxPointsNotSet");
    }
    // Ensure that all exercises in an exercise group have the same amount of max points and max bonus points
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Set<Double> allMaxPoints = exerciseGroup.getExercises().stream().map(Exercise::getMaxPoints).collect(Collectors.toSet());
        Set<Double> allBonusPoints = exerciseGroup.getExercises().stream().map(Exercise::getBonusPoints).collect(Collectors.toSet());
        if (allMaxPoints.size() > 1 || allBonusPoints.size() > 1) {
            throw new BadRequestAlertException("All exercises in an exercise group need to give the same amount of points", "Exam", "artemisApp.exam.validation.allExercisesInExerciseGroupGiveSameNumberOfPoints");
        }
    }
    // Ensure that the sum of all max points of mandatory exercise groups is not bigger than the max points set in the exam
    // At this point we are already sure that each exercise group has at least one exercise, all exercises in the group have the same no of points
    // and all are of the same calculation type, therefore we can just use any as representation for the group here
    Double pointsReachableByMandatoryExercises = 0.0;
    Set<ExerciseGroup> mandatoryExerciseGroups = exam.getExerciseGroups().stream().filter(ExerciseGroup::getIsMandatory).collect(Collectors.toSet());
    for (ExerciseGroup exerciseGroup : mandatoryExerciseGroups) {
        Exercise groupRepresentativeExercise = exerciseGroup.getExercises().stream().findAny().get();
        if (groupRepresentativeExercise.getIncludedInOverallScore().equals(IncludedInOverallScore.INCLUDED_COMPLETELY)) {
            pointsReachableByMandatoryExercises += groupRepresentativeExercise.getMaxPoints();
        }
    }
    if (pointsReachableByMandatoryExercises > exam.getMaxPoints()) {
        throw new BadRequestAlertException("Check that you set the exam max points correctly! The max points a student can earn in the mandatory exercise groups is too big", "Exam", "artemisApp.exam.validation.tooManyMaxPoints");
    }
    // Ensure that the sum of all max points of all exercise groups is at least as big as the max points set in the exam
    Double pointsReachable = 0.0;
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        Exercise groupRepresentativeExercise = exerciseGroup.getExercises().stream().findAny().get();
        if (groupRepresentativeExercise.getIncludedInOverallScore().equals(IncludedInOverallScore.INCLUDED_COMPLETELY)) {
            pointsReachable += groupRepresentativeExercise.getMaxPoints();
        }
    }
    if (pointsReachable < exam.getMaxPoints()) {
        throw new BadRequestAlertException("Check that you set the exam max points correctly! The max points a student can earn in the exercise groups is too low", "Exam", "artemisApp.exam.validation.tooFewMaxPoints");
    }
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup)

Example 4 with IncludedInOverallScore

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

the class ExamServiceTest method addNewTextExerciseToExerciseGroup.

private TextExercise addNewTextExerciseToExerciseGroup(ExerciseGroup exerciseGroup, Long id, Double maxPoints, Double maxBonusPoints, IncludedInOverallScore includedInOverallScore) {
    TextExercise includedTextExercise = new TextExercise();
    includedTextExercise.setId(id);
    includedTextExercise.setMaxPoints(maxPoints);
    includedTextExercise.setBonusPoints(maxBonusPoints);
    includedTextExercise.setIncludedInOverallScore(includedInOverallScore);
    includedTextExercise.setExerciseGroup(exerciseGroup);
    return includedTextExercise;
}
Also used : TextExercise(de.tum.in.www1.artemis.domain.TextExercise)

Aggregations

TextExercise (de.tum.in.www1.artemis.domain.TextExercise)2 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)2 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)2 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)2 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)2