feat: dashboard API feedback
This commit is contained in:
parent
7550ec9a3f
commit
ea2e303592
|
|
@ -1,7 +1,7 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from vbv_lernwelt.course.models import Course, CourseSessionUser
|
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):
|
class DashboardQuery(graphene.ObjectType):
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from typing import List
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
|
from vbv_lernwelt.core.models import User
|
||||||
from vbv_lernwelt.course.models import CourseSessionUser
|
from vbv_lernwelt.course.models import CourseSessionUser
|
||||||
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
|
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
|
||||||
from vbv_lernwelt.course_session.services.attendance import AttendanceUserStatus
|
from vbv_lernwelt.course_session.services.attendance import AttendanceUserStatus
|
||||||
|
|
@ -31,6 +32,57 @@ class AttendanceDayPresences(graphene.ObjectType):
|
||||||
filter = graphene.String()
|
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:
|
def calculate_avg_participation(records: List[Record]) -> float:
|
||||||
if not records:
|
if not records:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
@ -44,60 +96,3 @@ def calculate_avg_participation(records: List[Record]) -> float:
|
||||||
)
|
)
|
||||||
|
|
||||||
return math.ceil(total_ratio / len(records) * 100)
|
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")
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,23 @@
|
||||||
import graphene
|
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):
|
class CourseSessionDashboardType(graphene.ObjectType):
|
||||||
session_id = graphene.ID()
|
session_id = graphene.ID()
|
||||||
session_title = graphene.String()
|
session_title = graphene.String()
|
||||||
session_generation = 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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
Loading…
Reference in New Issue