Commit f1aaee1e authored by I.K Seneviratne's avatar I.K Seneviratne

Committing the implementation for calculating the correlations among the...

Committing the implementation for calculating the correlations among the student behavior components.
parent aaa66103
...@@ -15,7 +15,6 @@ from random import Random ...@@ -15,7 +15,6 @@ from random import Random
from MonitorLecturerApp.models import LectureRecordedVideo, LecturerVideoMetaData from MonitorLecturerApp.models import LectureRecordedVideo, LecturerVideoMetaData
from MonitorLecturerApp.serializers import LectureRecordedVideoSerializer, LecturerVideoMetaDataSerializer from MonitorLecturerApp.serializers import LectureRecordedVideoSerializer, LecturerVideoMetaDataSerializer
from .MongoModels import *
from rest_framework.views import * from rest_framework.views import *
from .logic import activity_recognition as ar from .logic import activity_recognition as ar
from . import emotion_detector as ed from . import emotion_detector as ed
...@@ -23,6 +22,7 @@ from .logic import id_generator as ig ...@@ -23,6 +22,7 @@ from .logic import id_generator as ig
from .logic import pdf_file_generator as pdf from .logic import pdf_file_generator as pdf
from .logic import head_gaze_estimation as hge from .logic import head_gaze_estimation as hge
from .logic import video_extraction as ve from .logic import video_extraction as ve
from . logic import student_behavior_process as sbp
from .serializers import * from .serializers import *
from braces.views import CsrfExemptMixin from braces.views import CsrfExemptMixin
...@@ -114,8 +114,7 @@ class LecturerSubjectViewSet(APIView): ...@@ -114,8 +114,7 @@ class LecturerSubjectViewSet(APIView):
# API for timetables # API for timetables
class FacultyTimetableViewSet(CsrfExemptMixin, APIView): class FacultyTimetableViewSet(APIView):
# authentication_classes = []
def get(self, request): def get(self, request):
timetable = FacultyTimetable.objects.all().filter() timetable = FacultyTimetable.objects.all().filter()
...@@ -1271,6 +1270,208 @@ class GetLectureGazeCorrelations(APIView): ...@@ -1271,6 +1270,208 @@ class GetLectureGazeCorrelations(APIView):
}) })
# this class will handle the student activity-emotion correlations
class GetStudentActivityEmotionCorrelations(APIView):
def get(self, request):
# get the day option
option = request.query_params.get('option')
# get the lecturer id
lecturer = request.query_params.get('lecturer')
int_option = int(option)
# initialize the student behavior count
student_behavior_count = 0
current_date = datetime.datetime.now().date()
option_date = datetime.timedelta(days=int_option)
# get the actual date
previous_date = current_date - option_date
# initialize the lists
individual_lec_activities = []
individual_lec_emotions = []
activity_emotion_correlations = []
# retrieving lecture activities
lec_activity = LectureActivity.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# retrieving lecture emotions
lec_emotion = LectureEmotionReport.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# if there are lecture activities
if len(lec_activity) > 0:
student_behavior_count += 1
activity_serializer = LectureActivitySerializer(lec_activity, many=True)
activity_data = activity_serializer.data
_, individual_lec_activities, _ = ar.get_student_activity_summary_for_period(activity_data)
# if there are lecture emotions
if len(lec_emotion) > 0:
student_behavior_count += 1
emotion_serializer = LectureEmotionSerializer(lec_emotion, many=True)
emotion_data = emotion_serializer.data
_, individual_lec_emotions, _ = ed.get_student_emotion_summary_for_period(emotion_data)
# if both student activity, emotion are available
if student_behavior_count == 2:
# find the correlations between student activity and gaze estimations
activity_emotion_correlations = sbp.calculate_student_activity_emotion_correlations(individual_lec_activities, individual_lec_emotions)
return Response({
"correlations": activity_emotion_correlations
})
# this class will handle the student activity-emotion correlations
class GetStudentActivityGazeCorrelations(APIView):
def get(self, request):
# get the day option
option = request.query_params.get('option')
# get the lecturer id
lecturer = request.query_params.get('lecturer')
int_option = int(option)
# initialize the student behavior count
student_behavior_count = 0
current_date = datetime.datetime.now().date()
option_date = datetime.timedelta(days=int_option)
# get the actual date
previous_date = current_date - option_date
# initialize the lists
individual_lec_activities = []
individual_lec_gaze = []
activity_gaze_correlations = []
# retrieving lecture gaze estimations
lec_gaze = LectureGazeEstimation.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# retrieving lecture activities
lec_activity = LectureActivity.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# if there are lecture activities
if len(lec_activity) > 0:
student_behavior_count += 1
activity_serializer = LectureActivitySerializer(lec_activity, many=True)
activity_data = activity_serializer.data
_, individual_lec_activities, _ = ar.get_student_activity_summary_for_period(activity_data)
# if there are gaze estimations
if len(lec_gaze) > 0:
student_behavior_count += 1
gaze_serializer = LectureGazeEstimationSerializer(lec_gaze, many=True)
gaze_data = gaze_serializer.data
_, individual_lec_gaze, _ = hge.get_student_gaze_estimation_summary_for_period(gaze_data)
# if there are any recorded lectures
if student_behavior_count == 2:
# find the correlations between student activity and gaze estimations
activity_gaze_correlations = sbp.calculate_student_activity_gaze_correlations(individual_lec_activities, individual_lec_gaze)
return Response({
"correlations": activity_gaze_correlations
})
# this class will handle the student emotion-gaze correlations
class GetStudentEmotionGazeCorrelations(APIView):
def get(self, request):
# get the day option
option = request.query_params.get('option')
# get the lecturer id
lecturer = request.query_params.get('lecturer')
int_option = int(option)
# initialize the student behavior count
student_behavior_count = 0
current_date = datetime.datetime.now().date()
option_date = datetime.timedelta(days=int_option)
# get the actual date
previous_date = current_date - option_date
# initialize the lists
individual_lec_emotions = []
individual_lec_gaze = []
emotion_gaze_correlations = []
# retrieving lecture gaze estimations
lec_gaze = LectureGazeEstimation.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# retrieving lecture emotions
lec_emotion = LectureEmotionReport.objects.filter(
lecture_video_id__date__gte=previous_date,
lecture_video_id__date__lte=current_date,
lecture_video_id__lecturer=lecturer
)
# if there are lecture emotions
if len(lec_emotion) > 0:
student_behavior_count += 1
emotion_serializer = LectureEmotionSerializer(lec_emotion, many=True)
emotion_data = emotion_serializer.data
_, individual_lec_emotions, _ = ed.get_student_emotion_summary_for_period(emotion_data)
# if there are gaze estimations
if len(lec_gaze) > 0:
student_behavior_count += 1
gaze_serializer = LectureGazeEstimationSerializer(lec_gaze, many=True)
gaze_data = gaze_serializer.data
_, individual_lec_gaze, _ = hge.get_student_gaze_estimation_summary_for_period(gaze_data)
# if there are any recorded lectures
if student_behavior_count == 2:
# find the correlations between student activity and gaze estimations
emotion_gaze_correlations = sbp.calculate_student_emotion_gaze_correlations(individual_lec_emotions, individual_lec_gaze)
return Response({
"correlations": emotion_gaze_correlations
})
##### BATCH PROCESS SECTION ##### ##### BATCH PROCESS SECTION #####
# perform the student behavior analysis as a batch process # perform the student behavior analysis as a batch process
...@@ -1319,4 +1520,5 @@ class TestRandom(APIView): ...@@ -1319,4 +1520,5 @@ class TestRandom(APIView):
return Response({ return Response({
"response": random "response": random
}) })
\ No newline at end of file
import pandas as pd
from . import utilities as ut
def calculate_student_activity_emotion_correlations(lec_activities, lec_emotions):
# this variable will be used to store the correlations
correlations = []
limit = 10
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_activities))]
# student gaze labels
student_activity_labels = ['phone checking', 'listening', 'note taking']
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
# lecture activity data list (student)
phone_perct_list = []
note_perct_list = []
listen_perct_list = []
# lecture emotion data list (student)
happy_perct_list = []
sad_perct_list = []
angry_perct_list = []
surprise_perct_list = []
neutral_perct_list = []
# loop through the lecture activity data
for data in lec_activities:
phone_perct_list.append(int(data['phone_perct']))
listen_perct_list.append(int(data['listening_perct']))
note_perct_list.append(int(data['writing_perct']))
# loop through the lecture emotion data
for data in lec_emotions:
happy_perct_list.append(int(data['happy_perct']))
sad_perct_list.append(int(data['sad_perct']))
angry_perct_list.append(int(data['angry_perct']))
surprise_perct_list.append(int(data['surprise_perct']))
neutral_perct_list.append(int(data['neutral_perct']))
corr_data = {'phone checking': phone_perct_list, 'listening': listen_perct_list, 'note taking': note_perct_list,
'Happy': happy_perct_list, 'Sad': sad_perct_list, 'Angry': angry_perct_list, 'Surprise': surprise_perct_list, 'Neutral': neutral_perct_list,
}
# create the dataframe
df = pd.DataFrame(corr_data, index=data_index)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
index = pd_series.index[i]
# check whether the first index is a student activity
isStudentActivity = index[0] in student_activity_labels
# check whether the second index is a lecturer activity
isStudentEmotion = index[1] in student_emotion_labels
# if both are student and lecturer activities, add to the dictionary
if isStudentActivity & isStudentEmotion:
corr_dict['index'] = index
corr_dict['value'] = pd_series.values[i]
# append the dictionary to the 'correlations' list
correlations.append(corr_dict)
# return the list
return correlations
# this method will calculate the student activity-gaze correlations
def calculate_student_activity_gaze_correlations(lec_activities, lec_gaze):
# this variable will be used to store the correlations
correlations = []
limit = 10
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_activities))]
# student gaze labels
student_activity_labels = ['phone checking', 'listening', 'note taking']
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
student_gaze_labels = ['Up and Right', 'Up and Left', 'Down and Right', 'Down and Left', 'Front']
# lecture activity data list (student)
phone_perct_list = []
note_perct_list = []
listen_perct_list = []
# lecture gaze estimation data list (student)
upright_perct_list = []
upleft_perct_list = []
downright_perct_list = []
downleft_perct_list = []
front_perct_list = []
# loop through the lecture activity data
for data in lec_activities:
phone_perct_list.append(int(data['phone_perct']))
listen_perct_list.append(int(data['listening_perct']))
note_perct_list.append(int(data['writing_perct']))
# loop through the lecture activity data
for data in lec_gaze:
upright_perct_list.append(int(data['looking_up_and_right_perct']))
upleft_perct_list.append(int(data['looking_up_and_left_perct']))
downright_perct_list.append(int(data['looking_down_and_right_perct']))
downleft_perct_list.append(int(data['looking_down_and_left_perct']))
front_perct_list.append(int(data['looking_front_perct']))
corr_data = {'phone checking': phone_perct_list, 'listening': listen_perct_list, 'note taking': note_perct_list,
'Up and Right': upright_perct_list, 'Up and Left': upleft_perct_list, 'Down and Right': downright_perct_list,
'Down and Left': downleft_perct_list, 'Front': front_perct_list
}
# create the dataframe
df = pd.DataFrame(corr_data, index=data_index)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
index = pd_series.index[i]
# check whether the first index is a student activity
isStudentActivity = index[0] in student_activity_labels
# check whether the second index is a student gaze estimation
isStudentGaze = index[1] in student_gaze_labels
# if both are student and lecturer activities, add to the dictionary
if isStudentActivity & isStudentGaze:
corr_dict['index'] = index
corr_dict['value'] = pd_series.values[i]
# append the dictionary to the 'correlations' list
correlations.append(corr_dict)
# return the list
return correlations
# this method will calculate the student activity-gaze correlations
def calculate_student_emotion_gaze_correlations(lec_emotions, lec_gaze):
# this variable will be used to store the correlations
correlations = []
limit = 10
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_emotions))]
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
student_gaze_labels = ['Up and Right', 'Up and Left', 'Down and Right', 'Down and Left', 'Front']
# lecture emotion data list (student)
happy_perct_list = []
sad_perct_list = []
angry_perct_list = []
surprise_perct_list = []
neutral_perct_list = []
# lecture gaze estimation data list (student)
upright_perct_list = []
upleft_perct_list = []
downright_perct_list = []
downleft_perct_list = []
front_perct_list = []
# loop through the lecture emotion data
for data in lec_emotions:
happy_perct_list.append(int(data['happy_perct']))
sad_perct_list.append(int(data['sad_perct']))
angry_perct_list.append(int(data['angry_perct']))
surprise_perct_list.append(int(data['surprise_perct']))
neutral_perct_list.append(int(data['neutral_perct']))
# loop through the lecture gaze data
for data in lec_gaze:
upright_perct_list.append(int(data['looking_up_and_right_perct']))
upleft_perct_list.append(int(data['looking_up_and_left_perct']))
downright_perct_list.append(int(data['looking_down_and_right_perct']))
downleft_perct_list.append(int(data['looking_down_and_left_perct']))
front_perct_list.append(int(data['looking_front_perct']))
corr_data = {'Happy': happy_perct_list, 'Sad': sad_perct_list, 'Angry': angry_perct_list, 'Surprise': surprise_perct_list, 'Neutral': neutral_perct_list,
'Up and Right': upright_perct_list, 'Up and Left': upleft_perct_list, 'Down and Right': downright_perct_list,
'Down and Left': downleft_perct_list, 'Front': front_perct_list
}
# create the dataframe
df = pd.DataFrame(corr_data, index=data_index)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
index = pd_series.index[i]
# check whether the first index is a student activity
isStudentEmotion = index[0] in student_emotion_labels
# check whether the second index is a student gaze estimation
isStudentGaze = index[1] in student_gaze_labels
# if both are student and lecturer activities, add to the dictionary
if isStudentEmotion & isStudentGaze:
corr_dict['index'] = index
corr_dict['value'] = pd_series.values[i]
# append the dictionary to the 'correlations' list
correlations.append(corr_dict)
# return the list
return correlations
\ No newline at end of file
This diff is collapsed.
...@@ -151,21 +151,30 @@ urlpatterns = [ ...@@ -151,21 +151,30 @@ urlpatterns = [
# retrieves lecture activity summary # retrieves lecture activity summary
url(r'^get-lecture-activity-summary/$', api.GetLectureActivitySummary.as_view()), url(r'^get-lecture-activity-summary/$', api.GetLectureActivitySummary.as_view()),
# retrieves lecture activity summary # retrieves lecture emotion summary
url(r'^get-lecture-emotion-summary/$', api.GetLectureEmotionSummary.as_view()), url(r'^get-lecture-emotion-summary/$', api.GetLectureEmotionSummary.as_view()),
# retrieves lecture activity summary # retrieves lecture gaze estimation summary
url(r'^get-lecture-gaze-summary/$', api.GetLectureGazeSummary.as_view()), url(r'^get-lecture-gaze-summary/$', api.GetLectureGazeSummary.as_view()),
# retrieves lecture activity summary # retrieves student activity correlations with lecturer activity
url(r'^get-activity-correlations/$', api.GetLectureActivityCorrelations.as_view()), url(r'^get-activity-correlations/$', api.GetLectureActivityCorrelations.as_view()),
# retrieves lecture activity summary # retrieves student emotion correlations with lecturer activity
url(r'^get-emotion-correlations/$', api.GetLectureEmotionCorrelations.as_view()), url(r'^get-emotion-correlations/$', api.GetLectureEmotionCorrelations.as_view()),
# retrieves lecture activity summary # retrieves student gaze estimation correlations with lecturer activity
url(r'^get-gaze-correlations/$', api.GetLectureGazeCorrelations.as_view()), url(r'^get-gaze-correlations/$', api.GetLectureGazeCorrelations.as_view()),
# retrieves student activity-emotion correlations
url(r'^get-student-activity-emotion-correlations/$', api.GetStudentActivityEmotionCorrelations.as_view()),
# retrieves student activity-gaze correlations
url(r'^get-student-activity-gaze-correlations/$', api.GetStudentActivityGazeCorrelations.as_view()),
# retrieves student emotion-gaze correlations
url(r'^get-student-emotion-gaze-correlations/$', api.GetStudentEmotionGazeCorrelations.as_view()),
##### OTHERS ##### ##### OTHERS #####
......
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