Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
069680f0
Commit
069680f0
authored
Jan 08, 2021
by
I.K Seneviratne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Committing the implementations of APscheduler background task.
parent
aa31a5c7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
37 deletions
+140
-37
FirstApp/api.py
FirstApp/api.py
+62
-20
FirstApp/automation_process.py
FirstApp/automation_process.py
+10
-2
FirstApp/logic/scheduler_tasks.py
FirstApp/logic/scheduler_tasks.py
+25
-0
FirstApp/templates/FirstApp/video_results.html
FirstApp/templates/FirstApp/video_results.html
+24
-12
FirstApp/views.py
FirstApp/views.py
+19
-2
integrated_slpes/settings.py
integrated_slpes/settings.py
+0
-1
No files found.
FirstApp/api.py
View file @
069680f0
...
...
@@ -11,11 +11,16 @@ each method will return an HttpResponse that allows its data to be rendered into
arbitrary media types.
"""
import
json
from
random
import
Random
from
apscheduler.jobstores.mongodb
import
MongoDBJobStore
from
MonitorLecturerApp.models
import
LectureRecordedVideo
,
LecturerVideoMetaData
from
MonitorLecturerApp.serializers
import
LectureRecordedVideoSerializer
,
LecturerVideoMetaDataSerializer
from
rest_framework.views
import
*
from
integrated_slpes.wsgi
import
application
from
.logic
import
activity_recognition
as
ar
from
.
import
emotion_detector
as
ed
,
automation_process
as
ap
from
.logic
import
id_generator
as
ig
...
...
@@ -23,10 +28,15 @@ from .logic import pdf_file_generator as pdf
from
.logic
import
head_gaze_estimation
as
hge
from
.logic
import
video_extraction
as
ve
from
.
logic
import
student_behavior_process
as
sbp
from
.logic.scheduler_tasks
import
task_scheduler
from
.serializers
import
*
from
braces.views
import
CsrfExemptMixin
from
django.core.handlers.wsgi
import
WSGIRequest
from
django.http.request
import
HttpRequest
import
datetime
import
os
class
LectureViewSet
(
APIView
):
...
...
@@ -1539,19 +1549,36 @@ class CheckStudentBehaviorAvailability(APIView):
def
get
(
self
,
request
):
video_name
=
request
.
query_params
.
get
(
'video_name'
)
#
# isActivityExist = LectureActivityFrameGroupings.objects.filter(
# lecture_activity_id__lecture_video_id__video_name=video_name).exists()
#
# isEmotionExist = LectureEmotionFrameGroupings.objects.filter(
# lecture_emotion_id__lecture_video_id__video_name=video_name).exists()
#
# isGazeExist = LectureGazeFrameGroupings.objects.filter(
# lecture_gaze_id__lecture_video_id__video_name=video_name).exists()
print
(
'video name: '
,
video_name
)
# retrieve the 'MongoDbJobStore' instance
jobs
=
MongoDBJobStore
()
.
get_all_jobs
()
print
(
'jobs: '
,
jobs
)
# initialize the variables
isActivityExist
=
False
isEmotionExist
=
False
isGazeExist
=
False
# if there are scheduled jobs
if
len
(
jobs
)
>
0
:
isActivityExist
=
bool
(
Random
()
.
randint
(
0
,
2
))
isEmotionExist
=
bool
(
Random
()
.
randint
(
0
,
2
))
isGazeExist
=
bool
(
Random
()
.
randint
(
0
,
2
))
# retrieve the activity frame groupings
isActivityExist
=
LectureActivityFrameGroupings
.
objects
.
filter
(
lecture_activity_id__lecture_video_id__video_name
=
video_name
)
.
exists
()
# retrieve the emotion frame groupings
isEmotionExist
=
LectureEmotionFrameGroupings
.
objects
.
filter
(
lecture_emotion_id__lecture_video_id__video_name
=
video_name
)
.
exists
()
# retrieve the gaze frame groupings
isGazeExist
=
LectureGazeFrameGroupings
.
objects
.
filter
(
lecture_gaze_id__lecture_video_id__video_name
=
video_name
)
.
exists
()
else
:
isActivityExist
=
True
isEmotionExist
=
True
isGazeExist
=
True
# isActivityExist = bool(Random().randint(0,2))
# isEmotionExist = bool(Random().randint(0,2))
# isGazeExist = bool(Random().randint(0,2))
return
Response
({
"isActivityExist"
:
isActivityExist
,
...
...
@@ -1657,13 +1684,28 @@ class AutomationProcess(APIView):
})
def
post
(
self
,
request
):
processed
=
False
try
:
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
)
# processed = ap.automation_process(lecturer=lecturer, subject=subject, subject_code=subject_code, video_length=video_length)
# run the scheduler
scheduler
=
task_scheduler
(
lecturer
=
lecturer
,
subject
=
subject
,
subject_code
=
subject_code
,
video_length
=
video_length
)
processed
=
True
return
Response
({
"is_processed"
:
processed
,
})
except
Exception
as
exc
:
print
(
'Exception: '
,
exc
)
return
Response
({
"is_processed"
:
processed
"is_processed"
:
processed
,
})
\ No newline at end of file
FirstApp/automation_process.py
View file @
069680f0
import
requests
import
json
from
background_task
import
background
from
.MongoModels
import
LectureVideo
from
.
logic
import
batch_process
as
bp
...
...
@@ -47,6 +46,7 @@ import datetime
# return response[0]
# this method will handle the batch processing and video/audio saving pf the system
from
.logic.batch_process
import
student_behavior_batch_process
from
.serializers
import
LectureVideoSerializer
...
...
@@ -63,6 +63,7 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00")
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
...
...
@@ -93,7 +94,7 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00")
student_video_response
=
bp
.
save_student_lecture_video
(
student_video_content
)
# student_video_response = save_student_lecture_video(student_video_content)
print
(
'student video response: '
,
student_video_response
)
#
student_video_id = student_video_response['id']
student_video_id
=
student_video_response
[
'id'
]
# save the lecturer video
lecturer_video_response
=
lbp
.
save_lecturer_video_details
(
lecturer_video_content
)
...
...
@@ -103,6 +104,13 @@ def automation_process(lecturer, subject, subject_code, video_length="00:20:00")
# save the lecturer audio
for
i
in
range
(
100
):
print
(
'outer loop: '
,
i
)
for
j
in
range
(
10000
):
print
(
'inner loop: '
,
j
)
# start the batch processing for lecture summarization component
# lecture_summary_batch_process = lecture_summarization_batch_process(audio_name)
lecture_summary_batch_process
=
True
...
...
FirstApp/logic/scheduler_tasks.py
0 → 100644
View file @
069680f0
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
apscheduler.jobstores.mongodb
import
MongoDBJobStore
import
datetime
as
d
from
datetime
import
datetime
# this method will schedule the automation process task
from
FirstApp.automation_process
import
automation_process
def
task_scheduler
(
lecturer
,
subject
,
subject_code
,
video_length
):
jobstores
=
{
'mongo'
:
MongoDBJobStore
(),
}
sched
=
BackgroundScheduler
(
jobstores
=
jobstores
)
after_20s
=
datetime
.
now
()
+
d
.
timedelta
(
seconds
=
30
)
sched
.
add_job
(
automation_process
,
args
=
[
lecturer
,
subject
,
subject_code
,
video_length
],
trigger
=
'date'
,
run_date
=
after_20s
,
id
=
'Automation_1'
)
sched
.
start
()
job
=
sched
.
get_job
(
job_id
=
'Automation_1'
)
MongoDBJobStore
()
.
add_job
(
job
=
job
)
return
sched
\ No newline at end of file
FirstApp/templates/FirstApp/video_results.html
View file @
069680f0
...
...
@@ -40,7 +40,7 @@
$
(
document
).
ready
(
function
()
{
let
folder
=
''
;
{
#
$
(
'
#activity_loader
'
).
attr
(
'
hidden
'
,
false
);
#
}
$
(
'
#activity_loader
'
).
attr
(
'
hidden
'
,
false
);
{
#
$
(
'
#emotion_loader
'
).
attr
(
'
hidden
'
,
false
);
#
}
{
#
$
(
'
#gaze_loader
'
).
attr
(
'
hidden
'
,
false
);
#
}
...
...
@@ -297,20 +297,30 @@
}
}
//this is a test function (delete later)
/*
let interval = setInterval(() => {
setInterval(() => {
let time = new Date().getTime();
alert('time: ', time);
{#let url = 'http://127.0.0.1:8000/get-random_number';#}
let url = 'http://127.0.0.1:8000/check-availability';
}, 5000);
*/
//this is a test function (delete later)
//get the due lecture video name
var
due_lecture_video_name
=
"
{{ due_lecture_video_name }}
"
;
let
interval
=
setInterval
(()
=>
{
let
url
=
'
http://127.0.0.1:8000/check-availability/?video_name=
'
+
due_lecture_video_name
;
fetch
(
url
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
out
)
=>
displayProcess
(
out
))
.
catch
((
err
)
=>
alert
(
'
error:
'
+
err
))
},
10
000);
},
5
000
);
//this function will handle the displaying loaders and status in the workflow
...
...
@@ -356,7 +366,8 @@
}
*/
});
...
...
@@ -440,11 +451,12 @@
<td
class=
"font-weight-bolder"
>
{{ lecture.start_time }}
</td>
<td
class=
"font-weight-bolder"
>
{{ lecture.end_time }}
</td>
<td>
<button
type=
"button"
class=
"btn btn-success batch_process"
data-video-id=
"{{ lecture.video_id }}"
data-video-name=
"{{ lecture.video_name }}"
id=
"{{ lecture.subject }}"
>
Process
</button>
<span
class=
"font-italic text-success"
>
Processing
</span>
{#
<button
type=
"button"
class=
"btn btn-success batch_process"
#
}
{
#
data-video-id=
"{{ lecture.video_id }}"
#
}
{
#
data-video-name=
"{{ lecture.video_name }}"
#
}
{
#
id=
"{{ lecture.subject }}"
>
Process#}
{#
</button>
#}
{#
<span
class=
"font-italic font-weight-bolder text-success"
>
Processing
</span>
#}
</td>
</tr>
...
...
FirstApp/views.py
View file @
069680f0
...
...
@@ -33,8 +33,14 @@ from django.contrib.auth.decorators import login_required
from
.
serializers
import
*
from
.
forms
import
*
import
os
import
datetime
as
d
from
datetime
import
datetime
from
apscheduler.schedulers.background
import
BackgroundScheduler
from
apscheduler.triggers.date
import
DateTrigger
from
apscheduler.jobstores.mongodb
import
MongoDBJobStore
# Create your views here.
...
...
@@ -54,6 +60,11 @@ def hello(request):
print
(
'user_type: '
,
user_type
)
print
(
'request type: '
,
type
(
request
))
# test the scheduler
# test_scheduler()
# retrieve the lecturer's timetable slots
lecturer_timetable
=
FacultyTimetable
.
objects
.
filter
()
...
...
@@ -123,6 +134,7 @@ def hello(request):
return
redirect
(
'/401'
)
except
Exception
as
exc
:
print
(
'exception: '
,
exc
)
return
redirect
(
'/500'
)
# this method will handle 404 error page
...
...
@@ -270,13 +282,17 @@ def video_result(request):
# handling the general exceptions
except
Exception
as
exc
:
print
(
'
what is wrong?
: '
,
exc
)
print
(
'
Exception
: '
,
exc
)
return
redirect
(
'/500'
)
print
(
'due lectures: '
,
due_lecture_list
)
due_lecture_video_name
=
due_lecture_list
[
0
][
'video_name'
]
if
len
(
due_lecture_list
)
>
0
else
"Test.mp4"
# due_lecture_video_name = "Test.mp4"
print
(
'due lecture video name: '
,
due_lecture_video_name
)
return
render
(
request
,
"FirstApp/video_results.html"
,
{
"lecturer"
:
lecturer
,
"due_lectures"
:
due_lecture_list
})
{
"lecturer"
:
lecturer
,
"due_lectures"
:
due_lecture_list
,
"due_lecture_video_name"
:
due_lecture_video_name
})
# view for emotion page
...
...
@@ -382,6 +398,7 @@ def activity(request):
# handling the general exception
except
Exception
as
exc
:
print
(
'exception: '
,
exc
)
return
redirect
(
'/500'
)
return
render
(
request
,
"FirstApp/activity.html"
,
{
"lecturer_subjects"
:
lecturer_subjects
,
"subjects"
:
subject_list
,
"lecturer"
:
lecturer
})
...
...
integrated_slpes/settings.py
View file @
069680f0
...
...
@@ -44,7 +44,6 @@ INSTALLED_APPS = [
'bootstrap4'
,
'rest_framework'
,
'os'
,
'background_task'
]
MIDDLEWARE
=
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment