Search in sources :

Example 6 with ModelElement

use of de.tum.in.www1.artemis.domain.modeling.ModelElement 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 7 with ModelElement

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

the class AssessmentKnowledgeIntegrationTest method testSetModelAssessmentKnowledgeToModelElements.

/**
 * Tests that a ModelAssessmentKnowledge is correctly set to model elements
 * based on the ModelAssessmentKnowledge of the respective exercise
 *
 * @throws Exception might be thrown from Network Call to Artemis API
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSetModelAssessmentKnowledgeToModelElements() throws Exception {
    ModelingSubmission submission1 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json"), true);
    submission1.setId(1L);
    ModelingSubmission submission2 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission2.setId(2L);
    ModelingSubmission submission3 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission3.setId(3L);
    ModelingSubmission submission4 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission4.setId(4L);
    Course course = database.addEmptyCourse();
    ModelingExercise exercise1 = modelingExerciseUtilService.createModelingExercise(course.getId());
    ModelingExercise exercise2 = modelingExerciseUtilService.createModelingExercise(course.getId());
    modelAssessmentKnowledgeService = new ModelAssessmentKnowledgeService(modelAssessmentKnowledgeRepository, modelingExerciseRepository);
    exercise1.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    exercise2.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    ModelClusterFactory modelClusterFactory = new ModelClusterFactory();
    List<ModelCluster> modelClusters1 = modelClusterFactory.buildClusters(List.of(submission1, submission2), exercise1);
    List<ModelCluster> modelClusters2 = modelClusterFactory.buildClusters(List.of(submission3, submission4), exercise2);
    ModelCluster modelCluster = modelClusters1.get(0);
    for (ModelElement element : modelCluster.getModelElements()) {
        assertThat(element.getKnowledge().getId()).isEqualTo(exercise1.getKnowledge().getId());
    }
    modelCluster = modelClusters2.get(0);
    for (ModelElement element : modelCluster.getModelElements()) {
        assertThat(element.getKnowledge().getId()).isEqualTo(exercise2.getKnowledge().getId());
    }
    assertThat(exercise1.getKnowledge().getId()).isNotEqualTo(exercise2.getKnowledge().getId());
}
Also used : ModelClusterFactory(de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelAssessmentKnowledgeService(de.tum.in.www1.artemis.service.ModelAssessmentKnowledgeService) ModelCluster(de.tum.in.www1.artemis.domain.modeling.ModelCluster) Course(de.tum.in.www1.artemis.domain.Course) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 8 with ModelElement

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

the class FeedbackSelectorTest method testConfidenceThreshold.

@Test
public void testConfidenceThreshold() {
    Feedback feedback1 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2121");
    Feedback feedback2 = new Feedback().credits(20.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2122").text("wrong text");
    Result result = new Result();
    ModelElement modelElement = new ModelElement();
    modelElement.setModelElementType("Class");
    modelElement.setModelElementId("6aba5764-d102-4740-9675-b2bd0a4f2126");
    Feedback selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback2), result);
    assertThat(selectedFeedback).as("feedback was selected").isNotNull();
    assertThat(selectedFeedback.getReference()).as("feedback is assigned to the element").isEqualTo("Class:6aba5764-d102-4740-9675-b2bd0a4f2126");
    assertThat(selectedFeedback.getCredits()).as("credits of element are correct").isEqualTo(20);
    assertThat(selectedFeedback.getText()).as("feedback text of element is correct").isEqualTo("wrong text");
    feedback1 = feedback1.text("long feedback text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback3 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2123").text("short text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback4 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2124").text("very long feedback text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3, feedback4), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback5 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2125").text("medium text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3, feedback4, feedback5), result);
    assertThat(selectedFeedback).as("feedback was selected").isNotNull();
    assertThat(selectedFeedback.getReference()).as("feedback is assigned to the element").isEqualTo("Class:6aba5764-d102-4740-9675-b2bd0a4f2126");
    assertThat(selectedFeedback.getCredits()).as("credits of element are correct").isEqualTo(1);
    assertThat(selectedFeedback.getText()).as("feedback text of element is correct").isEqualTo("very long feedback text");
}
Also used : ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) Feedback(de.tum.in.www1.artemis.domain.Feedback) Result(de.tum.in.www1.artemis.domain.Result) Test(org.junit.jupiter.api.Test)

Example 9 with ModelElement

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

the class ModelingSubmissionService method setNumberOfAffectedSubmissionsPerElement.

/**
 * Sets number of potential automatic Feedback's for each model element belonging to the `Result`'s submission.
 * This number determines how many other submissions would be affected if the user were to submit a certain element feedback.
 * For each ModelElement of the submission, this method finds how many other ModelElements exist in the same cluster.
 * This number is represented with the `numberOfAffectedSubmissions` field which is set here for each
 * ModelElement of this submission
 *
 * @param submission Result for the Submission acting as a reference for the modeling submission to be searched.
 */
