Search in sources :

Example 1 with GradingInstruction

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

the class FeedbackSelector method selectFeedback.

/**
 * Selects the feedback to suggest from the list of feedback then sets up the selected feedback for the given element and result
 *
 * @param modelElement the UML model element the Feedback will be suggested for
 * @param feedbackList the list of feedback to choose from
 * @param result the result the selected feedback will belong to
 * @return the feedback that is selected for suggestion
 */
public static Feedback selectFeedback(ModelElement modelElement, List<Feedback> feedbackList, Result result) {
    if (feedbackList == null || feedbackList.isEmpty()) {
        return null;
    }
    // counts the amount of feedback elements that have the same credits assigned, i.e. maps "credits -> amount" for every unique credit number
    Map<Double, Integer> creditCount = new HashMap<>();
    // collects the feedback texts of the feedback elements that have the same credits assigned, i.e. maps "credits -> set of feedback text" for every unique credit number
    Map<Double, Set<String>> creditFeedbackText = new HashMap<>();
    // collects associated grading instruction of the feedback that have the same credits assigned, i.e. maps "credits -> GradingInstruction" for every unique credit number
    Map<Double, GradingInstruction> creditGradingInstruction = new HashMap<>();
    for (Feedback existingFeedback : feedbackList) {
        double credits = existingFeedback.getCredits();
        creditCount.put(credits, creditCount.getOrDefault(credits, 0) + 1);
        if (existingFeedback.getText() != null) {
            Set<String> feedbackTextForCredits = creditFeedbackText.getOrDefault(credits, new HashSet<>());
            feedbackTextForCredits.add(existingFeedback.getText());
            creditFeedbackText.put(credits, feedbackTextForCredits);
        }
        if (existingFeedback.getGradingInstruction() != null) {
            creditGradingInstruction.put(credits, existingFeedback.getGradingInstruction());
        }
    }
    double maxCount = creditCount.values().stream().mapToInt(i -> i).max().orElse(0);
    double confidence = maxCount / feedbackList.size();
    double maxCountCredits = creditCount.entrySet().stream().filter(entry -> entry.getValue() == maxCount).map(Map.Entry::getKey).findFirst().orElse(0.0);
    Set<String> feedbackTextForMaxCountCredits = creditFeedbackText.getOrDefault(maxCountCredits, new HashSet<>());
    String text = feedbackTextForMaxCountCredits.stream().filter(Objects::nonNull).max(Comparator.comparingInt(String::length)).orElse("");
    GradingInstruction gradingInstruction = creditGradingInstruction.getOrDefault(maxCountCredits, new GradingInstruction());
    if (confidence < CompassConfiguration.ELEMENT_CONFIDENCE_THRESHOLD) {
        return null;
    }
    Feedback feedback = new Feedback();
    feedback.setCredits(roundCredits(maxCountCredits));
    feedback.setPositive(feedback.getCredits() >= 0);
    feedback.setReference(buildReferenceString(modelElement));
    feedback.setType(FeedbackType.AUTOMATIC);
    feedback.setResult(result);
    if (gradingInstruction.getId() != null) {
        feedback.setGradingInstruction(gradingInstruction);
    } else {
        feedback.setText(text);
    }
    return feedback;
}
Also used : BigDecimal(java.math.BigDecimal) Result(de.tum.in.www1.artemis.domain.Result) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) java.util(java.util) Feedback(de.tum.in.www1.artemis.domain.Feedback) GradingInstruction(de.tum.in.www1.artemis.domain.GradingInstruction) FeedbackType(de.tum.in.www1.artemis.domain.enumeration.FeedbackType) RoundingMode(java.math.RoundingMode) CompassConfiguration(de.tum.in.www1.artemis.service.compass.utils.CompassConfiguration) GradingInstruction(de.tum.in.www1.artemis.domain.GradingInstruction) Feedback(de.tum.in.www1.artemis.domain.Feedback)

Example 2 with GradingInstruction

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

the class ModelingExerciseIntegrationTest method testUpdateModelingExerciseInstructions_asInstructor.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testUpdateModelingExerciseInstructions_asInstructor() throws Exception {
    ModelingExercise modelingExercise = modelingExerciseUtilService.createModelingExercise(classExercise.getCourseViaExerciseGroupOrCourseMember().getId());
    gradingCriteria = database.addGradingInstructionsToExercise(modelingExercise);
    var currentInstructionsSize = modelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().size();
    var newInstruction = new GradingInstruction();
    newInstruction.setInstructionDescription("New Instruction");
    modelingExercise.getGradingCriteria().get(1).addStructuredGradingInstructions(newInstruction);
    ModelingExercise createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions()).hasSize(currentInstructionsSize + 1);
    modelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().get(0).setInstructionDescription("UPDATE");
    createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().get(0).getInstructionDescription()).isEqualTo("UPDATE");
    modelingExercise.getGradingCriteria().get(1).setStructuredGradingInstructions(null);
    createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria()).isNotEmpty();
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions()).isNullOrEmpty();
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with GradingInstruction

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

