feat: dashboard API feedback
This commit is contained in:
parent
7550ec9a3f
commit
ea2e303592
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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,33 +32,12 @@ class AttendanceDayPresences(graphene.ObjectType):
|
|||
filter = graphene.String()
|
||||
|
||||
|
||||
def calculate_avg_participation(records: List[Record]) -> float:
|
||||
if not records:
|
||||
return 0.0
|
||||
|
||||
total_ratio = 0.0
|
||||
for record in records:
|
||||
if record.participants_total == 0:
|
||||
continue
|
||||
total_ratio += float(record.participants_present) / float(
|
||||
record.participants_total
|
||||
)
|
||||
|
||||
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
|
||||
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=root.course_id,
|
||||
course_session__course_id=course_id,
|
||||
).order_by("-due_date__end")
|
||||
|
||||
_filter = {}
|
||||
|
|
@ -101,3 +81,18 @@ class CourseDashboardType(graphene.ObjectType):
|
|||
)
|
||||
|
||||
return AttendanceDayPresences(summary=summary, records=records, filter="fuck")
|
||||
|
||||
|
||||
def calculate_avg_participation(records: List[Record]) -> float:
|
||||
if not records:
|
||||
return 0.0
|
||||
|
||||
total_ratio = 0.0
|
||||
for record in records:
|
||||
if record.participants_total == 0:
|
||||
continue
|
||||
total_ratio += float(record.participants_present) / float(
|
||||
record.participants_total
|
||||
)
|
||||
|
||||
return math.ceil(total_ratio / len(records) * 100)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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