Search in sources :

Example 1 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal 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;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 2 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal 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;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 3 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal 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);
    }
}
Also used : LearningGoal(de.tum.in.www1.artemis.domain.LearningGoal)

Example 4 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal in project ArTEMiS by ls1intum.

the class LearningGoalResource method getPrerequisites.

/**
 * GET /courses/:courseId/prerequisites
 * @param courseId the id of the course for which the learning goals should be fetched
 * @return the ResponseEntity with status 200 (OK) and with body the found learning goals
 */
@GetMapping("/courses/{courseId}/prerequisites")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<LearningGoal>> getPrerequisites(@PathVariable Long courseId) {
    log.debug("REST request to get prerequisites for course with id: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    // Authorization check is skipped when course is open to self-registration
    if (!course.isRegistrationEnabled()) {
        User user = userRepository.getUserWithGroupsAndAuthorities();
        authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    }
    Set<LearningGoal> prerequisites = learningGoalRepository.findPrerequisitesByCourseId(courseId);
    // Remove all lecture units as not needed for now
    for (LearningGoal prerequisite : prerequisites) {
        prerequisite.setLectureUnits(Collections.emptySet());
    }
    return ResponseEntity.ok(new ArrayList<>(prerequisites));
}
Also used : User(de.tum.in.www1.artemis.domain.User) LearningGoal(de.tum.in.www1.artemis.domain.LearningGoal) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal 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);
}
Also used : CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)16 LearningGoal (de.tum.in.www1.artemis.domain.LearningGoal)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Course (de.tum.in.www1.artemis.domain.Course)8 CourseLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress)8 User (de.tum.in.www1.artemis.domain.User)6 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)6 IndividualLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)4 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)4 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)4 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)4 CourseExerciseStatisticsDTO (de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO)4 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)4 URI (java.net.URI)4 Stream (java.util.stream.Stream)4