use of de.tum.in.www1.artemis.domain.lecture.ExerciseUnit in project Artemis by ls1intum.
the class LearningGoalService method calculateLearningGoalCourseProgress.
/**
* Calculate the progress in a learning goal for a whole course
*
* @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
* @param learningGoal learning goal to get the progress for
* @return progress of the course in the learning goal
*/
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
courseLearningGoalProgress.learningGoalId = learningGoal.getId();
courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
// The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
// updating learningGoalPerformance by summing up the points of the individual lecture unit progress
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
return courseLearningGoalProgress;
}
use of de.tum.in.www1.artemis.domain.lecture.ExerciseUnit in project ArTEMiS by ls1intum.
the class LearningGoalService method calculateLearningGoalCourseProgress.
/**
* Calculate the progress in a learning goal for a whole course
*
* @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
* @param learningGoal learning goal to get the progress for
* @return progress of the course in the learning goal
*/
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
courseLearningGoalProgress.learningGoalId = learningGoal.getId();
courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
// The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
// updating learningGoalPerformance by summing up the points of the individual lecture unit progress
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
return courseLearningGoalProgress;
}
use of de.tum.in.www1.artemis.domain.lecture.ExerciseUnit in project ArTEMiS by ls1intum.
the class LectureImportService method cloneLectureUnit.
/**
* This helper function clones the {@code importedLectureUnit} and returns it
*
* @param importedLectureUnit The original lecture unit to be copied
* @param newLecture The new lecture to which the lecture units are appended
* @return The cloned lecture unit
*/
private LectureUnit cloneLectureUnit(final LectureUnit importedLectureUnit, final Lecture newLecture) {
log.debug("Creating a new LectureUnit from lecture unit {}", importedLectureUnit);
if (importedLectureUnit instanceof TextUnit) {
TextUnit textUnit = new TextUnit();
textUnit.setName(importedLectureUnit.getName());
textUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
textUnit.setContent(((TextUnit) importedLectureUnit).getContent());
return textUnit;
} else if (importedLectureUnit instanceof VideoUnit) {
VideoUnit videoUnit = new VideoUnit();
videoUnit.setName(importedLectureUnit.getName());
videoUnit.setReleaseDate(importedLectureUnit.getReleaseDate());
videoUnit.setDescription(((VideoUnit) importedLectureUnit).getDescription());
videoUnit.setSource(((VideoUnit) importedLectureUnit).getSource());
return videoUnit;
} else if (importedLectureUnit instanceof AttachmentUnit) {
// Create and save the attachment unit, then the attachment itself, as the id is needed for file handling
AttachmentUnit attachmentUnit = new AttachmentUnit();
attachmentUnit.setDescription(((AttachmentUnit) importedLectureUnit).getDescription());
attachmentUnit.setLecture(newLecture);
lectureUnitRepository.save(attachmentUnit);
Attachment attachment = cloneAttachment(((AttachmentUnit) importedLectureUnit).getAttachment());
attachment.setAttachmentUnit(attachmentUnit);
attachmentRepository.save(attachment);
attachmentUnit.setAttachment(attachment);
return attachmentUnit;
} else if (importedLectureUnit instanceof ExerciseUnit) {
// We have a dedicated exercise import system, so this is left out for now
return null;
}
return null;
}
use of de.tum.in.www1.artemis.domain.lecture.ExerciseUnit in project ArTEMiS by ls1intum.
the class ExerciseUnitIntegrationTest method testAllPreAuthorize.
private void testAllPreAuthorize() throws Exception {
ExerciseUnit exerciseUnit = new ExerciseUnit();
request.post("/api/lectures/" + lecture1.getId() + "/exercise-units", exerciseUnit, HttpStatus.FORBIDDEN);
request.getList("/api/lectures/" + lecture1.getId() + "/exercise-units", HttpStatus.FORBIDDEN, ExerciseUnit.class);
}
use of de.tum.in.www1.artemis.domain.lecture.ExerciseUnit in project ArTEMiS by ls1intum.
the class ExerciseUnitIntegrationTest method createExerciseUnit_notInstructorInCourse_shouldReturnForbidden.
@Test
@WithMockUser(username = "instructor42", roles = "INSTRUCTOR")
public void createExerciseUnit_notInstructorInCourse_shouldReturnForbidden() throws Exception {
Exercise exercise = course1.getExercises().stream().findFirst().get();
ExerciseUnit exerciseUnit = new ExerciseUnit();
exerciseUnit.setExercise(exercise);
request.postWithResponseBody("/api/lectures/" + lecture1.getId() + "/exercise-units", exerciseUnit, ExerciseUnit.class, HttpStatus.FORBIDDEN);
}
Aggregations