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

Committing the implementations of the django-background-tasks library.

parent fdd96901
import requests import requests
import json import json
from background_task import background
from .MongoModels import LectureVideo
from . logic import batch_process as bp from . logic import batch_process as bp
from MonitorLecturerApp.logic import lecturer_batch_process as lbp from MonitorLecturerApp.logic import lecturer_batch_process as lbp
import datetime import datetime
# this method will save the lecture video # this method will save the lecture video
# #
...@@ -43,6 +47,10 @@ import datetime ...@@ -43,6 +47,10 @@ import datetime
# return response[0] # return response[0]
# this method will handle the batch processing and video/audio saving pf the system # this method will handle the batch processing and video/audio saving pf the system
from .serializers import LectureVideoSerializer
# @background(schedule=5)
def automation_process(lecturer, subject, subject_code, video_length="00:20:00"): def automation_process(lecturer, subject, subject_code, video_length="00:20:00"):
current_date = datetime.datetime.now().date() current_date = datetime.datetime.now().date()
...@@ -80,10 +88,12 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00") ...@@ -80,10 +88,12 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00")
# create the lecturer audio # create the lecturer audio
lecturer_audio_content = {} lecturer_audio_content = {}
# save the student video # save the student video
student_video_response = bp.save_student_lecture_video(student_video_content) student_video_response = bp.save_student_lecture_video(student_video_content)
# student_video_response = save_student_lecture_video(student_video_content) # student_video_response = save_student_lecture_video(student_video_content)
student_video_id = student_video_response['id'] print('student video response: ', student_video_response)
# student_video_id = student_video_response['id']
# save the lecturer video # save the lecturer video
lecturer_video_response = lbp.save_lecturer_video_details(lecturer_video_content) lecturer_video_response = lbp.save_lecturer_video_details(lecturer_video_content)
...@@ -117,6 +127,7 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00") ...@@ -117,6 +127,7 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00")
# return the status # return the status
return is_all_processed return is_all_processed
# test the above method using 'main' method # test the above method using 'main' method
# if __name__ == '__main__': # if __name__ == '__main__':
# #
......
import requests import requests
import json import json
from background_task import background
def student_behavior_batch_process(video_id, video_name): def student_behavior_batch_process(video_id, video_name):
...@@ -30,6 +31,7 @@ def student_behavior_batch_process(video_id, video_name): ...@@ -30,6 +31,7 @@ def student_behavior_batch_process(video_id, video_name):
# this method will save the student lecture video # this method will save the student lecture video
# @background(schedule=5)
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)
......
...@@ -29,6 +29,7 @@ from django.contrib.auth import ( ...@@ -29,6 +29,7 @@ from django.contrib.auth import (
logout, logout,
) )
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from . serializers import * from . serializers import *
from . forms import * from . forms import *
import os import os
...@@ -232,8 +233,6 @@ def video_result(request): ...@@ -232,8 +233,6 @@ def video_result(request):
for item in to_do_lecture_list: for item in to_do_lecture_list:
isDate = item['date'] == str(day_timetable['date']) isDate = item['date'] == str(day_timetable['date'])
print('item date: ', item['date'])
print('timetable date: ', str(day_timetable['date']))
# isLecturer = item['lecturer'] == # isLecturer = item['lecturer'] ==
# check for the particular lecture on the day # check for the particular lecture on the day
if isDate: if isDate:
...@@ -246,6 +245,12 @@ def video_result(request): ...@@ -246,6 +245,12 @@ def video_result(request):
isLecturer = item['lecturer'] == slot['lecturer']['id'] isLecturer = item['lecturer'] == slot['lecturer']['id']
isSubject = item['subject'] == slot['subject']['id'] isSubject = item['subject'] == slot['subject']['id']
print('item lecturer: ', item['lecturer'])
print('timetable lecturer: ', slot['lecturer']['id'])
print('item subject: ', item['subject'])
print('timetable subject: ', slot['subject']['id'])
if isLecturer & isSubject: if isLecturer & isSubject:
obj = {} obj = {}
obj['date'] = item['date'] obj['date'] = item['date']
......
...@@ -43,7 +43,8 @@ INSTALLED_APPS = [ ...@@ -43,7 +43,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'bootstrap4', 'bootstrap4',
'rest_framework', 'rest_framework',
'os' 'os',
'background_task'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -25,5 +25,5 @@ urlpatterns = [ ...@@ -25,5 +25,5 @@ urlpatterns = [
path('lecturer/', include('MonitorLecturerApp.urls')), path('lecturer/', include('MonitorLecturerApp.urls')),
# path('lecturer/', include('MonitorLecturerApp.urls')), # path('lecturer/', include('MonitorLecturerApp.urls')),
path('summary/', include('LectureSummarizingApp.urls')), path('summary/', include('LectureSummarizingApp.urls')),
path('record/', include('LectureSummarizingApp.urls')) path('record/', include('LectureSummarizingApp.urls')),
] ]
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