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

Committing the modifications of finding correlations between student behavior components.

.
parent 723f804a
......@@ -1167,6 +1167,7 @@ class GetLectureActivityCorrelations(APIView):
activity_correlations = ar.get_activity_correlations(individual_lec_activities, lec_recorded_activity_data)
return Response({
"correlations": activity_correlations
})
......
......@@ -5,10 +5,14 @@ def calculate_student_activity_emotion_correlations(lec_activities, lec_emotions
# this variable will be used to store the correlations
correlations = []
limit = 10
# limit = 10
limit = len(lec_activities)
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_activities))]
# define the correlation data dictionary
corr_data = {}
# student gaze labels
student_activity_labels = ['phone checking', 'listening', 'note taking']
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
......@@ -28,29 +32,74 @@ def calculate_student_activity_emotion_correlations(lec_activities, lec_emotions
# 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']))
value = int(data['phone_perct'])
value1 = int(data['listening_perct'])
value2= int(data['writing_perct'])
if value != 0:
phone_perct_list.append(int(data['phone_perct']))
if value1 != 0:
listen_perct_list.append(int(data['listening_perct']))
if value2 != 0:
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,
}
value = int(data['happy_perct'])
value1 = int(data['sad_perct'])
value2 = int(data['angry_perct'])
value3 = int(data['surprise_perct'])
value4 = int(data['neutral_perct'])
if value != 0:
happy_perct_list.append(int(data['happy_perct']))
if value1 != 0:
sad_perct_list.append(int(data['sad_perct']))
if value2 != 0:
angry_perct_list.append(int(data['angry_perct']))
if value3 != 0:
surprise_perct_list.append(int(data['surprise_perct']))
if value4 != 0:
neutral_perct_list.append(int(data['neutral_perct']))
if len(phone_perct_list) == len(lec_activities):
corr_data[student_activity_labels[0]] = phone_perct_list
if len(listen_perct_list) == len(lec_activities):
corr_data[student_activity_labels[1]] = listen_perct_list
if len(note_perct_list) == len(lec_activities):
corr_data[student_activity_labels[2]] = note_perct_list
if len(happy_perct_list) == len(lec_activities):
corr_data[student_emotion_labels[0]] = happy_perct_list
if len(sad_perct_list) == len(lec_activities):
corr_data[student_emotion_labels[1]] = sad_perct_list
if len(angry_perct_list) == len(lec_activities):
corr_data[student_emotion_labels[2]] = angry_perct_list
if len(surprise_perct_list) == len(lec_activities):
corr_data[student_emotion_labels[3]] = surprise_perct_list
if len(neutral_perct_list) == len(lec_activities):
corr_data[student_emotion_labels[4]] = neutral_perct_list
# 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,
# }
print('data: ', corr_data)
# create the dataframe
df = pd.DataFrame(corr_data, index=data_index)
df = df[(df.T != 0).any()]
print(df)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
print(pd_series)
# assign a new value to the 'limit' variable
limit = len(pd_series) if len(pd_series) < limit else limit
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
......@@ -70,6 +119,7 @@ def calculate_student_activity_emotion_correlations(lec_activities, lec_emotions
# append the dictionary to the 'correlations' list
correlations.append(corr_dict)
# return the list
return correlations
......@@ -79,13 +129,16 @@ def calculate_student_activity_gaze_correlations(lec_activities, lec_gaze):
# this variable will be used to store the correlations
correlations = []
limit = 10
limit = len(lec_activities)
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_activities))]
# this dictionary contains the correlation data
corr_data = {}
# student gaze labels
student_activity_labels = ['phone checking', 'listening', 'note taking']
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
# 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)
......@@ -103,30 +156,73 @@ def calculate_student_activity_gaze_correlations(lec_activities, lec_gaze):
# 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']))
value = int(data['phone_perct'])
value1 = int(data['listening_perct'])
value2 = int(data['writing_perct'])
if value != 0:
phone_perct_list.append(int(data['phone_perct']))
if value1 != 0:
listen_perct_list.append(int(data['listening_perct']))
if value2 != 0:
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
}
value = int(data['looking_up_and_right_perct'])
value1 = int(data['looking_up_and_left_perct'])
value2 = int(data['looking_down_and_right_perct'])
value3 = int(data['looking_down_and_left_perct'])
value4 = int(data['looking_front_perct'])
if value != 0:
upright_perct_list.append(int(data['looking_up_and_right_perct']))
if value1 != 0:
upleft_perct_list.append(int(data['looking_up_and_left_perct']))
if value2 != 0:
downright_perct_list.append(int(data['looking_down_and_right_perct']))
if value3 != 0:
downleft_perct_list.append(int(data['looking_down_and_left_perct']))
if value4 != 0:
front_perct_list.append(int(data['looking_front_perct']))
if (len(phone_perct_list)) == len(lec_activities):
corr_data[student_activity_labels[0]] = phone_perct_list
if (len(listen_perct_list)) == len(lec_activities):
corr_data[student_activity_labels[1]] = listen_perct_list
if (len(note_perct_list)) == len(lec_activities):
corr_data[student_activity_labels[2]] = note_perct_list
if (len(upright_perct_list)) == len(lec_activities):
corr_data[student_gaze_labels[0]] = upright_perct_list
if (len(upleft_perct_list)) == len(lec_activities):
corr_data[student_gaze_labels[1]] = upleft_perct_list
if (len(downright_perct_list)) == len(lec_activities):
corr_data[student_gaze_labels[2]] = downright_perct_list
if (len(downleft_perct_list)) == len(lec_activities):
corr_data[student_gaze_labels[3]] = downleft_perct_list
if (len(front_perct_list)) == len(lec_activities):
corr_data[student_gaze_labels[4]] = front_perct_list
# 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)
print(df)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
print(pd_series)
print('length of pd_series: ', len(pd_series))
# assign a new value to the 'limit' variable
limit = len(pd_series) if len(pd_series) < limit else limit
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
......@@ -146,6 +242,8 @@ def calculate_student_activity_gaze_correlations(lec_activities, lec_gaze):
# append the dictionary to the 'correlations' list
correlations.append(corr_dict)
print('correlations: ', correlations)
# return the list
return correlations
......@@ -155,10 +253,13 @@ def calculate_student_emotion_gaze_correlations(lec_emotions, lec_gaze):
# this variable will be used to store the correlations
correlations = []
limit = 10
limit = len(lec_emotions)
data_index = ['lecture-{}'.format(i + 1) for i in range(len(lec_emotions))]
# this dictionary will contain the correlation data
corr_data = {}
student_emotion_labels = ['Happy', 'Sad', 'Angry', 'Surprise', 'Neutral']
student_gaze_labels = ['Up and Right', 'Up and Left', 'Down and Right', 'Down and Left', 'Front']
......@@ -180,32 +281,84 @@ def calculate_student_emotion_gaze_correlations(lec_emotions, lec_gaze):
# 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']))
value = int(data['happy_perct'])
value1 = int(data['sad_perct'])
value2 = int(data['angry_perct'])
value3 = int(data['surprise_perct'])
value4 = int(data['neutral_perct'])
if value != 0:
happy_perct_list.append(int(data['happy_perct']))
if value1 != 0:
sad_perct_list.append(int(data['sad_perct']))
if value2 != 0:
angry_perct_list.append(int(data['angry_perct']))
if value3 != 0:
surprise_perct_list.append(int(data['surprise_perct']))
if value4 != 0:
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
}
value = int(data['looking_up_and_right_perct'])
value1 = int(data['looking_up_and_left_perct'])
value2 = int(data['looking_down_and_right_perct'])
value3 = int(data['looking_down_and_left_perct'])
value4 = int(data['looking_front_perct'])
if value != 0:
upright_perct_list.append(int(data['looking_up_and_right_perct']))
if value1 != 0:
upleft_perct_list.append(int(data['looking_up_and_left_perct']))
if value2 != 0:
downright_perct_list.append(int(data['looking_down_and_right_perct']))
if value3 != 0:
downleft_perct_list.append(int(data['looking_down_and_left_perct']))
if value4 != 0:
front_perct_list.append(int(data['looking_front_perct']))
if len(happy_perct_list) == len(lec_emotions):
corr_data[student_emotion_labels[0]] = happy_perct_list
if len(sad_perct_list) == len(lec_emotions):
corr_data[student_emotion_labels[1]] = sad_perct_list
if len(angry_perct_list) == len(lec_emotions):
corr_data[student_emotion_labels[2]] = angry_perct_list
if len(surprise_perct_list) == len(lec_emotions):
corr_data[student_emotion_labels[3]] = surprise_perct_list
if len(neutral_perct_list) == len(lec_emotions):
corr_data[student_emotion_labels[4]] = neutral_perct_list
if (len(upright_perct_list)) == len(lec_emotions):
corr_data[student_gaze_labels[0]] = upright_perct_list
if (len(upleft_perct_list)) == len(lec_emotions):
corr_data[student_gaze_labels[1]] = upleft_perct_list
if (len(downright_perct_list)) == len(lec_emotions):
corr_data[student_gaze_labels[2]] = downright_perct_list
if (len(downleft_perct_list)) == len(lec_emotions):
corr_data[student_gaze_labels[3]] = downleft_perct_list
if (len(front_perct_list)) == len(lec_emotions):
corr_data[student_gaze_labels[4]] = front_perct_list
# 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)
print(df)
# calculate the correlation
pd_series = ut.get_top_abs_correlations(df, limit)
print(pd_series)
# assign a new value to the 'limit' variable
limit = len(pd_series) if len(pd_series) < limit else limit
for i in range(limit):
# this dictionary will get the pandas.Series object's indices and values separately
corr_dict = {}
......
......@@ -1240,42 +1240,50 @@
function displayActivityEmotionCorrelations(correlations) {
let htmlString = "";
if (correlations.length !== 0) {
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
htmlString += "</td>";
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
htmlString += "</tr>";
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
} else {
htmlString += "<tr>";
htmlString += "<td colspan='3'>";
htmlString += "<span class='font-italic'>No correlations were found</span>";
htmlString += "</td>";
htmlString += "</tr>";
}
//append to the <tbody>
$('#student_activity_emotion_corr_tbody').append(htmlString);
......@@ -1293,39 +1301,47 @@
let htmlString = "";
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
if (correlations.length !== 0) {
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
htmlString += "</td>";
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
htmlString += "</tr>";
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
}
} else {
htmlString += "<tr>";
htmlString += "<td colspan='3'>";
htmlString += "<span class='font-italic'>No correlations were found</span>";
htmlString += "</td>";
htmlString += "</tr>";
}
//append to the <tbody>
......@@ -1346,41 +1362,50 @@
let htmlString = "";
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
if (correlations.length !== 0) {
//create the html content for the activity correlation table
for (let i = 0; i < correlations.length; i++) {
let corr = correlations[i];
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
let indices = corr.index;
let value = corr.value;
value = Math.round(value * 100, 1);
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
htmlString += "</td>";
if (value <= 100 && value > 80) {
htmlString += "<tr class='bg-success text-white'>";
} else if (value <= 80 && value > 60) {
htmlString += "<tr class='bg-primary text-white'>";
} else if (value <= 60 && value > 40) {
htmlString += "<tr class='bg-warning text-white'>";
} else if (value <= 40 && value > 20) {
htmlString += "<tr class='bg-danger text-white'>";
} else if (value <= 20 && value > 0) {
htmlString += "<tr class='bg-dark text-white'>";
}
htmlString += "</tr>";
//create a <tr> to be inserted
htmlString += "<td>";
htmlString += indices[0];
htmlString += "</td>";
htmlString += "<td>";
htmlString += indices[1];
htmlString += "</td>";
htmlString += "<td>";
htmlString += value;
}
} else {
htmlString += "<tr>";
htmlString += "<td colspan='3'>";
htmlString += "<span class='font-italic'>No correlations were found</span>";
htmlString += "</td>";
htmlString += "</tr>";
}
//append to the <tbody>
$('#student_emotion_gaze_corr_tbody').append(htmlString);
......
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