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