Commit 7bcf0851 authored by I.K Seneviratne's avatar I.K Seneviratne

Committing the implementation of the Gaze estimation period statistics in Lecturer Home Page

parent 0e91389b
...@@ -11,4 +11,5 @@ admin.site.register(LecturerSubject) ...@@ -11,4 +11,5 @@ admin.site.register(LecturerSubject)
admin.site.register(LecturerCredentials) admin.site.register(LecturerCredentials)
admin.site.register(FacultyTimetable) admin.site.register(FacultyTimetable)
admin.site.register(LectureVideo) admin.site.register(LectureVideo)
admin.site.register(LectureActivity) admin.site.register(LectureActivity)
\ No newline at end of file admin.site.register(LectureGazeEstimation)
\ No newline at end of file
...@@ -668,10 +668,15 @@ class GetStudentBehaviorSummaryForPeriod(APIView): ...@@ -668,10 +668,15 @@ class GetStudentBehaviorSummaryForPeriod(APIView):
isRecordFound = False isRecordFound = False
activity_percentages = {} activity_percentages = {}
emotion_percentages = {} emotion_percentages = {}
gaze_estimation_percentages = {}
individual_lec_activties = [] individual_lec_activties = []
individual_lec_emotions = [] individual_lec_emotions = []
individual_lec_gaze_estimations = []
activity_labels = [] activity_labels = []
emotion_labels = [] emotion_labels = []
gaze_estimation_labels = []
current_date = datetime.datetime.now().date() current_date = datetime.datetime.now().date()
...@@ -705,13 +710,29 @@ class GetStudentBehaviorSummaryForPeriod(APIView): ...@@ -705,13 +710,29 @@ class GetStudentBehaviorSummaryForPeriod(APIView):
emotion_percentages, individual_lec_emotions, emotion_labels = ed.get_student_emotion_summary_for_period(emotion_data) emotion_percentages, individual_lec_emotions, emotion_labels = ed.get_student_emotion_summary_for_period(emotion_data)
# retrieving lecture gaze estimations
lec_gaze_estimation = LectureGazeEstimation.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# if there are gaze estimation data
if len(lec_gaze_estimation) > 0:
gaze_estimation_serializer = LectureGazeEstimationSerializer(lec_gaze_estimation, many=True)
gaze_estimation_data = gaze_estimation_serializer.data
gaze_estimation_percentages, individual_lec_gaze_estimations, gaze_estimation_labels = hge.get_student_gaze_estimation_summary_for_period(gaze_estimation_data)
return Response({ return Response({
"activity_response": activity_percentages, "activity_response": activity_percentages,
"emotion_response": emotion_percentages, "emotion_response": emotion_percentages,
"gaze_estimation_response": gaze_estimation_percentages,
"individual_activities": individual_lec_activties, "individual_activities": individual_lec_activties,
"individual_emotions": individual_lec_emotions, "individual_emotions": individual_lec_emotions,
"individual_gaze_estimations": individual_lec_gaze_estimations,
"activity_labels": activity_labels, "activity_labels": activity_labels,
"emotion_labels": emotion_labels, "emotion_labels": emotion_labels,
"gaze_estimation_labels": gaze_estimation_labels,
"isRecordFound": isRecordFound "isRecordFound": isRecordFound
}) })
...@@ -554,4 +554,58 @@ def get_lecture_gaze_esrimation_for_frames(video_name): ...@@ -554,4 +554,58 @@ def get_lecture_gaze_esrimation_for_frames(video_name):
return frame_detections, frame_rate return frame_detections, frame_rate
\ No newline at end of file
def get_student_gaze_estimation_summary_for_period(gaze_estimation_data):
# declare variables to add percentage values
phone_checking_perct_combined = 0.0
listening_perct_combined = 0.0
note_taking_perct_combined = 0.0
looking_up_right_perct_combined = 0.0
looking_up_left_perct_combined = 0.0
looking_down_right_perct_combined = 0.0
looking_down_left_perct_combined = 0.0
looking_front_perct_combined = 0.0
# get the number of activties to calculate average
no_of_gaze_estimations = len(gaze_estimation_data)
individual_lec_gaze_estimations = []
gaze_estimation_labels = ["looking_up_and_right_perct", "looking_up_and_left_perct", "looking_down_and_right_perct", "looking_down_and_left_perct", "looking_front_perct"]
# iterate through the activities
for gaze_estimation in gaze_estimation_data:
individual_gaze_estimation = {}
individual_gaze_estimation["looking_up_and_right_perct"] = float(gaze_estimation['looking_up_and_right_perct'])
individual_gaze_estimation["looking_up_and_left_perct"] = float(gaze_estimation['looking_up_and_left_perct'])
individual_gaze_estimation["looking_down_and_right_perct"] = float(gaze_estimation['looking_down_and_right_perct'])
individual_gaze_estimation["looking_down_and_left_perct"] = float(gaze_estimation['looking_down_and_left_perct'])
individual_gaze_estimation["looking_front_perct"] = float(gaze_estimation['looking_front_perct'])
looking_up_right_perct_combined += float(gaze_estimation['looking_up_and_right_perct'])
looking_up_left_perct_combined += float(gaze_estimation['looking_up_and_left_perct'])
looking_down_right_perct_combined += float(gaze_estimation['looking_down_and_right_perct'])
looking_down_left_perct_combined += float(gaze_estimation['looking_down_and_left_perct'])
looking_front_perct_combined += float(gaze_estimation['looking_front_perct'])
# append to the list
individual_lec_gaze_estimations.append(individual_gaze_estimation)
# calculate the average percentages
looking_up_right_average_perct = round((looking_up_right_perct_combined / no_of_gaze_estimations), 1)
looking_up_left_perct = round((looking_up_left_perct_combined / no_of_gaze_estimations), 1)
looking_down_right_average_perct = round((looking_down_right_perct_combined / no_of_gaze_estimations), 1)
looking_down_left_average_perct = round((looking_down_left_perct_combined / no_of_gaze_estimations), 1)
looking_front_average_perct = round((looking_front_perct_combined / no_of_gaze_estimations), 1)
percentages = {}
percentages["looking_up_and_right_perct"] = looking_up_right_average_perct
percentages["looking_up_and_left_perct"] = looking_up_left_perct_combined
percentages["looking_down_and_right_perct"] = looking_down_right_perct_combined
percentages["looking_down_and_left_perct"] = looking_down_left_perct_combined
percentages["looking_front_perct"] = looking_front_average_perct
return percentages, individual_lec_gaze_estimations, gaze_estimation_labels
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment