Commit 966e1a42 authored by I.K Seneviratne's avatar I.K Seneviratne

Committing the implementations of the system automation method and new REST...

Committing the implementations of the system automation method and new REST endpoint to invoke that method.
parent 58b6c3fd
...@@ -17,7 +17,7 @@ from MonitorLecturerApp.models import LectureRecordedVideo, LecturerVideoMetaDat ...@@ -17,7 +17,7 @@ from MonitorLecturerApp.models import LectureRecordedVideo, LecturerVideoMetaDat
from MonitorLecturerApp.serializers import LectureRecordedVideoSerializer, LecturerVideoMetaDataSerializer from MonitorLecturerApp.serializers import LectureRecordedVideoSerializer, LecturerVideoMetaDataSerializer
from rest_framework.views import * from rest_framework.views import *
from .logic import activity_recognition as ar from .logic import activity_recognition as ar
from . import emotion_detector as ed from . import emotion_detector as ed, automation_process as ap
from .logic import id_generator as ig from .logic import id_generator as ig
from .logic import pdf_file_generator as pdf from .logic import pdf_file_generator as pdf
from .logic import head_gaze_estimation as hge from .logic import head_gaze_estimation as hge
...@@ -1647,3 +1647,23 @@ class DisplayUpcomingLecturesAPI(APIView): ...@@ -1647,3 +1647,23 @@ class DisplayUpcomingLecturesAPI(APIView):
"subject_code": subject_code, "subject_code": subject_code,
}) })
# this API will handle all the batch processes and video/audio saving to the system
class AutomationProcess(APIView):
def get(self, request):
return Response({
"response": "This API will be used for Automation process"
})
def post(self, request):
lecturer = request.data['lecturer']
subject = request.data['subject']
subject_code = request.data['subject_code']
video_length = request.data['video_length']
processed = ap.automation_process(lecturer=lecturer, subject=subject, subject_code=subject_code, video_length=video_length)
return Response({
"is_processed": processed
})
\ No newline at end of file
import requests
import json
from . logic import batch_process as bp
from MonitorLecturerApp.logic import lecturer_batch_process as lbp
import datetime
# this method will save the lecture video
#
# def save_student_lecture_video(student_video):
#
# data_dumps = json.dumps(student_video)
#
# headers = {
# 'Content-Type': 'application/json'
# }
#
# # call the API
# # student_video_save_resp = requests.post('http://127.0.0.1:8000/lecture-video', student_video)
# student_video_save_resp = requests.post(url='http://127.0.0.1:8000/lecture-video', data=data_dumps, headers=headers)
#
# data = student_video_save_resp.json()
#
# return data[0]
#
#
# # this method will save the lecturer video details
# def save_lecturer_video_details(video):
#
#
# headers = {
# "Content-Type": "application/json"
# }
#
# # convert the data into JSON string
# video_json_str = json.dumps(video)
#
# lecturer_video_resp = requests.post(url='http://127.0.0.1:8000/lecturer/lecturer-video/', data=video_json_str, headers=headers)
#
# response = lecturer_video_resp.json()
#
# return response[0]
# this method will handle the batch processing and video/audio saving pf the system
def automation_process(lecturer, subject, subject_code, video_length="00:20:00"):
current_date = datetime.datetime.now().date()
# this variable will be returned
is_all_processed = False
# define the video/audio names to be saved
student_video_name = str(current_date) + "_{}_student_video.mp4".format(subject_code)
lecturer_video_name = str(current_date) + "_{}_lecturer_video.mp4".format(subject_code)
lecturer_audio_name = str(current_date) + "_{}_lecturer_audio.wav".format(subject_code)
# this variable will be passed in the individual batch process
student_video_id = 0
# create the student video content
student_video_content = {
"lecturer": lecturer,
"subject": subject,
"date": str(current_date),
"video_name": student_video_name,
"video_length": video_length
}
# create the student video content
lecturer_video_content = {
"lecturer": lecturer,
"subject": subject,
"lecturer_date": str(current_date),
"lecture_video_name": lecturer_video_name,
"lecture_video_length": video_length
}
# create the lecturer audio
lecturer_audio_content = {}
# save the student video
student_video_response = bp.save_student_lecture_video(student_video_content)
# student_video_response = save_student_lecture_video(student_video_content)
student_video_id = student_video_response['id']
# save the lecturer video
lecturer_video_response = lbp.save_lecturer_video_details(lecturer_video_content)
# lecturer_video_response = save_lecturer_video_details(lecturer_video_content)
print('lecturer video response: ', lecturer_video_response)
# save the lecturer audio
# start the batch processing for lecture summarization component
# lecture_summary_batch_process = lecture_summarization_batch_process(audio_name)
lecture_summary_batch_process = True
# if the lecture summarization process is successful
# if lecture_summary_batch_process:
#
# # start the batch processing for monitoring lecturer performance component
# lecturer_batch_process_response = lecturer_batch_process(lecturer_video_name, lecturer_audio_name)
#
# # if the lecturer performance process is successful
# if lecturer_batch_process_response:
#
# # start the batch processing for monitoring student behavior component
# student_batch_process_response = student_behavior_batch_process(student_video_id, student_video_name)
#
# # if the student behavior process is successful
# if student_batch_process_response:
# is_all_processed = True
# return the status
return is_all_processed
# test the above method using 'main' method
# if __name__ == '__main__':
#
# lecturer = 1
# subject = 16
# subject_code = "IT1120"
#
# # call the method
# automation_process(lecturer, subject, subject_code)
...@@ -29,10 +29,11 @@ def student_behavior_batch_process(video_id, video_name): ...@@ -29,10 +29,11 @@ def student_behavior_batch_process(video_id, video_name):
return is_all_processed return is_all_processed
# this method will save the lecture video # this method will save the student lecture video
def save_student_lecture_video(student_video): def save_student_lecture_video(student_video):
data_dumps = json.dumps(student_video) data_dumps = json.dumps(student_video)
response = None
headers = { headers = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
...@@ -43,11 +44,12 @@ def save_student_lecture_video(student_video): ...@@ -43,11 +44,12 @@ def save_student_lecture_video(student_video):
student_video_save_resp = requests.post(url='http://127.0.0.1:8000/lecture-video', data=data_dumps, headers=headers) student_video_save_resp = requests.post(url='http://127.0.0.1:8000/lecture-video', data=data_dumps, headers=headers)
data = student_video_save_resp.json() data = student_video_save_resp.json()
response = data[0]
return data[0] return response
if __name__ == '__main__': # if __name__ == '__main__':
# content = { # content = {
# "lecturer": 1, # "lecturer": 1,
# "subject": 16, # "subject": 16,
...@@ -63,5 +65,5 @@ if __name__ == '__main__': ...@@ -63,5 +65,5 @@ if __name__ == '__main__':
# #
# save_student_lecture_video(content) # save_student_lecture_video(content)
student_behavior_batch_process(8, "Video_test_8.mp4") # student_behavior_batch_process(8, "Video_test_8.mp4")
...@@ -195,6 +195,9 @@ urlpatterns = [ ...@@ -195,6 +195,9 @@ urlpatterns = [
# perform random task (delete later) # perform random task (delete later)
url(r'^display-upcoming-lectures/$', api.DisplayUpcomingLecturesAPI.as_view()), url(r'^display-upcoming-lectures/$', api.DisplayUpcomingLecturesAPI.as_view()),
# perform random task (delete later)
url(r'^automation-process/', api.AutomationProcess.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