the class ModelingExerciseIntegrationTest method testImportModelingExercise_setGradingInstructionForCopiedFeedback.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testImportModelingExercise_setGradingInstructionForCopiedFeedback() throws Exception {
    var now = ZonedDateTime.now();
    Course course1 = database.addEmptyCourse();
    Course course2 = database.addEmptyCourse();
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course1);
    modelingExercise = modelingExerciseRepository.save(modelingExercise);
    List<GradingCriterion> gradingCriteria = database.addGradingInstructionsToExercise(modelingExercise);
    gradingCriterionRepository.saveAll(gradingCriteria);
    GradingInstruction gradingInstruction = gradingCriteria.get(0).getStructuredGradingInstructions().get(0);
    assertThat(gradingInstruction.getFeedback()).as("Test feedback should have student readable feedback").isNotEmpty();
    // Create example submission
    var exampleSubmission = database.generateExampleSubmission("model", modelingExercise, true);
    exampleSubmission = database.addExampleSubmission(exampleSubmission);
    database.addResultToSubmission(exampleSubmission.getSubmission(), AssessmentType.MANUAL);
    var submission = submissionRepository.findWithEagerResultAndFeedbackById(exampleSubmission.getSubmission().getId()).get();
    Feedback feedback = ModelFactory.generateFeedback().get(0);
    feedback.setGradingInstruction(gradingInstruction);
    database.addFeedbackToResult(feedback, Objects.requireNonNull(submission.getLatestResult()));
    modelingExercise.setCourse(course2);
    var importedModelingExercise = request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(modelingExerciseRepository.findById(importedModelingExercise.getId())).isPresent();
    var importedExampleSubmission = importedModelingExercise.getExampleSubmissions().stream().findFirst().get();
    GradingInstruction importedFeedbackGradingInstruction = importedExampleSubmission.getSubmission().getLatestResult().getFeedbacks().get(0).getGradingInstruction();
    assertThat(importedFeedbackGradingInstruction).isNotNull();
    // Copy and original should have the same data but not the same ids.
    assertThat(importedFeedbackGradingInstruction.getId()).isNotEqualTo(gradingInstruction.getId());
    // To avoid infinite recursion when serializing to JSON.
    assertThat(importedFeedbackGradingInstruction.getGradingCriterion()).isNull();
    assertThat(importedFeedbackGradingInstruction.getFeedback()).isEqualTo(gradingInstruction.getFeedback());
    assertThat(importedFeedbackGradingInstruction.getGradingScale()).isEqualTo(gradingInstruction.getGradingScale());
    assertThat(importedFeedbackGradingInstruction.getInstructionDescription()).isEqualTo(gradingInstruction.getInstructionDescription());
    assertThat(importedFeedbackGradingInstruction.getCredits()).isEqualTo(gradingInstruction.getCredits());
    assertThat(importedFeedbackGradingInstruction.getUsageCount()).isEqualTo(gradingInstruction.getUsageCount());
    var importedModelingExerciseFromDb = modelingExerciseRepository.findByIdWithExampleSubmissionsAndResults(importedModelingExercise.getId()).get();
    var importedFeedbackGradingInstructionFromDb = importedModelingExerciseFromDb.getExampleSubmissions().stream().findFirst().get().getSubmission().getLatestResult().getFeedbacks().get(0).getGradingInstruction();
    assertThat(importedFeedbackGradingInstructionFromDb.getGradingCriterion().getId()).isNotEqualTo(gradingInstruction.getGradingCriterion().getId());
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GradingInstruction

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

the class FeedbackSelector method selectFeedback.

/**
 * Selects the feedback to suggest from the list of feedback then sets up the selected feedback for the given element and result
 *
 * @param modelElement the UML model element the Feedback will be suggested for
 * @param feedbackList the list of feedback to choose from
 * @param result the result the selected feedback will belong to
 * @return the feedback that is selected for suggestion
 */
