Commit 539497be authored by I.K Seneviratne's avatar I.K Seneviratne

Committing the addition of 401 page and full implementation of saving...

Committing the addition of 401 page and full implementation of saving activity, emotion and gaze estimations through a single process.
parent 745c0fb3
...@@ -300,7 +300,7 @@ class LectureEmotionFrameRecognitions(models.Model): ...@@ -300,7 +300,7 @@ class LectureEmotionFrameRecognitions(models.Model):
# POSE section # POSE section
# lecture pose estimation # lecture gaze estimation
class LectureGazeEstimation(models.Model): class LectureGazeEstimation(models.Model):
lecture_gaze_id = models.CharField(max_length=10) lecture_gaze_id = models.CharField(max_length=10)
lecture_video_id = models.ForeignKey(LectureVideo, on_delete=models.CASCADE) lecture_video_id = models.ForeignKey(LectureVideo, on_delete=models.CASCADE)
......
...@@ -300,7 +300,6 @@ class LectureActivityProcess(APIView): ...@@ -300,7 +300,6 @@ class LectureActivityProcess(APIView):
LectureActivity( LectureActivity(
lecture_activity_id=new_lecture_activity_id, lecture_activity_id=new_lecture_activity_id,
lecture_video_id_id=lec_video_id, lecture_video_id_id=lec_video_id,
talking_perct=percentages['talking_perct'],
phone_perct=percentages['phone_perct'], phone_perct=percentages['phone_perct'],
listening_perct=percentages['listening_perct'], listening_perct=percentages['listening_perct'],
writing_perct=percentages['writing_perct'] writing_perct=percentages['writing_perct']
...@@ -473,16 +472,18 @@ class LectureEmotionProcess(APIView): ...@@ -473,16 +472,18 @@ class LectureEmotionProcess(APIView):
pass pass
def save_emotion_report(self, lec_video_id, percentages): def save_emotion_report(self, lec_video_id, percentages):
lec_video = LectureVideo.objects.get(lecture_video_id=lec_video_id) lec_video = LectureVideo.objects.filter(lecture_video_id=lec_video_id)
lec_video_serializer = LectureVideoSerializer(lec_video, many=True) lec_video_serializer = LectureVideoSerializer(lec_video, many=True)
lec_video_data = lec_video_serializer.data[0] lec_video_data = lec_video_serializer.data[0]
last_lec_emotion = LectureEmotionReport.objects.order_by('lecture_emotion_id').last() last_lec_emotion = LectureEmotionReport.objects.order_by('lecture_emotion_id').last()
new_lecture_emotion_id = ig.generate_new_id(last_lec_emotion.lecture_emotion_id) new_lecture_emotion_id = ig.generate_new_id(last_lec_emotion.lecture_emotion_id)
lecture_video_id = lec_video_data['id']
# creating a new lecture emotion report # creating a new lecture emotion report
LectureEmotionReport( LectureEmotionReport(
lecture_emotion_id=new_lecture_emotion_id, lecture_emotion_id=new_lecture_emotion_id,
lecture_video_id=lec_video, lecture_video_id_id=lecture_video_id,
happy_perct=percentages.happy_perct, happy_perct=percentages.happy_perct,
sad_perct=percentages.sad_perct, sad_perct=percentages.sad_perct,
angry_perct=percentages.angry_perct, angry_perct=percentages.angry_perct,
...@@ -685,17 +686,23 @@ class ProcessLectureGazeEstimation(APIView): ...@@ -685,17 +686,23 @@ class ProcessLectureGazeEstimation(APIView):
pass pass
def estimate_gaze(self, lec_video_id, percentages): def estimate_gaze(self, lec_video_id, percentages):
lec_video = LectureVideo.objects.get(lecture_video_id=lec_video_id) lec_video = LectureVideo.objects.filter(lecture_video_id=lec_video_id)
last_lec_gaze = LectureGazeEstimation.objects.order_by('lecture_gaze_id').last() last_lec_gaze = LectureGazeEstimation.objects.order_by('lecture_gaze_id').last()
lec_video_serializer = LectureVideoSerializer(lec_video, many=True) lec_video_serializer = LectureVideoSerializer(lec_video, many=True)
lec_video_data = lec_video_serializer.data[0] lec_video_data = lec_video_serializer.data[0]
new_lecture_gaze_id = "LG000001" if (last_lec_gaze is None) else ig.generate_new_id( new_lecture_gaze_id = "LG000001" if (last_lec_gaze is None) else ig.generate_new_id(
last_lec_gaze.lecture_gaze_id) last_lec_gaze.lecture_gaze_id)
new_lecture_gaze_primary_id = 1 if (last_lec_gaze is None) else int(last_lec_gaze.id) + 1
# get the video id
lecture_video_id = lec_video_data['id']
# creating a new lecture gaze estimation # creating a new lecture gaze estimation
LectureGazeEstimation( LectureGazeEstimation(
id=new_lecture_gaze_primary_id,
lecture_gaze_id=new_lecture_gaze_id, lecture_gaze_id=new_lecture_gaze_id,
lecture_video_id=lec_video, lecture_video_id_id=lecture_video_id,
looking_up_and_right_perct=percentages['head_up_right_perct'], looking_up_and_right_perct=percentages['head_up_right_perct'],
looking_up_and_left_perct=percentages['head_up_left_perct'], looking_up_and_left_perct=percentages['head_up_left_perct'],
looking_down_and_right_perct=percentages['head_down_right_perct'], looking_down_and_right_perct=percentages['head_down_right_perct'],
...@@ -723,7 +730,7 @@ class GetLectureGazeEstimationViewSet(APIView): ...@@ -723,7 +730,7 @@ class GetLectureGazeEstimationViewSet(APIView):
lecture_video_id = request.query_params.get('lecture_video_id') lecture_video_id = request.query_params.get('lecture_video_id')
lecture_video_name = request.query_params.get('lecture_video_name') lecture_video_name = request.query_params.get('lecture_video_name')
# retrieve the extracted frames # retrieve the extracted frames
extracted = hge.getExtractedFrames(lecture_video_name) # extracted = hge.getExtractedFrames(lecture_video_name)
lecture_gaze_estimations = LectureGazeEstimation.objects.filter( lecture_gaze_estimations = LectureGazeEstimation.objects.filter(
lecture_video_id__lecture_video_id=lecture_video_id) lecture_video_id__lecture_video_id=lecture_video_id)
...@@ -731,7 +738,7 @@ class GetLectureGazeEstimationViewSet(APIView): ...@@ -731,7 +738,7 @@ class GetLectureGazeEstimationViewSet(APIView):
return Response({ return Response({
"response": serializer.data, "response": serializer.data,
"extracted": extracted # "extracted": extracted
}) })
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import os import os
import cv2 import cv2
import shutil import shutil
import datetime # import datetime
from datetime import timedelta
from FirstApp.MongoModels import * from FirstApp.MongoModels import *
from FirstApp.serializers import * from FirstApp.serializers import *
...@@ -94,7 +95,7 @@ def getTimeLandmarks(video_name): ...@@ -94,7 +95,7 @@ def getTimeLandmarks(video_name):
THRESHOLD_GAP = 5 THRESHOLD_GAP = 5
# calculating the real duration # calculating the real duration
real_duration = datetime.timedelta(seconds=(duration+THRESHOLD_GAP)) real_duration = timedelta(seconds=(duration))
# defines the number of seconds included for a frame group # defines the number of seconds included for a frame group
THRESHOLD_TIME = 10 THRESHOLD_TIME = 10
...@@ -112,7 +113,7 @@ def getTimeLandmarks(video_name): ...@@ -112,7 +113,7 @@ def getTimeLandmarks(video_name):
# loop through the threshold gap limit to define the time landmarks # loop through the threshold gap limit to define the time landmarks
for i in range(THRESHOLD_GAP): for i in range(THRESHOLD_GAP):
initial_landmark += unit_gap initial_landmark += unit_gap
time_landmark = str(datetime.timedelta(seconds=initial_landmark)) time_landmark = str(timedelta(seconds=initial_landmark))
time_landmark_value = initial_landmark time_landmark_value = initial_landmark
time_landmarks.append(time_landmark) time_landmarks.append(time_landmark)
time_landmarks_values.append(time_landmark_value) time_landmarks_values.append(time_landmark_value)
...@@ -204,6 +205,9 @@ def getFrameLandmarks(video_name, category): ...@@ -204,6 +205,9 @@ def getFrameLandmarks(video_name, category):
# this section will handle some database operations # this section will handle some database operations
def save_time_landmarks(video_name): def save_time_landmarks(video_name):
# for testing purposes
print('starting the saving time landmarks process')
last_lec_video_time_landmarks = LectureVideoTimeLandmarks.objects.order_by('lecture_video_time_landmarks_id').last() last_lec_video_time_landmarks = LectureVideoTimeLandmarks.objects.order_by('lecture_video_time_landmarks_id').last()
new_lecture_video_time_landmarks_id = "LVTL00001" if (last_lec_video_time_landmarks is None) else \ new_lecture_video_time_landmarks_id = "LVTL00001" if (last_lec_video_time_landmarks is None) else \
ig.generate_new_id(last_lec_video_time_landmarks.lecture_video_time_landmarks_id) ig.generate_new_id(last_lec_video_time_landmarks.lecture_video_time_landmarks_id)
...@@ -233,12 +237,18 @@ def save_time_landmarks(video_name): ...@@ -233,12 +237,18 @@ def save_time_landmarks(video_name):
new_lec_video_time_landmarks.lecture_video_id_id = lec_video_id new_lec_video_time_landmarks.lecture_video_id_id = lec_video_id
new_lec_video_time_landmarks.time_landmarks = db_time_landmarks new_lec_video_time_landmarks.time_landmarks = db_time_landmarks
# for testing purposes
print('ending the saving time landmarks process')
new_lec_video_time_landmarks.save() new_lec_video_time_landmarks.save()
# this method will save frame landmarks to the database # this method will save frame landmarks to the database
def save_frame_landmarks(video_name): def save_frame_landmarks(video_name):
# for testing purposes
print('starting the saving frame landmarks process')
# retrieve the previous lecture video frame landmarks details # retrieve the previous lecture video frame landmarks details
last_lec_video_frame_landmarks = LectureVideoFrameLandmarks.objects.order_by( last_lec_video_frame_landmarks = LectureVideoFrameLandmarks.objects.order_by(
'lecture_video_frame_landmarks_id').last() 'lecture_video_frame_landmarks_id').last()
...@@ -271,6 +281,9 @@ def save_frame_landmarks(video_name): ...@@ -271,6 +281,9 @@ def save_frame_landmarks(video_name):
new_lec_video_frame_landmarks.save() new_lec_video_frame_landmarks.save()
# for testing purposes
print('ending the saving frame landmarks process')
# now return the frame landmarks and the frame group dictionary # now return the frame landmarks and the frame group dictionary
return frame_landmarks, frame_group_dict return frame_landmarks, frame_group_dict
......
{% extends 'FirstApp/template.html' %}
<!DOCTYPE html>
<html lang="en">
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Begin Page Content -->
{% block 'container-fluid' %}
<div class="container-fluid">
{% load static %}
<!-- 404 Error Text -->
<div class="text-center">
<div class="error mx-auto" data-text="404">401</div>
<p class="lead text-gray-800 mb-5">Unauthorized access</p>
<p class="text-gray-500 mb-0">It looks like you do not have access to this url</p>
<p class="text-gray-500 mb-0">Please login with the correct user type</p>
<a href="/logout">&larr; Back to Login Page</a>
</div>
</div>
{% endblock %}
<!--end of container-fluid -->
</div>
<!-- End of Main Content -->
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright &copy; Your Website 2019</span>
</div>
</div>
</footer>
<!-- End of Footer -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<a class="btn btn-primary" href="login.html">Logout</a>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>
</body>
</html>
...@@ -216,6 +216,7 @@ ...@@ -216,6 +216,7 @@
//to handle the 'btn-success' (process) button //to handle the 'btn-success' (process) button
$(document).on('click', '.btn-success', function (e) { $(document).on('click', '.btn-success', function (e) {
//sending the POST request to process the lecture activities //sending the POST request to process the lecture activities
fetch('http://127.0.0.1:8000/process-lecture-emotion/?lecture_video_name=' + global_video_name + '&lecture_video_id=' + global_lecture_video_id) fetch('http://127.0.0.1:8000/process-lecture-emotion/?lecture_video_name=' + global_video_name + '&lecture_video_id=' + global_lecture_video_id)
.then((res) => res.json()) .then((res) => res.json())
......
...@@ -66,6 +66,8 @@ ...@@ -66,6 +66,8 @@
Interface Interface
</div> </div>
{% if request.session.user_type == "Lecturer" %}
<!-- Nav Item - Pages Collapse Menu --> <!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item"> <li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo"> <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
...@@ -83,6 +85,7 @@ ...@@ -83,6 +85,7 @@
</div> </div>
</li> </li>
<!-- Nav Item - Pages Collapse Menu --> <!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item"> <li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseThree" aria-expanded="true" aria-controls="collapseThree"> <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseThree" aria-expanded="true" aria-controls="collapseThree">
...@@ -97,6 +100,8 @@ ...@@ -97,6 +100,8 @@
</div> </div>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseFour" aria-expanded="true" aria-controls="collapseThree"> <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseFour" aria-expanded="true" aria-controls="collapseThree">
<i class="fas fa-fw fa-cog"></i> <i class="fas fa-fw fa-cog"></i>
...@@ -127,6 +132,8 @@ ...@@ -127,6 +132,8 @@
</div> </div>
</li> </li>
{% endif %}
<!-- Divider --> <!-- Divider -->
<hr class="sidebar-divider"> <hr class="sidebar-divider">
...@@ -178,6 +185,8 @@ ...@@ -178,6 +185,8 @@
</div> </div>
</ul> </ul>
<!-- End of Sidebar --> <!-- End of Sidebar -->
<div id="content-wrapper" class="d-flex flex-column"> <div id="content-wrapper" class="d-flex flex-column">
......
...@@ -14,6 +14,7 @@ urlpatterns = [ ...@@ -14,6 +14,7 @@ urlpatterns = [
path('logout', views.logoutView), path('logout', views.logoutView),
path('register-user', views.register), path('register-user', views.register),
path('404', views.view404), path('404', views.view404),
path('401', views.view401),
path('500', views.view500), path('500', views.view500),
path('blank', views.blank), path('blank', views.blank),
path('gaze', views.gaze), path('gaze', views.gaze),
......
...@@ -109,13 +109,18 @@ class LectureViewSet(APIView): ...@@ -109,13 +109,18 @@ class LectureViewSet(APIView):
####### VIEWS ###### ####### VIEWS ######
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def hello(request): def hello(request):
try:
username = request.user.username username = request.user.username
# retrieve the lecturer # retrieve the lecturer
lecturer = request.session['lecturer'] lecturer = request.session['lecturer']
user_type = request.session['user_type']
print('user_type: ', user_type)
# retrieve the lecturer's timetable slots # retrieve the lecturer's timetable slots
lecturer_timetable = FacultyTimetable.objects.filter() lecturer_timetable = FacultyTimetable.objects.filter()
...@@ -194,15 +199,27 @@ def hello(request): ...@@ -194,15 +199,27 @@ def hello(request):
context = {'object': obj, 'Videos': videos, 'durations': durations, 'template_name': 'FirstApp/template.html', 'lecturer_details': lecturer_details, "lecturer": lecturer} context = {'object': obj, 'Videos': videos, 'durations': durations, 'template_name': 'FirstApp/template.html', 'lecturer_details': lecturer_details, "lecturer": lecturer}
return render(request, 'FirstApp/Home.html', context) return render(request, 'FirstApp/Home.html', context)
# in case of keyerror exception
except KeyError as exc:
return redirect('/401')
except Exception as exc:
return redirect('/500')
# this method will handle 404 error page
def view404(request): def view404(request):
return render(request, 'FirstApp/404.html') return render(request, 'FirstApp/404.html')
# this page will handle 401 error page
def view401(request):
return render(request, 'FirstApp/401.html')
# querying the database # querying the database
def blank(request): def blank(request):
emotions = LectureEmotionReport.objects.all().order_by('lecture_id') emotions = LectureEmotionReport.objects.all().order_by('lecture_id')
return render(request, 'FirstApp/blank.html', {'details': emotions}) return render(request, 'FirstApp/blank.html', {'details': emotions})
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def gaze(request): def gaze(request):
try: try:
...@@ -221,6 +238,11 @@ def gaze(request): ...@@ -221,6 +238,11 @@ def gaze(request):
subject_list.append(subject_serialized.data) subject_list.append(subject_serialized.data)
# handling the keyError
except KeyError as exc:
return redirect('/401')
# handling the general exceptions
except Exception as exc: except Exception as exc:
return redirect('/500') return redirect('/500')
...@@ -240,7 +262,7 @@ def processGaze(request): ...@@ -240,7 +262,7 @@ def processGaze(request):
# the corresponding view for pose estimation # the corresponding view for pose estimation
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def pose(request): def pose(request):
try: try:
...@@ -295,7 +317,7 @@ def webcam(request): ...@@ -295,7 +317,7 @@ def webcam(request):
return redirect('/') return redirect('/')
# to process video for emotion detection # to process video for emotion detection
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def video(request): def video(request):
title = 'Student and Lecturer Performance Enhancement System' title = 'Student and Lecturer Performance Enhancement System'
video_name = request.GET.get('video_name') video_name = request.GET.get('video_name')
...@@ -310,7 +332,7 @@ def video(request): ...@@ -310,7 +332,7 @@ def video(request):
# extractor view # extractor view
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def extractor(request): def extractor(request):
folder = os.path.join(BASE_DIR, os.path.join('static\\FirstApp\\videos')) folder = os.path.join(BASE_DIR, os.path.join('static\\FirstApp\\videos'))
videoPaths = [os.path.join(folder, file) for file in os.listdir(folder)] videoPaths = [os.path.join(folder, file) for file in os.listdir(folder)]
...@@ -358,7 +380,7 @@ def child(request): ...@@ -358,7 +380,7 @@ def child(request):
return render(request, 'FirstApp/child.html', {'template_name': 'FirstApp/base.html'}) return render(request, 'FirstApp/child.html', {'template_name': 'FirstApp/base.html'})
# displaying video results # displaying video results
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def video_result(request): def video_result(request):
try: try:
...@@ -434,7 +456,11 @@ def video_result(request): ...@@ -434,7 +456,11 @@ def video_result(request):
# append to the list # append to the list
due_lecture_list.append(obj) due_lecture_list.append(obj)
# handling the keyError
except KeyError as exc:
return redirect('/401')
# handling the general exceptions
except Exception as exc: except Exception as exc:
print('what is wrong?: ', exc) print('what is wrong?: ', exc)
return redirect('/500') return redirect('/500')
...@@ -444,7 +470,7 @@ def video_result(request): ...@@ -444,7 +470,7 @@ def video_result(request):
# view for emotion page # view for emotion page
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def emotion_view(request): def emotion_view(request):
try: try:
...@@ -463,6 +489,11 @@ def emotion_view(request): ...@@ -463,6 +489,11 @@ def emotion_view(request):
subject_list.append(subject_serialized.data) subject_list.append(subject_serialized.data)
# handling the keyError
except KeyError as exc:
return redirect('/401')
# handling the general exceptions
except Exception as exc: except Exception as exc:
return redirect('/500') return redirect('/500')
...@@ -490,6 +521,7 @@ def loggedInView(request): ...@@ -490,6 +521,7 @@ def loggedInView(request):
login(request, user) login(request, user)
# setting up the session # setting up the session
request.session['lecturer'] = lecturer.id request.session['lecturer'] = lecturer.id
request.session['user_type'] = "Lecturer"
return redirect('/') return redirect('/')
...@@ -519,7 +551,7 @@ def tables(request): ...@@ -519,7 +551,7 @@ def tables(request):
return render(request, "FirstApp/tables.html") return render(request, "FirstApp/tables.html")
@login_required(login_url='/login') @login_required(login_url='/user-direct')
def activity(request): def activity(request):
try: try:
...@@ -538,6 +570,11 @@ def activity(request): ...@@ -538,6 +570,11 @@ def activity(request):
subject_list.append(subject_serialized.data) subject_list.append(subject_serialized.data)
# handling the keyError
except KeyError as exc:
return redirect('/401')
# handling the general exception
except Exception as exc: except Exception as exc:
return redirect('/500') return redirect('/500')
...@@ -593,6 +630,7 @@ def processAdminLogin(request): ...@@ -593,6 +630,7 @@ def processAdminLogin(request):
login(request, user) login(request, user)
# setting up the session # setting up the session
request.session['admin'] = admin.id request.session['admin'] = admin.id
request.session['user_type'] = "Admin"
return redirect('/summary/lecture') return redirect('/summary/lecture')
......
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