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

Merge branch 'monitoring_student_behavior_IT17138000' into 'QA_RELEASE'

Monitoring student behavior it17138000

See merge request !20
parents d4597493 2eab3f22
"""
this file is responsible for creating the API classes so that
frontend could communicate with the backend, through JSON-based communication
each class is extended by djangorestframework APIVIEW class
each class contains methods to represent the HTTP methods received through the requests
in this case the GET method was mostly used.
each method will return an HttpResponse that allows its data to be rendered into
arbitrary media types.
"""
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
......@@ -5,9 +20,6 @@ from MonitorLecturerApp.models import LectureRecordedVideo, LecturerVideoMetaDat
from MonitorLecturerApp.serializers import LectureRecordedVideoSerializer, LecturerVideoMetaDataSerializer
from .MongoModels import *
from rest_framework.views import *
from .ImageOperations import saveImage
from .logic import head_pose_estimation
from .logic import video_extraction
from .logic import activity_recognition as ar
from .logic import posenet_calculation as pc
from . import emotion_detector as ed
......@@ -22,55 +34,6 @@ from .serializers import *
import datetime
# to create images
class ImageViewSet(APIView):
def post(self, request):
saveImage(request.data)
return Response({"response": "successful"})
# to perform pose estimation on images
class GazeEstimationViewSet(APIView):
def post(self, request):
response = head_pose_estimation.estimatePose(request.data)
return Response({"response": response})
# to perform video extraction
class VideoExtractionViewSet(APIView):
def get(self, request):
response = video_extraction.getExtractedFrames(request.query_params)
return Response({"response": response})
def post(self, request):
response = video_extraction.VideoExtractor(request.data)
return Response({"response": response})
# lecture emotions view set
class LectureEmotionViewSet(APIView):
def get(self, request):
emotions = LectureEmotionReport.objects.all().order_by('lecture_id')
serializer = LectureEmotionSerializer(emotions, many=True)
return Response({"response": serializer.data})
def post(self, request):
LectureEmotionReport(
lecture_id=request.data["lecture_id"],
happy_perct=request.data["happy_perct"],
sad_perct=request.data["sad_perct"],
angry_perct=request.data["angry_perct"],
surprise_perct=request.data["surprise_perct"],
disgust_perct=request.data["disgust_perct"],
neutral_perct=request.data["neutral_perct"]
).save()
return Response({"response": request.data})
class LectureViewSet(APIView):
def get(self, request):
......@@ -191,20 +154,33 @@ class LectureVideoViewSet(APIView):
status=status.HTTP_400_BAD_REQUEST)
# this API will retrieve a lecture video details
class GetLectureVideoViewSet(APIView):
def get(self, request):
# get the lecturer id from the request
lecturer = request.query_params.get('lecturer')
# get the lecture date from the request
date = request.query_params.get('date')
# get the item number from the request
index = int(request.query_params.get('index'))
# retrieve the lecture video from the db
lecturer_video = LectureVideo.objects.filter(lecturer_id=lecturer, date=date)
# serialize the object
serializer = LectureVideoSerializer(lecturer_video, many=True)
# get the lecture video id
lecture_video_id = serializer.data[0]['lecture_video_id']
print('lecture video id: ', lecture_video_id)
# retrieve the lecture activties exist for the given video
activities = LectureActivity.objects.filter(lecture_video_id__lecture_video_id=lecture_video_id)
# assign the whether there are found lecture activites or not
isActivityFound = (len(activities) > 0)
# return the response
return Response({
"response": serializer.data[index],
"isActivityFound": isActivityFound
......@@ -225,21 +201,22 @@ class GetLectureVideoViewSetForHome(APIView):
# to check whether there is only one lecture video for the query
# if there are more than one, send only the specified lecture video
if len(serializer.data) > 1:
lecture_video_id = serializer.data[counter]['lecture_video_id']
response = serializer.data[counter]
# else, send the only lecture video
else:
lecture_video_id = serializer.data[0]['lecture_video_id']
response = serializer.data[0]
# return the response
return Response({
"response": response
})
# ACTIVITY
##### ACTIVITY section #####
# API for lecture activities
class LectureActivityViewSet(APIView):
......@@ -276,7 +253,7 @@ class GetLectureActivityViewSet(APIView):
})
# API to process lecture activity
# API to process lecture activity and save to DB
class LectureActivityProcess(APIView):
def get(self, request):
......@@ -286,8 +263,6 @@ class LectureActivityProcess(APIView):
self.activity(video_id, percentages)
return Response({"response": True})
def post(self, request):
pass
def activity(self, lec_video_id, percentages):
# lec_video = LectureVideo.objects.filter(lecture_video_id=lec_video_id)
......
"""
this file contain the relevant methods to implement the student emotion recognition logic
main methods include
* the execution of emotion recognition model and saving the results into the database,
* retrieving the emotion recognition details for lectures within a given time period
* calculating the emotion recognition details for each frame, for a given lecture
* calculating the emotion recognition details for frame groups, for a given lecture
* calculating the emotion recognition correlations with the lecturer posture activities
"""
from tensorflow.keras.models import load_model
from time import sleep
from keras.preprocessing.image import img_to_array
......
"""
this file contain the relevant methods to implement the student activity recognition logic
main methods include
* the execution of activity recognition model and saving the results into the database,
* retrieving the activity recognition details for lectures within a given time period
* calculating the activity recognition details for each frame, for a given lecture
* calculating the activity recognition details for frame groups, for a given lecture
* calculating the activity recognition correlations with the lecturer posture activities
"""
import tensorflow as tf
import tensorflow.keras
from PIL import Image, ImageOps
......
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 31 03:00:36 2020
@author: hp
this file contain the relevant methods to implement the student gaze estimation logic
main methods include
* the execution of gaze estimation model and saving the results into the database,
* retrieving the gaze estimation details for lectures within a given time period
* calculating the gaze estimation details for each frame, for a given lecture
* calculating the gaze estimation details for frame groups, for a given lecture
* calculating the gaze estimation correlations with the lecturer posture activities
"""
from decimal import Decimal
from . custom_sorter import *
......
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
</head>
<body>
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog/">Blog</a></li>
</ul>
{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{% extends "FirstApp/base.html" %}
{% block title %}My amazing blog{% endblock %}
{% block content %}
{% for entry in blog_entries %}
<h2>{{ entry.title }}</h2>
<p>{{ entry.body }}</p>
{% endfor %}
{% endblock %}
\ No newline at end of file
{% extends 'FirstApp/template.html' %}
<!DOCTYPE html>
<html lang="en">
<body id="page-top">
<!-- Page Wrapper -->
{% block javascript %}
{% load static %}
<!-- Bootstrap core JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"></script>
<script src="{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<!-- Core plugin JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"></script>
<script type="text/javascript">
const cur_date = new Date().toDateString();
let video_name = '';
$(document).ready(function () {
$('.video_row').click(function () {
video_name = $(this).attr('id');
let video_duration = $(this).attr('data-duration');
let src = "{% static '' %}FirstApp/videos/" + video_name;
//assigning the src
$("video").attr('src', src);
//setting the video details
$('#video_name').text(video_name);
$('#video_duration').text(video_duration);
$('#video_date').text(cur_date);
});
//to handle video extraction button
$('#extractBtn').click(function () {
//run the api
fetch('http://127.0.0.1:8000/videoExtract', {
method: 'POST',
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
"video_name": video_name
})
})
.then((res) => res.json())
.then((out) => alert(out.response))
.catch((error) => alert('this is an error'));
});
});
</script>
{% endblock %}
<div id="wrapper">
<!-- Sidebar -->
<!-- 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 %}
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Video Extractor</h1>
</div>
<!--1st row -->
<div class="row p-2">
<!--first column -->
<div class="col-lg-6">
<!-- Main Video Context -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Main Video</h6>
</div>
<div class="card-body">
<video width="500" height="300" id="first_video" controls>
<source src="{% static '' %}FirstApp/videos/{{ firstVideo.name }}"
type="video/mp4">
Your browser does not support the video tag.
</video>
<table class="table table-borderless table-striped m-1">
<tbody>
<tr>
<td class="font-weight-bold">Name</td>
<td id="video_name">{{ firstVideo.name }}</td>
</tr>
<tr>
<td class="font-weight-bold">Duration</td>
<td id="video_duration">{{ firstVideo.duration }}</td>
</tr>
<tr>
<td class="font-weight-bold">Date</td>
<td id="video_date"></td>
</tr>
</tbody>
</table>
<div class="col-lg-3 p-3">
<button type="button" class="btn btn-outline-primary" id="extractBtn">Extract</button>
</div>
</div>
</div>
</div>
<!--second column -->
<div class="col-lg-6">
<!-- Main Video Context -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">List of Lectures</h6>
</div>
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Video Name</th>
<th>Length</th>
</tr>
</thead>
<tbody>
{% for video in Videos %}
<tr class="video_row" id="{{ video.name }}" data-duration="{{ video.duration }}">
<td>
{{ video.name }}
</td>
<td>{{ video.duration }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
<!-- End of container-fluid -->
</div>
<!-- End of Main Content -->
</div>
<!-- End of Content Wrapper -->
</div>
{% block 'modal' %}
<div class="modal fade" id="gif-body" role="dialog" aria-labelledby="gif-body">
<div class="modal-dialog modal-lg" style="max-width: 1600px; max-height: 800px">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Processing....</h2>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-center">
<img src="{% static 'FirstApp/images/ajax-loader.gif' %}" width="200" height="500"
alt="This is a GIF">
<h5>This might take few seconds...</h5>
</div>
</div>
</div>
</div>
{% endblock %}
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin 2 - Forgot Password</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/sb-admin-2.min.css" rel="stylesheet">
</head>
<body class="bg-gradient-primary">
<div class="container">
<!-- Outer Row -->
<div class="row justify-content-center">
<div class="col-xl-10 col-lg-12 col-md-9">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-6 d-none d-lg-block bg-password-image"></div>
<div class="col-lg-6">
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-2">Forgot Your Password?</h1>
<p class="mb-4">We get it, stuff happens. Just enter your email address below and we'll send you a link to reset your password!</p>
</div>
<form class="user">
<div class="form-group">
<input type="email" class="form-control form-control-user" id="exampleInputEmail" aria-describedby="emailHelp" placeholder="Enter Email Address...">
</div>
<a href="login.html" class="btn btn-primary btn-user btn-block">
Reset Password
</a>
</form>
<hr>
<div class="text-center">
<a class="small" href="register.html">Create an Account!</a>
</div>
<div class="text-center">
<a class="small" href="login.html">Already have an account? Login!</a>
</div>
</div>
</div>
</div>
</div>
</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>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>This is my username{{ username }}</p>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin 2 - Register</title>
{% load static %}
<link href="{% static 'FirstApp/vendor/fontawesome-free/css/all.min.css' %}" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<link href="{% static 'FirstApp/css/sb-admin-2.min.css' %}" rel="stylesheet">
</head>
<body class="bg-gradient-primary">
<script type="text/javascript">
function insert() {
fetch('http://127.0.0.1:8000/register/', {
method: 'POST',
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
"firstName": document.getElementById('exampleFirstName').value,
"lastName": document.getElementById('exampleLastName').value,
"email": document.getElementById('exampleInputEmail').value,
"password": document.getElementById('exampleInputPassword').value
})
})
.then(resposne => resposne.json())
.then(json => {
if (json) {
alert('successfully inserted');
}
}
)
}
</script>
<div class="container">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
<div class="col-lg-7">
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Create an Account!</h1>
</div>
<form action="#" class="user">
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="text" class="form-control form-control-user" id="exampleFirstName" placeholder="First Name">
</div>
<div class="col-sm-6">
<input type="text" class="form-control form-control-user" id="exampleLastName" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<input type="email" class="form-control form-control-user" id="exampleInputEmail" placeholder="Email Address">
</div>
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="password" class="form-control form-control-user" id="exampleInputPassword" placeholder="Password">
</div>
<div class="col-sm-6">
<input type="password" class="form-control form-control-user" id="exampleRepeatPassword" placeholder="Repeat Password">
</div>
</div>
<button type="submit" class="btn btn-primary btn-user btn-block" onclick="insert()">
Register Account
</button>
<hr>
<a href="index.html" class="btn btn-google btn-user btn-block">
<i class="fab fa-google fa-fw"></i> Register with Google
</a>
<a href="index.html" class="btn btn-facebook btn-user btn-block">
<i class="fab fa-facebook-f fa-fw"></i> Register with Facebook
</a>
</form>
<hr>
<div class="text-center">
<a class="small" href="forgot-password.html">Forgot Password?</a>
</div>
<div class="text-center">
<a class="small" href="login.html">Already have an account? Login!</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery/jquery.js' %}"></script>
<script src="{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<!-- Core plugin JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"></script>
<!-- Custom scripts for all pages-->
<script src="{% static 'FirstApp/js/sb-admin-2.min.js' %}"></script>
</body>
</html>
{% extends 'FirstApp/template.html' %}
<!DOCTYPE html>
<html lang="en">
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
<!-- 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 %}
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">{{video_name}}</h1>
<a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>
</div>
<!-- &lt;!&ndash; Content Row &ndash;&gt;-->
<div class="row">
<!-- Earnings (Monthly) Card Example -->
<div class="col-xl-12 col-md-6 mb-4">
<div class="card border-left-primary shadow h-100 py-2">
<div class="card-body">
<div class="row">
<div class="col-3">
<video width="500" height="300" controls>
<source src="{% static '' %}FirstApp/videos/{{video_name}}" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<div class="col-3"></div>
<!--progress bars-->
<!-- showing the percentage for each emotion-->
<div class="col-6">
<h2 class="big font-weight-bold">Emotion Detection</h2>
<h4 class="small font-weight-bold">Anger
<span class="float-right">{{meta.angry_perct}}%</span></h4>
<div class="progress mb-4">
<div class="progress-bar bg-danger" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<h4 class="small font-weight-bold">Happy
<span class="float-right">{{meta.happy_perct}}%</span></h4>
<div class="progress mb-4">
<div class="progress-bar bg-warning" role="progressbar" style="width: 40%" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<h4 class="small font-weight-bold">Sadness
<span class="float-right">{{meta.sad_perct}}%</span></h4>
<div class="progress mb-4">
<div class="progress-bar" role="progressbar" style="width: 60%" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<h4 class="small font-weight-bold">Surprise
<span class="float-right">{{meta.surprise_perct}}%</span></h4>
<div class="progress mb-4">
<div class="progress-bar bg-info" role="progressbar" style="width: 80%" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<h4 class="small font-weight-bold">Neutral
<span class="float-right">{{meta.neutral_perct}}%</span></h4>
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="form-control">
<button type="button" id="test" data-target="#gif-body" data-toggle="modal">Test</button>
</div>
</div>
</div>
<div class="row">
<h2 class="big font-weight-bold">Eye Gaze Estimation</h2>
</div>
<div class="row">
<div class="col-6">
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
<!-- End of container-fluid -->
</div>
<!-- End of Main Content -->
</div>
<!-- End of Content Wrapper -->
</div>
{% block 'modal' %}
<div class="modal fade" id="gif-body" role="dialog" aria-labelledby="gif-body">
<div class="modal-dialog modal-lg" style="max-width: 1600px; max-height: 800px">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Processing....</h2>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body text-center">
<img src="{% static 'FirstApp/images/ajax-loader.gif' %}" width="200" height="500" alt="This is a GIF">
<h5>This might take few seconds...</h5>
</div>
</div>
</div>
</div>
{% endblock %}
</body>
</html>
\ No newline at end of file
"""
- this file will handle the urlpatterns for the 'FirstApp' application
- the 'urlpatterns' variable will contain the list of url patterns exist for this application
- inside this 'list' variable, the 'path' variable will accept the url mappings to be redirected
to an HTML page (view)
- the 'url' will accept the url mappings to be redirected to a RESTful endpoint
"""
from django.urls import path, re_path, include
from django.conf.urls import url
from rest_framework import routers
......@@ -5,29 +19,18 @@ from . import views
from . import api
router = routers.DefaultRouter()
router.register(r'^register', views.RegisterViewSet)
# router.register(r'^createImage', views.ImageViewSet)
urlpatterns = [
path('', views.hello),
path('login', views.loginForm),
path('logout', views.logoutView),
path('register-user', views.register),
path('404', views.view404),
path('401', views.view401),
path('500', views.view500),
path('blank', views.blank),
path('gaze', views.gaze),
path('gaze-process', views.processGaze),
path('pose', views.pose),
path('charts', views.charts),
path('forgot-password', views.forget_password),
path('webcam', views.webcam),
path('template', views.template),
path('base', views.base),
path('child', views.child),
# extractor path
path('extract', views.extractor),
# emotion path
path('emotion', views.emotion_view),
# video results
......@@ -49,9 +52,6 @@ urlpatterns = [
# this is used for activity
path('activity', views.activity),
# tables view
path('tables', views.tables),
# test view (delete later)
path('test', views.test),
......@@ -59,21 +59,6 @@ urlpatterns = [
# user direct view
path('user-direct', views.userDirect),
url(r'^register', views.RegisterViewSet),
# re_path('video/?video_name<str:video_name>', views.video),
url(r'^teachers/', views.teachersList.as_view()),
url(r'^video/', views.video, name='video'),
url(r'^createImage', api.ImageViewSet.as_view()),
# for gaze estimation
url(r'^estimateGaze', api.GazeEstimationViewSet.as_view()),
# for video extraction (POST)
url(r'^videoExtract', api.VideoExtractionViewSet.as_view()),
# for video extraction (GET)
url(r'^videoExtract/(?P<folder_name>\D+)', api.VideoExtractionViewSet.as_view()),
# testing the lecture emotions in the API
url(r'^lecture_emotions', api.LectureEmotionViewSet.as_view()),
# testing the lecture in the API
url(r'^lectures', api.LectureViewSet.as_view()),
......@@ -101,9 +86,10 @@ urlpatterns = [
# lecture video API (to retrieve a lecture)
url(r'^get-lecture-video/$', api.GetLectureVideoViewSet.as_view()),
# lecture video API (to retrieve a lecture)
# lecture video API (to retrieve a lecture video in the lecturer home page)
url(r'^get-lecture-video-for-home/$', api.GetLectureVideoViewSetForHome.as_view()),
##### ACTIVITIES API #####
# lecture activity API (to retrieve lecture activities)
......
"""
this file will contain the function-based views where each function will render its
corresponding view (in other words, the HTML file)
each function will accept one parameter
params:
request - this is the HTTP request sent from the frontend
returns:
render
------
:params
request: the HTTP request received
template_name: path of the HTML template, relative the location of this file
context: the context that needs to be passed into the template
"""
from django.shortcuts import render, redirect
from django.contrib.auth import (
authenticate,
......@@ -23,90 +47,10 @@ import os
from datetime import datetime
# hashing
from django.contrib.auth.hashers import make_password
# Create your views here.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class teachersList(APIView):
def get(self, request):
teachers = Teachers.objects.all()
serializer = TeachersSerializer(teachers, many=True)
return Response(serializer.data)
def post(self):
pass
class RegisterViewSet(viewsets.ModelViewSet):
queryset = RegisterUser.objects.all().order_by('firstName')
serializer_class = RegisterUserSerializer
# to create images
class ImageViewSet(APIView):
def post(self, request):
saveImage(request.data)
return Response({"response": "successful"})
# to perform pose estimation on images
class GazeEstimationViewSet(APIView):
def post(self, request):
response = head_pose_estimation.estimatePose(request.data)
return Response({"response": response})
# to perform video extraction
class VideoExtractionViewSet(APIView):
def get(self, request):
response = video_extraction.getExtractedFrames(request.query_params)
return Response({"response": response})
def post(self, request):
response = video_extraction.VideoExtractor(request.data)
return Response({"response": response})
# lecture emotions view set
class LectureEmotionViewSet(APIView):
def get(self, request):
emotions = LectureEmotionReport.objects.all().order_by('lecture_id')
serializer = LectureEmotionSerializer(emotions, many=True)
return Response({"response": serializer.data})
def post(self, request):
LectureEmotionReport(
lecture_id=request.data["lecture_id"],
happy_perct=request.data["happy_perct"],
sad_perct=request.data["sad_perct"],
angry_perct=request.data["angry_perct"],
surprise_perct=request.data["surprise_perct"],
disgust_perct=request.data["disgust_perct"],
neutral_perct=request.data["neutral_perct"]
).save()
return Response({"response": request.data})
class LectureViewSet(APIView):
def get(self, request):
lectures = Lecture.objects.all().order_by('date')
serializer = LectureSerializer(lectures, many=True)
return Response(serializer.data)
def post(self, request):
Lecture(
lecture_id=request.data['lecture_id']
).save()
return Response({"response": request})
####### VIEWS ######
@login_required(login_url='/user-direct')
......@@ -181,21 +125,7 @@ def hello(request):
videoPaths = [os.path.join(folder, file) for file in os.listdir(folder)]
videos = []
durations = []
#
# for videoPath in videoPaths:
# video = Video()
# cap = cv2.VideoCapture(videoPath)
# fps = cap.get(cv2.CAP_PROP_FPS) # OpenCV2 version 2 used "CV_CAP_PROP_FPS"
# frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# duration = int(frame_count / fps)
# durations.append(duration)
# videoName = os.path.basename(videoPath)
# # videoName = videos.append(os.path.basename(videoPath))
# durationObj = datetime.timedelta(seconds=duration)
# video.path = videoPath
# video.name = videoName
# video.duration = str(durationObj)
# videos.append(video)
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)
......@@ -214,10 +144,6 @@ def view404(request):
def view401(request):
return render(request, 'FirstApp/401.html')
# querying the database
def blank(request):
emotions = LectureEmotionReport.objects.all().order_by('lecture_id')
return render(request, 'FirstApp/blank.html', {'details': emotions})
@login_required(login_url='/user-direct')
def gaze(request):
......@@ -250,134 +176,15 @@ def gaze(request):
{"lecturer_subjects": lecturer_subjects, "subjects": subject_list, "lecturer": lecturer})
# to redirect to the gaze interface
def processGaze(request):
print('My name is Ishan')
images = request.session.get('images', default='')
imageList = images.split(',')
for i in imageList:
print(i)
return redirect('/')
# the corresponding view for pose estimation
@login_required(login_url='/user-direct')
def pose(request):
try:
# retrieving data from the db
lecturer = request.session['lecturer']
lecturer_subjects = LecturerSubject.objects.filter(lecturer_id_id=lecturer)
lec_sub_serilizer = LecturerSubjectSerializer(lecturer_subjects, many=True)
subject_list = []
subjects = lec_sub_serilizer.data[0]['subjects']
for sub in subjects:
subject = Subject.objects.filter(id=sub)
subject_serialized = SubjectSerializer(subject, many=True)
subject_list.append(subject_serialized.data)
except Exception as exc:
return redirect('/500')
return render(request, "FirstApp/pose.html",
{"lecturer_subjects": lecturer_subjects, "subjects": subject_list, "lecturer": lecturer})
def charts(request):
return render(request, 'FirstApp/charts.html')
def forget_password(request):
return render(request, 'FirstApp/forgot-password.html')
def loginForm(request):
return render(request, 'FirstApp/login.html')
def register(request):
return render(request, 'FirstApp/register.html')
def webcam(request):
video = cv2.VideoCapture(os.path.join(BASE_DIR, 'static//FirstApp//videos//Classroom_video.mp4'))
while (True):
cap, frame = video.read()
cv2.imshow("Frame", frame)
if (cv2.waitKey(1) & 0XFF == ord('q')):
break
video.release()
cv2.destroyAllWindows()
# video = cv2.imread('D://SLIIT/Year 4//Sample Projects//django_project//DemoProject//static//FirstApp/videos/Classroom_video.mp4')
return redirect('/')
# to process video for emotion detection
@login_required(login_url='/user-direct')
def video(request):
title = 'Student and Lecturer Performance Enhancement System'
video_name = request.GET.get('video_name')
video_url = os.path.join(BASE_DIR, os.path.join('static\\FirstApp\\videos\\{0}'.format(video_name)))
meta_data = detect_emotion(video_url)
# meta_data = VideoMeta()
# calculating the respective percentages
meta_data.calcPercentages()
context = {'title': title, 'video_name': video_name, 'url': video_url, 'meta': meta_data}
return render(request, 'FirstApp/video.html', context)
# extractor view
@login_required(login_url='/user-direct')
def extractor(request):
folder = os.path.join(BASE_DIR, os.path.join('static\\FirstApp\\videos'))
videoPaths = [os.path.join(folder, file) for file in os.listdir(folder)]
videos = []
durations = []
# setting up the first video details
first_video_path = videoPaths[0]
first_video = Video()
cap = cv2.VideoCapture(first_video_path)
fps = cap.get(cv2.CAP_PROP_FPS) # OpenCV2 version 2 used "CV_CAP_PROP_FPS"
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = int(frame_count / fps)
videoName = os.path.basename(first_video_path)
durationObj = datetime.timedelta(seconds=duration)
first_video.path = first_video_path
first_video.name = videoName
first_video.duration = str(durationObj)
for videoPath in videoPaths:
video = Video()
cap = cv2.VideoCapture(videoPath)
fps = cap.get(cv2.CAP_PROP_FPS) # OpenCV2 version 2 used "CV_CAP_PROP_FPS"
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = int(frame_count / fps)
durations.append(duration)
videoName = os.path.basename(videoPath)
durationObj = datetime.timedelta(seconds=duration)
video.path = videoPath
video.name = videoName
video.duration = str(durationObj)
videos.append(video)
context = {'Videos': videos, 'firstVideo': first_video, 'durations': durations, 'template_name': 'FirstApp/template.html'}
return render(request, 'FirstApp/extractor.html', context)
def template(request):
obj = {'Message': 'Student and Lecturer Performance Enhancement System'}
return render(request, 'FirstApp/template.html', {'template_name': 'FirstApp/template.html', 'object': obj})
def base(request):
return render(request, 'FirstApp/base.html')
def child(request):
return render(request, 'FirstApp/child.html', {'template_name': 'FirstApp/base.html'})
# displaying video results
@login_required(login_url='/user-direct')
......@@ -546,10 +353,6 @@ def view500(request):
return render(request, "FirstApp/500.html")
# tables page
def tables(request):
return render(request, "FirstApp/tables.html")
@login_required(login_url='/user-direct')
def activity(request):
......
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