use of de.tum.in.www1.artemis.domain.lecture.LectureUnit in project Artemis by ls1intum.
the class LectureUnitResource method updateLectureUnitsOrder.
/**
* PUT /lectures/:lectureId/lecture-units-order
*
* @param lectureId the id of the lecture for which to update the lecture unit order
* @param orderedLectureUnits ordered lecture units
* @return the ResponseEntity with status 200 (OK) and with body the ordered lecture units
*/
@PutMapping("/lectures/{lectureId}/lecture-units-order")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<LectureUnit>> updateLectureUnitsOrder(@PathVariable Long lectureId, @RequestBody List<LectureUnit> orderedLectureUnits) {
log.debug("REST request to update the order of lecture units of lecture: {}", lectureId);
Optional<Lecture> lectureOptional = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(lectureId);
if (lectureOptional.isEmpty()) {
throw new EntityNotFoundException("Lecture", lectureId);
}
Lecture lecture = lectureOptional.get();
if (lecture.getCourse() == null) {
return conflict();
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
// Ensure that exactly as many lecture units have been received as are currently related to the lecture
if (orderedLectureUnits.size() != lecture.getLectureUnits().size()) {
return conflict();
}
// Ensure that all received lecture units are already related to the lecture
for (LectureUnit lectureUnit : orderedLectureUnits) {
if (!lecture.getLectureUnits().contains(lectureUnit)) {
return conflict();
}
// Set the lecture manually as it won't be included in orderedLectureUnits
lectureUnit.setLecture(lecture);
// keep bidirectional mapping between attachment unit and attachment
if (lectureUnit instanceof AttachmentUnit) {
((AttachmentUnit) lectureUnit).getAttachment().setAttachmentUnit((AttachmentUnit) lectureUnit);
}
}
lecture.setLectureUnits(orderedLectureUnits);
Lecture persistedLecture = lectureRepository.save(lecture);
return ResponseEntity.ok(persistedLecture.getLectureUnits());
}
use of de.tum.in.www1.artemis.domain.lecture.LectureUnit 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.LectureUnit 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.LectureUnit 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.LectureUnit in project ArTEMiS by ls1intum.
the class LectureUnitService method disconnectLectureUnitAndLearningGoal.
/**
* Remove connection between lecture unit and learning goal in the database
*
* @param lectureUnit Lecture unit connected to learning goal
* @param learningGoal Learning goal connected to lecture unit
*/
public void disconnectLectureUnitAndLearningGoal(LectureUnit lectureUnit, LearningGoal learningGoal) {
Optional<LearningGoal> learningGoalFromDbOptional = learningGoalRepository.findByIdWithLectureUnitsBidirectional(learningGoal.getId());
if (learningGoalFromDbOptional.isPresent()) {
LearningGoal learningGoalFromDb = learningGoalFromDbOptional.get();
learningGoalFromDb.removeLectureUnit(lectureUnit);
learningGoalRepository.save(learningGoalFromDb);
}
}
Aggregations