Commit 71039e2f authored by SohanDanushka's avatar SohanDanushka

Committing - updating logic files and end-point.

parent 2dfede4d
from rest_framework import status
from rest_framework.views import APIView
from rest_framework.response import Response
......@@ -10,6 +11,33 @@ from .serializers import *
import datetime
##### LECTURER VIDEO SECTION #####
# this API will handle basic lecturer video retrieval/saving
class LecturerVideoAPI(APIView):
def get(self, request):
lecturer_videos = LectureRecordedVideo.objects.all()
lecturer_videos_ser = LectureRecordedVideoSerializer(lecturer_videos, many=True)
lecturer_videos_ser_data = lecturer_videos_ser.data
return Response({
"response": lecturer_videos_ser_data
})
def post(self, request):
serializer = LectureRecordedVideoSerializer(data=request.data)
if serializer.is_valid(raise_exception=ValueError):
# serializer.create(validated_data=request.data)
serializer.create(validated_data=request.data)
return Response(serializer.data, status=status.HTTP_201_CREATED)
##### END OF LECTURER VIDEO SECTION #####
##### LECTURER ACTIVITY SECTION #####
class ActivityRecognitionAPI(APIView):
......@@ -61,6 +89,23 @@ class GetLectureVideoResultsAPI(APIView):
"response": percentages
})
# this API will process lecturer video frame recognitions
class ProcessLecturerFrameRecognitionsAPI(APIView):
def get(self, request):
video_name = request.query_params.get('video_name')
frame_recognitions, fps = classroom_activity.save_frame_recognition(video_name)
int_fps = int(fps)
# print('frame recognitions: ', frame_recognitions)
return Response({
"frame_recognitions": frame_recognitions,
"fps": fps
})
##### END OF LECTURER ACTIVITY SECTION #####
......@@ -169,6 +214,43 @@ class LectureAudioTextAPI(APIView):
})
# this API will save the lecture audio analysis
class ProcessLectureAudioAnalysis(APIView):
def get(self, request):
# lec_audio_text = ta.run()
# (this is temporary)
lec_audio_text = {
'num_of_words': 5000,
'lexical_count': 300,
'non_lexical_count': 40
}
last_lec_audio_text_id = LecturerAudioText.objects.order_by('lecturer_audio_text_id').last()
new_lec_audio_text_id = "LAT001" if (last_lec_audio_text_id is None) else ig.generate_new_id(
last_lec_audio_text_id.lecturer_audio_text_id)
# retrieve the lecture audio summary object (temporary)
lecture_audio_summary = LectureAudioSummary.objects.filter(lecture_audio_summary_id='LAU004_sum')[0]
# save the lecture audio text object
LecturerAudioText(
lecturer_audio_text_id=new_lec_audio_text_id,
lecturer_audio_text_wordcount=lec_audio_text['num_of_words'],
lecturer_audio_text_lexical_wordcount=lec_audio_text['lexical_count'],
lecturer_audio_text_non_lexical_wordcount=lec_audio_text['non_lexical_count'],
lecturer_audio_text_status='Average',
lecturer_audio_original_text=lecture_audio_summary
).save()
return Response({
"response": "success"
}, status=status.HTTP_201_CREATED)
# this API will retrieve lectuer audio summary for given period
class LecturerAudioSummaryPeriodAPI(APIView):
......@@ -250,4 +332,3 @@ class StudentLecturerIntegratedAPI(APIView):
"fps": fps
})
import requests
# this method lists down the main methods that need to be executed when the lecturer performance module is under operation
def lecturer_batch_process(video_name, audio_name):
# As the first step, calculate the lectuer activity details
lecturer_activity_resp = requests.get('http://127.0.0.1:8000/activities/?video_name=' + video_name)
# save the lecturer video frame recognitions
lecturer_video_frame_recognitions_resp = requests.get('http://127.0.0.1:8000/process-lecturer-video-frame-recognitions/?video_name=' + video_name)
# processing the lecture audio
lecture_audio_text_resp = requests.get('http://127.0.0.1:8000/lecturer/process-lecture-audio-analysis')
# this method will save the lecturer video details
def save_lecturer_video_details(video):
lecturer_video_resp = requests.post('http://127.0.0.1:8000/lecturer-video', video)
\ No newline at end of file
......@@ -2,11 +2,11 @@ import scripts
import re
import os
# change the method signature, IMMEDIATELY
def run():
# this dictionary will be returned
analysis = {}
# define the BASE path
BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
FILE_PATH = os.path.join(BASE_PATH, "MonitorLecturerApp\\lecture_Notes\\sample_text2.txt")
......@@ -81,7 +81,7 @@ def run():
lexical_count += d[key]
# print('\n number of occurrences (that)', d[key])
# "jest" newei bn "just"
elif (key == "just"):
lexical_count += d[key]
# print('\n number of occurrences (just)', d[key])
......@@ -210,6 +210,8 @@ def get_lecturer_audio_summary_for_period(lecture_audio_text_data):
# append to the list
individual_lec_data.append(individual_lecture)
#saving processed to the db
return individual_lec_data, labels
\ No newline at end of file
from rest_framework import serializers
from FirstApp.MongoModels import Lecturer, Subject
from FirstApp.serializers import LecturerSerializer, SubjectSerializer
from LectureSummarizingApp.models import LectureAudioSummary
from .models import RegisterTeacher, LecturerActivityFrameRecognitions
from .models import LecturerAudioText, LecturerVideoMetaData, LecturerVideo, LectureRecordedVideo
from FirstApp.logic import id_generator as ig
import datetime
class RegisterTeacherSerializer(serializers.ModelSerializer):
class Meta:
model = RegisterTeacher
......@@ -19,7 +24,6 @@ class LecturerVideoSerializer(serializers.ModelSerializer):
class LecturerAudioTextSerializer(serializers.ModelSerializer):
lecturer_audio_original_text = LectureAudioSummary()
class Meta:
......@@ -28,7 +32,6 @@ class LecturerAudioTextSerializer(serializers.ModelSerializer):
class LectureRecordedVideoSerializer(serializers.ModelSerializer):
lecturer = LecturerSerializer()
subject = SubjectSerializer()
......@@ -36,9 +39,47 @@ class LectureRecordedVideoSerializer(serializers.ModelSerializer):
model = LectureRecordedVideo
fields = '__all__'
# 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 = LectureRecordedVideo.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('lecture_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 = LectureRecordedVideo.objects.update_or_create(
lecture_video_id=new_lecture_video_id,
lecturer=lecturer[0],
subject=subject[0],
lecturer_date=validated_data.pop('lecturer_date'),
lecture_video_name=validated_data.pop('lecture_video_name'),
lecture_video_length=video_length
)
class LecturerVideoMetaDataSerializer(serializers.ModelSerializer):
return lecture_video
return None
class LecturerVideoMetaDataSerializer(serializers.ModelSerializer):
lecturer_video_id = LectureRecordedVideoSerializer()
class Meta:
......@@ -46,16 +87,13 @@ class LecturerVideoMetaDataSerializer(serializers.ModelSerializer):
fields = '__all__'
# lecture activity frame recognition serializer
class LecturerActivityFrameRecognitionsSerializer(serializers.ModelSerializer):
lecturer_meta_id = LecturerVideoMetaDataSerializer()
frame_recognition_details = serializers.SerializerMethodField()
# this method will be used to serialize the 'frame_recogition_details' field
def get_frame_recognition_details(self, obj):
return_data = []
for frame_recognition in obj.frame_recognition_details:
......@@ -71,8 +109,6 @@ class LecturerActivityFrameRecognitionsSerializer(serializers.ModelSerializer):
# return the data
return return_data
class Meta:
model = LecturerActivityFrameRecognitions
fields = '__all__'
......@@ -12,6 +12,10 @@ urlpatterns = [
path('lecture-video', views.lecVideo),
# path('Video', views.hello)
##### LECTURER VIDEO SECTION #####
# API to retrieve/save lecturer video details
url(r'^lecturer-video/$', api.LecturerVideoAPI.as_view()),
##### LECTURER ACTIVITY SECTION #####
# API to retrieve activity recognition
url(r'^activities/$', api.ActivityRecognitionAPI.as_view()),
......@@ -22,18 +26,29 @@ urlpatterns = [
# API to retrieve lecturer video frame recognitions
url(r'^get-lecturer-video-frame-recognitions/$', api.StudentLecturerIntegratedAPI.as_view()),
# API to process lecturer video frame recognitions
url(r'^process-lecturer-video-frame-recognitions/$', api.ProcessLecturerFrameRecognitionsAPI.as_view()),
##### END OF LECTURER ACTIVITY SECTION #####
##### LECTURE AUDIO SECTION #####
# API to retrieve audio analysis
url(r'^get-audio-analysis/$', api.GetLectureAudioAnalysis.as_view()),
# API to save audio analysis
url(r'^process-lecture-audio-analysis/$', api.ProcessLectureAudioAnalysis.as_view()),
# API to retrieve lecture audio text
url(r'^get-lecture-audio-text', api.LectureAudioTextAPI.as_view()),
# API to retrieve lecture audio text
url(r'^get-lecturer-audio-summary-for-period', api.LecturerAudioSummaryPeriodAPI.as_view()),
##### END OF LECTURE AUDIO SECTION #####
# test API
url(r'^test-api', api.TestAPI.as_view()),
......
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