public void setNumberOfAffectedSubmissionsPerElement(@NotNull ModelingSubmission submission) {
    List<ModelElementRepository.ModelElementCount> elementCounts = modelElementRepository.countOtherElementsInSameClusterForSubmissionId(submission.getId());
    submission.setSimilarElements(elementCounts.stream().map(modelElementCount -> {
        SimilarElementCount similarElementCount = new SimilarElementCount();
        similarElementCount.setElementId(modelElementCount.getElementId());
        similarElementCount.setNumberOfOtherElements(modelElementCount.getNumberOfOtherElements());
        return similarElementCount;
    }).collect(Collectors.toSet()));
}
Also used : SimilarElementCount(de.tum.in.www1.artemis.domain.modeling.SimilarElementCount)

Example 10 with ModelElement

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

the class FeedbackSelectorTest method testConfidenceThreshold.

@Test
public void testConfidenceThreshold() {
    Feedback feedback1 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2121");
    Feedback feedback2 = new Feedback().credits(20.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2122").text("wrong text");
    Result result = new Result();
    ModelElement modelElement = new ModelElement();
    modelElement.setModelElementType("Class");
    modelElement.setModelElementId("6aba5764-d102-4740-9675-b2bd0a4f2126");
    Feedback selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback2), result);
    assertThat(selectedFeedback).as("feedback was selected").isNotNull();
    assertThat(selectedFeedback.getReference()).as("feedback is assigned to the element").isEqualTo("Class:6aba5764-d102-4740-9675-b2bd0a4f2126");
    assertThat(selectedFeedback.getCredits()).as("credits of element are correct").isEqualTo(20);
    assertThat(selectedFeedback.getText()).as("feedback text of element is correct").isEqualTo("wrong text");
    feedback1 = feedback1.text("long feedback text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback3 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2123").text("short text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback4 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2124").text("very long feedback text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3, feedback4), result);
    assertThat(selectedFeedback).as("feedback not selected").isNull();
    Feedback feedback5 = new Feedback().credits(1.0).reference("Class:6aba5764-d102-4740-9675-b2bd0a4f2125").text("medium text");
    selectedFeedback = FeedbackSelector.selectFeedback(modelElement, List.of(feedback1, feedback2, feedback3, feedback4, feedback5), result);
    assertThat(selectedFeedback).as("feedback was selected").isNotNull();
    assertThat(selectedFeedback.getReference()).as("feedback is assigned to the element").isEqualTo("Class:6aba5764-d102-4740-9675-b2bd0a4f2126");
    assertThat(selectedFeedback.getCredits()).as("credits of element are correct").isEqualTo(1);
    assertThat(selectedFeedback.getText()).as("feedback text of element is correct").isEqualTo("very long feedback text");
}
Also used : ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) Feedback(de.tum.in.www1.artemis.domain.Feedback) Result(de.tum.in.www1.artemis.domain.Result) Test(org.junit.jupiter.api.Test)

Aggregations

ModelElement (de.tum.in.www1.artemis.domain.modeling.ModelElement)12 Feedback (de.tum.in.www1.artemis.domain.Feedback)8 Result (de.tum.in.www1.artemis.domain.Result)8 Test (org.junit.jupiter.api.Test)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)6 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)6 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)6 ModelClusterFactory (de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory)4 java.util (java.util)4 Course (de.tum.in.www1.artemis.domain.Course)2 GradingInstruction (de.tum.in.www1.artemis.domain.GradingInstruction)2 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)2 FeedbackType (de.tum.in.www1.artemis.domain.enumeration.FeedbackType)2 SimilarElementCount (de.tum.in.www1.artemis.domain.modeling.SimilarElementCount)2 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)2 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)2 ModelAssessmentKnowledgeService (de.tum.in.www1.artemis.service.ModelAssessmentKnowledgeService)2 FeedbackSelector (de.tum.in.www1.artemis.service.compass.controller.FeedbackSelector)2 UMLElement (de.tum.in.www1.artemis.service.compass.umlmodel.UMLElement)2 CompassConfiguration (de.tum.in.www1.artemis.service.compass.utils.CompassConfiguration)2