use of de.tum.in.www1.artemis.service.AutomaticTextFeedbackService in project ArTEMiS by ls1intum.
the class TextAssessmentService method prepareSubmissionForAssessment.
/**
* Load entities from database needed for text assessment, set potential feedback impact count & compute
* Feedback suggestions (Athene):
* 1. Create or load the result
* 2. Set potential Feedback impact
* 3. Compute Feedback Suggestions
* 4. Load Text Blocks
* 5. Compute Fallback Text Blocks if needed
*
* @param textSubmission Text Submission to be assessed
* @param result for which we prepare the submission
*/
public void prepareSubmissionForAssessment(TextSubmission textSubmission, @Nullable Result result) {
final Participation participation = textSubmission.getParticipation();
final TextExercise exercise = (TextExercise) participation.getExercise();
final boolean computeFeedbackSuggestions = automaticTextFeedbackService.isPresent() && exercise.isAutomaticAssessmentEnabled();
if (result != null) {
// Load Feedback already created for this assessment
final List<Feedback> assessments = exercise.isAutomaticAssessmentEnabled() ? getAssessmentsForResultWithConflicts(result) : feedbackRepository.findByResult(result);
result.setFeedbacks(assessments);
if (assessments.isEmpty() && computeFeedbackSuggestions) {
automaticTextFeedbackService.get().suggestFeedback(result);
}
// make sure this is not a Hibernate Proxy
result.setSubmission(textSubmission);
} else {
// We are the first ones to open assess this submission, we want to lock it.
result = new Result();
result.setParticipation(participation);
resultService.createNewRatedManualResult(result, false);
result.setCompletionDate(null);
result = resultRepository.save(result);
result.setSubmission(textSubmission);
textSubmission.addResult(result);
submissionRepository.save(textSubmission);
// If enabled, we want to compute feedback suggestions using Athene.
if (computeFeedbackSuggestions) {
automaticTextFeedbackService.get().suggestFeedback(result);
}
}
// If we did not call AutomaticTextFeedbackService::suggestFeedback, we need to fetch them now.
if (!result.getFeedbacks().isEmpty() || !computeFeedbackSuggestions) {
final var textBlocks = textBlockService.findAllBySubmissionId(textSubmission.getId());
textSubmission.setBlocks(textBlocks);
}
// If we did not fetch blocks from the database before, we fall back to computing them based on syntax.
if (textSubmission.getBlocks() == null || !isInitialized(textSubmission.getBlocks()) || textSubmission.getBlocks().isEmpty()) {
textBlockService.computeTextBlocksForSubmissionBasedOnSyntax(textSubmission);
}
// Remove participation after storing in database because submission already has the participation set
result.setParticipation(null);
// Set each block's impact on other submissions for the current 'textSubmission'
if (computeFeedbackSuggestions) {
textBlockService.setNumberOfAffectedSubmissionsPerBlock(result);
result.setSubmission(textSubmission);
}
}
use of de.tum.in.www1.artemis.service.AutomaticTextFeedbackService in project Artemis by ls1intum.
the class TextAssessmentService method prepareSubmissionForAssessment.
/**
* Load entities from database needed for text assessment, set potential feedback impact count & compute
* Feedback suggestions (Athene):
* 1. Create or load the result
* 2. Set potential Feedback impact
* 3. Compute Feedback Suggestions
* 4. Load Text Blocks
* 5. Compute Fallback Text Blocks if needed
*
* @param textSubmission Text Submission to be assessed
* @param result for which we prepare the submission
*/
public void prepareSubmissionForAssessment(TextSubmission textSubmission, @Nullable Result result) {
final Participation participation = textSubmission.getParticipation();
final TextExercise exercise = (TextExercise) participation.getExercise();
final boolean computeFeedbackSuggestions = automaticTextFeedbackService.isPresent() && exercise.isAutomaticAssessmentEnabled();
if (result != null) {
// Load Feedback already created for this assessment
final List<Feedback> assessments = exercise.isAutomaticAssessmentEnabled() ? getAssessmentsForResultWithConflicts(result) : feedbackRepository.findByResult(result);
result.setFeedbacks(assessments);
if (assessments.isEmpty() && computeFeedbackSuggestions) {
automaticTextFeedbackService.get().suggestFeedback(result);
}
// make sure this is not a Hibernate Proxy
result.setSubmission(textSubmission);
} else {
// We are the first ones to open assess this submission, we want to lock it.
result = new Result();
result.setParticipation(participation);
resultService.createNewRatedManualResult(result, false);
result.setCompletionDate(null);
result = resultRepository.save(result);
result.setSubmission(textSubmission);
textSubmission.addResult(result);
submissionRepository.save(textSubmission);
// If enabled, we want to compute feedback suggestions using Athene.
if (computeFeedbackSuggestions) {
automaticTextFeedbackService.get().suggestFeedback(result);
}
}
// If we did not call AutomaticTextFeedbackService::suggestFeedback, we need to fetch them now.
if (!result.getFeedbacks().isEmpty() || !computeFeedbackSuggestions) {
final var textBlocks = textBlockService.findAllBySubmissionId(textSubmission.getId());
textSubmission.setBlocks(textBlocks);
}
// If we did not fetch blocks from the database before, we fall back to computing them based on syntax.
if (textSubmission.getBlocks() == null || !isInitialized(textSubmission.getBlocks()) || textSubmission.getBlocks().isEmpty()) {
textBlockService.computeTextBlocksForSubmissionBasedOnSyntax(textSubmission);
}
// Remove participation after storing in database because submission already has the participation set
result.setParticipation(null);
// Set each block's impact on other submissions for the current 'textSubmission'
if (computeFeedbackSuggestions) {
textBlockService.setNumberOfAffectedSubmissionsPerBlock(result);
result.setSubmission(textSubmission);
}
}
Aggregations