diff --git a/server/vbv_lernwelt/dashboard/graphql/queries.py b/server/vbv_lernwelt/dashboard/graphql/queries.py index ad6400f5..4693c49c 100644 --- a/server/vbv_lernwelt/dashboard/graphql/queries.py +++ b/server/vbv_lernwelt/dashboard/graphql/queries.py @@ -1,7 +1,7 @@ import graphene from vbv_lernwelt.course.models import Course, CourseSessionUser -from vbv_lernwelt.dashboard.graphql.types.attendance import CourseDashboardType +from vbv_lernwelt.dashboard.graphql.types.dashboard import CourseDashboardType class DashboardQuery(graphene.ObjectType): diff --git a/server/vbv_lernwelt/dashboard/graphql/types/attendance.py b/server/vbv_lernwelt/dashboard/graphql/types/attendance.py index 4afff8be..3800c565 100644 --- a/server/vbv_lernwelt/dashboard/graphql/types/attendance.py +++ b/server/vbv_lernwelt/dashboard/graphql/types/attendance.py @@ -4,6 +4,7 @@ from typing import List import graphene +from vbv_lernwelt.core.models import User from vbv_lernwelt.course.models import CourseSessionUser from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse from vbv_lernwelt.course_session.services.attendance import AttendanceUserStatus @@ -31,6 +32,57 @@ class AttendanceDayPresences(graphene.ObjectType): filter = graphene.String() +def attendance_day_presences(course_id: graphene.String(), user: User): + completed = CourseSessionAttendanceCourse.objects.filter( + course_session__coursesessionuser__user=user, + course_session__coursesessionuser__role=CourseSessionUser.Role.SESSION_SUPERVISOR, + due_date__end__lt=datetime.datetime.now(), + course_session__course_id=course_id, + ).order_by("-due_date__end") + + _filter = {} + records = [] + + for attendance_day in completed: + circle = attendance_day.learning_content.get_parent_circle() + + course_session = attendance_day.course_session + + url = f"/course/{course_session.course.slug}/cockpit/attendance?id={attendance_day.learning_content.id}&courseSessionId={course_session.id}" + + participants_total = CourseSessionUser.objects.filter( + course_session=course_session, role=CourseSessionUser.Role.MEMBER + ).count() + + participants_present = len( + [ + participant + for participant in attendance_day.attendance_user_list + if participant["status"] == AttendanceUserStatus.PRESENT.value + ] + ) + + _filter[circle.id] = circle.title + records.append( + Record( + course_session_id=course_session.id, + generation=course_session.generation, + circle_id=circle.id, + due_date=format_swiss_datetime(attendance_day.due_date.end), + participants_present=participants_present, + participants_total=participants_total, + cockpit_url=url, + ) + ) + + summary = AttendanceSummary( + days_completed=completed.count(), + participants_present=calculate_avg_participation(records), + ) + + return AttendanceDayPresences(summary=summary, records=records, filter="fuck") + + def calculate_avg_participation(records: List[Record]) -> float: if not records: return 0.0 @@ -44,60 +96,3 @@ def calculate_avg_participation(records: List[Record]) -> float: ) return math.ceil(total_ratio / len(records) * 100) - - -class CourseDashboardType(graphene.ObjectType): - course_id = graphene.String() - course_title = graphene.String() - attendance_day_presences = graphene.Field(AttendanceDayPresences) - - def resolve_attendance_day_presences(root, info): - user = info.context.user - completed = CourseSessionAttendanceCourse.objects.filter( - course_session__coursesessionuser__user=user, - course_session__coursesessionuser__role=CourseSessionUser.Role.SESSION_SUPERVISOR, - due_date__end__lt=datetime.datetime.now(), - course_session__course_id=root.course_id, - ).order_by("-due_date__end") - - _filter = {} - records = [] - - for attendance_day in completed: - circle = attendance_day.learning_content.get_parent_circle() - - course_session = attendance_day.course_session - - url = f"/course/{course_session.course.slug}/cockpit/attendance?id={attendance_day.learning_content.id}&courseSessionId={course_session.id}" - - participants_total = CourseSessionUser.objects.filter( - course_session=course_session, role=CourseSessionUser.Role.MEMBER - ).count() - - participants_present = len( - [ - participant - for participant in attendance_day.attendance_user_list - if participant["status"] == AttendanceUserStatus.PRESENT.value - ] - ) - - _filter[circle.id] = circle.title - records.append( - Record( - course_session_id=course_session.id, - generation=course_session.generation, - circle_id=circle.id, - due_date=format_swiss_datetime(attendance_day.due_date.end), - participants_present=participants_present, - participants_total=participants_total, - cockpit_url=url, - ) - ) - - summary = AttendanceSummary( - days_completed=completed.count(), - participants_present=calculate_avg_participation(records), - ) - - return AttendanceDayPresences(summary=summary, records=records, filter="fuck") diff --git a/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py b/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py index 752c23f2..fb46c300 100644 --- a/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py +++ b/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py @@ -1,7 +1,23 @@ import graphene +from vbv_lernwelt.dashboard.graphql.types.attendance import ( + attendance_day_presences, + AttendanceDayPresences, +) +from vbv_lernwelt.dashboard.graphql.types.feedback import FeedbackResponses + class CourseSessionDashboardType(graphene.ObjectType): session_id = graphene.ID() session_title = graphene.String() session_generation = graphene.String() + + +class CourseDashboardType(graphene.ObjectType): + course_id = graphene.String() + course_title = graphene.String() + attendance_day_presences = graphene.Field(AttendanceDayPresences) + feedback_responses = graphene.Field(FeedbackResponses) + + def resolve_attendance_day_presences(root, info): + return attendance_day_presences(root.course_id, info.context.user) diff --git a/server/vbv_lernwelt/dashboard/graphql/types/feedback.py b/server/vbv_lernwelt/dashboard/graphql/types/feedback.py new file mode 100644 index 00000000..17eeb2e6 --- /dev/null +++ b/server/vbv_lernwelt/dashboard/graphql/types/feedback.py @@ -0,0 +1,18 @@ +import graphene + + +class FeedbackSummary(graphene.ObjectType): + satisfaction_average = graphene.Float() + satisfaction_total = graphene.Int() + total_responses = graphene.Int() + + +class Record(graphene.ObjectType): + course_session_id = graphene.ID() + generation = graphene.String() + circle_id = graphene.ID() + + +class FeedbackResponses(graphene.ObjectType): + records = graphene.List(Record) + summary = graphene.Field(FeedbackSummary)