public static Feedback selectFeedback(ModelElement modelElement, List<Feedback> feedbackList, Result result) {
    if (feedbackList == null || feedbackList.isEmpty()) {
        return null;
    }
    // counts the amount of feedback elements that have the same credits assigned, i.e. maps "credits -> amount" for every unique credit number
    Map<Double, Integer> creditCount = new HashMap<>();
    // collects the feedback texts of the feedback elements that have the same credits assigned, i.e. maps "credits -> set of feedback text" for every unique credit number
    Map<Double, Set<String>> creditFeedbackText = new HashMap<>();
    // collects associated grading instruction of the feedback that have the same credits assigned, i.e. maps "credits -> GradingInstruction" for every unique credit number
    Map<Double, GradingInstruction> creditGradingInstruction = new HashMap<>();
    for (Feedback existingFeedback : feedbackList) {
        double credits = existingFeedback.getCredits();
        creditCount.put(credits, creditCount.getOrDefault(credits, 0) + 1);
        if (existingFeedback.getText() != null) {
            Set<String> feedbackTextForCredits = creditFeedbackText.getOrDefault(credits, new HashSet<>());
            feedbackTextForCredits.add(existingFeedback.getText());
            creditFeedbackText.put(credits, feedbackTextForCredits);
        }
        if (existingFeedback.getGradingInstruction() != null) {
            creditGradingInstruction.put(credits, existingFeedback.getGradingInstruction());
        }
    }
    double maxCount = creditCount.values().stream().mapToInt(i -> i).max().orElse(0);
    double confidence = maxCount / feedbackList.size();
    double maxCountCredits = creditCount.entrySet().stream().filter(entry -> entry.getValue() == maxCount).map(Map.Entry::getKey).findFirst().orElse(0.0);
    Set<String> feedbackTextForMaxCountCredits = creditFeedbackText.getOrDefault(maxCountCredits, new HashSet<>());
    String text = feedbackTextForMaxCountCredits.stream().filter(Objects::nonNull).max(Comparator.comparingInt(String::length)).orElse("");
    GradingInstruction gradingInstruction = creditGradingInstruction.getOrDefault(maxCountCredits, new GradingInstruction());
    if (confidence < CompassConfiguration.ELEMENT_CONFIDENCE_THRESHOLD) {
        return null;
    }
    Feedback feedback = new Feedback();
    feedback.setCredits(roundCredits(maxCountCredits));
    feedback.setPositive(feedback.getCredits() >= 0);
    feedback.setReference(buildReferenceString(modelElement));
    feedback.setType(FeedbackType.AUTOMATIC);
    feedback.setResult(result);
    if (gradingInstruction.getId() != null) {
        feedback.setGradingInstruction(gradingInstruction);
    } else {
        feedback.setText(text);
    }
    return feedback;
}
Also used : BigDecimal(java.math.BigDecimal) Result(de.tum.in.www1.artemis.domain.Result) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) java.util(java.util) Feedback(de.tum.in.www1.artemis.domain.Feedback) GradingInstruction(de.tum.in.www1.artemis.domain.GradingInstruction) FeedbackType(de.tum.in.www1.artemis.domain.enumeration.FeedbackType) RoundingMode(java.math.RoundingMode) CompassConfiguration(de.tum.in.www1.artemis.service.compass.utils.CompassConfiguration) GradingInstruction(de.tum.in.www1.artemis.domain.GradingInstruction) Feedback(de.tum.in.www1.artemis.domain.Feedback)

Example 5 with GradingInstruction

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

the class ModelingExerciseImportService method copySubmission.

/**
 * This helper function does a hard copy of the {@code originalSubmission} and stores the values in {@code newSubmission}.
 * To copy the submission results this function calls {@link ExerciseImportService#copyExampleResult(Result, Submission, Map)} respectively.
 *
 * @param originalSubmission  The original submission to be copied.
 * @param gradingInstructionCopyTracker  The mapping from original GradingInstruction Ids to new GradingInstruction instances.
 * @return The cloned submission
 */
Submission copySubmission(Submission originalSubmission, Map<Long, GradingInstruction> gradingInstructionCopyTracker) {
    ModelingSubmission newSubmission = new ModelingSubmission();
    if (originalSubmission != null) {
        log.debug("Copying the Submission to new ExampleSubmission: {}", newSubmission);
        newSubmission.setExampleSubmission(true);
        newSubmission.setSubmissionDate(originalSubmission.getSubmissionDate());
        newSubmission.setType(originalSubmission.getType());
        newSubmission.setParticipation(originalSubmission.getParticipation());
        newSubmission.setExplanationText(((ModelingSubmission) originalSubmission).getExplanationText());
        newSubmission.setModel(((ModelingSubmission) originalSubmission).getModel());
        newSubmission = submissionRepository.saveAndFlush(newSubmission);
        if (originalSubmission.getLatestResult() != null) {
            newSubmission.addResult(copyExampleResult(originalSubmission.getLatestResult(), newSubmission, gradingInstructionCopyTracker));
        }
        newSubmission = submissionRepository.saveAndFlush(newSubmission);
    }
    return newSubmission;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)

Aggregations

ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)8 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 NotNull (javax.validation.constraints.NotNull)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Feedback (de.tum.in.www1.artemis.domain.Feedback)2 GradingInstruction (de.tum.in.www1.artemis.domain.GradingInstruction)2 Result (de.tum.in.www1.artemis.domain.Result)2 FeedbackType (de.tum.in.www1.artemis.domain.enumeration.FeedbackType)2 ModelElement (de.tum.in.www1.artemis.domain.modeling.ModelElement)2 CompassConfiguration (de.tum.in.www1.artemis.service.compass.utils.CompassConfiguration)2 BigDecimal (java.math.BigDecimal)2 RoundingMode (java.math.RoundingMode)2 java.util (java.util)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2