Commit 098788f4 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 !35
parents f7621cbd a7659974
...@@ -140,13 +140,45 @@ class LectureVideoViewSet(APIView): ...@@ -140,13 +140,45 @@ class LectureVideoViewSet(APIView):
return Response(serializer.data) return Response(serializer.data)
def post(self, request): def post(self, request):
# get the request data
# data = request.data
#
# # retrieve the last lecture video details
# last_lec_video = LectureVideo.objects.order_by('lecture_video_id').last()
# # create the next lecture video id
# new_lecture_video_id = ig.generate_new_id(last_lec_video.lecture_video_id)
#
# # create the new lecture video
# LectureVideo(
# lecture_video_id=new_lecture_video_id,
# lecturer_id=data['lecturer_id'],
# subject_id=data['subject_id'],
# video_name=data['video_name'],
# video_length=data['video_length'],
# date=data['date']
# ).save()
#
# # return the successful response
# return Response({
# "response": "Successfully created",
#
# }, status=status.HTTP_201_CREATED)
# serializer = LectureVideoSerializer(data=request.data, many=True)
serializer = LectureVideoSerializer(data=request.data) serializer = LectureVideoSerializer(data=request.data)
# serializer.create(validated_data=request.data)
if serializer.is_valid(raise_exception=ValueError): if serializer.is_valid(raise_exception=ValueError):
print('valid')
serializer.create(validated_data=request.data) serializer.create(validated_data=request.data)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.error_messages,
status=status.HTTP_400_BAD_REQUEST) # return Response(serializer.error_messages,
# status=status.HTTP_400_BAD_REQUEST)
# this API will retrieve a lecture video details # this API will retrieve a lecture video details
......
...@@ -1007,6 +1007,7 @@ def get_gaze_correlations(individual_lec_gaze, lec_recorded_activity_data): ...@@ -1007,6 +1007,7 @@ def get_gaze_correlations(individual_lec_gaze, lec_recorded_activity_data):
# this variable will be used to store the correlations # this variable will be used to store the correlations
correlations = [] correlations = []
# limit = 10 # limit = 10
limit = len(individual_lec_gaze) limit = len(individual_lec_gaze)
......
...@@ -18,8 +18,12 @@ there are two fields inside "Meta" class, as follows. ...@@ -18,8 +18,12 @@ there are two fields inside "Meta" class, as follows.
from rest_framework import serializers from rest_framework import serializers
from djongo import models
from .MongoModels import * from .MongoModels import *
from . models import VideoMeta from . models import VideoMeta
from .logic import id_generator as ig
# from datetime import datetime as dt
import datetime
# lecture serializer # lecture serializer
...@@ -190,6 +194,110 @@ class LectureVideoSerializer(serializers.ModelSerializer): ...@@ -190,6 +194,110 @@ class LectureVideoSerializer(serializers.ModelSerializer):
model = LectureVideo model = LectureVideo
fields = '__all__' fields = '__all__'
# this method will validate the input data
def to_internal_value(self, data):
lecturer = None
subject = None
lecturer_data = data.get('lecturer')
subject_data = data.get('subject')
# serialize the lecturer data
lecturer = Lecturer.objects.filter(id=lecturer_data)
subject = Subject.objects.filter(id=subject_data)
lecturer_ser_data = LecturerSerializer(lecturer, many=True).data[0]
subject_ser_data = SubjectSerializer(subject, many=True).data[0]
# retrieve the last lecture video details
last_lec_video = LectureVideo.objects.order_by('lecture_video_id').last()
# create the next lecture video id
new_lecture_video_id = ig.generate_new_id(last_lec_video.lecture_video_id)
# if both subject and lecturer details are available
if len(lecturer) == 1 & len(subject) == 1:
str_video_length = data.get('video_length')
video_length_parts = str_video_length.split(':')
video_length = datetime.timedelta(minutes=int(video_length_parts[0]), seconds=int(video_length_parts[1]),
milliseconds=int(video_length_parts[2]))
# this data will be passed as validated data
validated_data = {
'lecture_video_id': new_lecture_video_id,
'lecturer': lecturer_ser_data,
'subject': subject_ser_data,
'date': data.get('date'),
'video_name': data.get('video_name'),
'video_length': video_length
}
return super(LectureVideoSerializer, self).to_internal_value(validated_data)
# this method will override the 'create' method
def create(self, validated_data):
lecturer = None
subject = None
lecturer_data = validated_data.pop('lecturer')
subject_data = validated_data.pop('subject')
# serialize the lecturer data
lecturer = Lecturer.objects.filter(id=lecturer_data)
subject = Subject.objects.filter(id=subject_data)
# retrieve the last lecture video details
last_lec_video = LectureVideo.objects.order_by('lecture_video_id').last()
# create the next lecture video id
new_lecture_video_id = ig.generate_new_id(last_lec_video.lecture_video_id)
# if both subject and lecturer details are available
if len(lecturer) == 1 & len(subject) == 1:
str_video_length = validated_data.pop('video_length')
video_length_parts = str_video_length.split(':')
video_length = datetime.timedelta(minutes=int(video_length_parts[0]), seconds=int(video_length_parts[1]), milliseconds=int(video_length_parts[2]))
lecture_video, created = LectureVideo.objects.update_or_create(
lecture_video_id=new_lecture_video_id,
lecturer=lecturer[0],
subject=subject[0],
date=validated_data.pop('date'),
video_name=validated_data.pop('video_name'),
video_length=video_length
)
# faculty_data = validated_data.pop('faculty')
# serialized_faculty = FacultySerializer(data=faculty_data)
#
# if (serialized_faculty.is_valid()):
# # faculty, faculty_created = Faculty.objects.get_or_create(defaults={}, faculty_id=serialized_faculty.data['faculty_id'])
# faculty = Faculty.objects.filter(faculty_id=serialized_faculty.data['faculty_id'])
#
# if (len(faculty) == 1):
# lecturer, created = Lecturer.objects.update_or_create(
# faculty=faculty[0],
# lecturer_id=validated_data.pop('lecturer_id'),
# fname=validated_data.pop('fname'),
# lname=validated_data.pop('lname'),
# email=validated_data.pop('email'),
# telephone=validated_data('telephone')
# )
#
# return lecturer
#
return lecture_video
return None
# lecture video time landmarks serializer # lecture video time landmarks serializer
class LectureVideoTimeLandmarksSerializer(serializers.ModelSerializer): class LectureVideoTimeLandmarksSerializer(serializers.ModelSerializer):
......
...@@ -49,15 +49,21 @@ ...@@ -49,15 +49,21 @@
{# <div class="sidebar-brand-icon rotate-n-15">#} {# <div class="sidebar-brand-icon rotate-n-15">#}
{# <i class="fas fa-laugh-wink"></i>#} {# <i class="fas fa-laugh-wink"></i>#}
{# </div>#} {# </div>#}
{# <div class="sidebar-brand-icon">#}
{# <i class="fas fa-chalkboard-teacher"></i>#}
{# </div>#}
{% if request.session.user_type == "Lecturer" %}
<div class="sidebar-brand-icon"> <div class="sidebar-brand-icon">
<i class="fas fa-chalkboard-teacher"></i> <i class="fas fa-chalkboard-teacher"></i>
</div> </div>
{% if request.session.user_type == "Lecturer" %}
<div class="sidebar-brand-text mx-3">SLPES Lecturer</div> <div class="sidebar-brand-text mx-3">SLPES Lecturer</div>
{% endif %} {% endif %}
{% if request.session.user_type == "Admin" %} {% if request.session.user_type == "Admin" %}
<div class="sidebar-brand-icon">
<i class="fa fa-user" aria-hidden="true"></i>
</div>
<div class="sidebar-brand-text mx-3">SLPES Admin</div> <div class="sidebar-brand-text mx-3">SLPES Admin</div>
{% endif %} {% endif %}
</a> </a>
......
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