use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionResultSimulationService method createSubmission.
/**
* This method creates a new submission for the provided user
* @param exerciseId the exerciseId of the exercise for which a submission should be created
* This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
* @return the newly created and stored submission
*/
public ProgrammingSubmission createSubmission(Long exerciseId) {
User user = userRepository.getUserWithGroupsAndAuthorities();
Participant participant = user;
ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation;
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
Optional<StudentParticipation> optionalStudentParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(programmingExercise, user.getLogin());
if (optionalStudentParticipation.isEmpty()) {
programmingExerciseStudentParticipation = createParticipation(programmingExercise, participant, user);
} else {
programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) optionalStudentParticipation.get();
}
ProgrammingSubmission programmingSubmission = new ProgrammingSubmission();
programmingSubmission.setCommitHash(VCSSimulationUtils.simulateCommitHash());
programmingSubmission.setSubmitted(true);
programmingSubmission.setSubmissionDate(ZonedDateTime.now());
programmingSubmission.setType(SubmissionType.MANUAL);
programmingExerciseStudentParticipation.addSubmission(programmingSubmission);
programmingSubmissionRepository.save(programmingSubmission);
return programmingSubmission;
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ExamQuizService method evaluateSubmissions.
/**
* // @formatter:off
* Evaluate the given quiz exercise by performing the following actions for each participation:
* 1. Get the submission for each participation (there should be only one as in exam mode, the submission gets created upfront and will be updated)
* - If no submission is found, print a warning and continue as we cannot evaluate that submission
* - If more than one submission is found, select one of them
* 2. mark submission and participation as evaluated
* 3. Create a new result for the selected submission and calculate scores
* 4. Save the updated submission & participation and the newly created result
*
* After processing all participations, the created results will be returned for further processing
* Note: We ignore test run participations
* // @formatter:on
* @param quizExercise the id of the QuizExercise that should be evaluated
* @return the newly generated results
*/
private Set<Result> evaluateSubmissions(@NotNull QuizExercise quizExercise) {
Set<Result> createdResults = new HashSet<>();
List<StudentParticipation> studentParticipations = studentParticipationRepository.findAllWithEagerLegalSubmissionsAndEagerResultsByExerciseId(quizExercise.getId());
for (var participation : studentParticipations) {
if (!participation.isTestRun()) {
try {
// reconnect so that the quiz questions are available later on (otherwise there will be a org.hibernate.LazyInitializationException)
participation.setExercise(quizExercise);
Set<Submission> submissions = participation.getSubmissions();
QuizSubmission quizSubmission;
if (submissions.isEmpty()) {
log.warn("Found no submissions for participation {} (Participant {}) in quiz {}", participation.getId(), participation.getParticipant().getName(), quizExercise.getId());
continue;
} else if (submissions.size() > 1) {
log.warn("Found multiple ({}) submissions for participation {} (Participant {}) in quiz {}, taking the one with highest id", submissions.size(), participation.getId(), participation.getParticipant().getName(), quizExercise.getId());
List<Submission> submissionsList = new ArrayList<>(submissions);
// Load submission with highest id
submissionsList.sort(Comparator.comparing(Submission::getId).reversed());
quizSubmission = (QuizSubmission) submissionsList.get(0);
} else {
quizSubmission = (QuizSubmission) submissions.iterator().next();
}
participation.setInitializationState(InitializationState.FINISHED);
boolean resultExisting = false;
// create new result if none is existing
Result result;
if (participation.getResults().isEmpty()) {
result = new Result().participation(participation);
} else {
resultExisting = true;
result = participation.getResults().iterator().next();
}
// Only create Results once after the first evaluation
if (!resultExisting) {
// delete result from quizSubmission, to be able to set a new one
if (quizSubmission.getLatestResult() != null) {
resultService.deleteResultWithComplaint(quizSubmission.getLatestResult().getId());
}
result.setRated(true);
result.setAssessmentType(AssessmentType.AUTOMATIC);
result.setCompletionDate(ZonedDateTime.now());
// set submission to calculate scores
result.setSubmission(quizSubmission);
// calculate scores and update result and submission accordingly
quizSubmission.calculateAndUpdateScores(quizExercise);
result.evaluateQuizSubmission();
// remove submission to follow save order for ordered collections
result.setSubmission(null);
// NOTE: we save participation, submission and result here individually so that one exception (e.g. duplicated key) cannot destroy multiple student answers
submissionRepository.save(quizSubmission);
result = resultRepository.save(result);
// add result to participation
participation.addResult(result);
studentParticipationRepository.save(participation);
// add result to submission
result.setSubmission(quizSubmission);
quizSubmission.addResult(result);
submissionRepository.save(quizSubmission);
// Add result so that it can be returned (and processed later)
createdResults.add(result);
}
} catch (Exception e) {
log.error("Exception in evaluateExamQuizExercise() for user {} in quiz {}: {}", participation.getParticipantIdentifier(), quizExercise.getId(), e.getMessage(), e);
}
}
}
return createdResults;
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class LearningGoalResource method getLearningGoalProgressOfCourse.
/**
* GET /courses/:courseId/goals/:learningGoalId/course-progress gets the learning goal progress for the whole course
*
* @param courseId the id of the course to which the learning goal belongs
* @param learningGoalId the id of the learning goal for which to get the progress
* @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
* @return the ResponseEntity with status 200 (OK) and with the learning goal course performance in the body
*/
@GetMapping("/courses/{courseId}/goals/{learningGoalId}/course-progress")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<CourseLearningGoalProgress> getLearningGoalProgressOfCourse(@PathVariable Long learningGoalId, @PathVariable Long courseId, @RequestParam(defaultValue = "false", required = false) boolean useParticipantScoreTable) {
log.debug("REST request to get course progress for LearningGoal : {}", learningGoalId);
var learningGoal = findLearningGoal(Role.INSTRUCTOR, learningGoalId, courseId);
CourseLearningGoalProgress courseLearningGoalProgress = learningGoalService.calculateLearningGoalCourseProgress(learningGoal, useParticipantScoreTable);
return ResponseEntity.ok().body(courseLearningGoalProgress);
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ParticipantScoreResource method getParticipantScoresOfCourse.
/**
* GET /courses/:courseId/participant-scores gets the participant scores of the course
*
* @param courseId the id of the course for which to get the participant score
* @param pageable pageable object
* @param getUnpaged if set all participant scores of the course will be loaded (paging deactivated)
* @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfCourse(@PathVariable Long courseId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
long start = System.currentTimeMillis();
log.debug("REST request to get participant scores for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).collect(toSet());
List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(getUnpaged ? Pageable.unpaged() : pageable, exercisesOfCourse);
log.info("getParticipantScoresOfCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ParticipantScoreResource method getAverageScoreOfParticipantInCourse.
/**
* GET /courses/:courseId/participant-scores/average-participant gets the average scores of the participants in the course
* <p>
* Important: Exercises with {@link de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore#NOT_INCLUDED} will be not taken into account!
*
* @param courseId the id of the course for which to get the average scores of the participants
* @return the ResponseEntity with status 200 (OK) and with the average scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores/average-participant")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreAverageDTO>> getAverageScoreOfParticipantInCourse(@PathVariable Long courseId) {
long start = System.currentTimeMillis();
log.debug("REST request to get average participant scores of participants for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
List<ParticipantScoreAverageDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreAverageDTOs(exercisesOfCourse);
log.info("getAverageScoreOfStudentInCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
Aggregations