Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-proctoring
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
edx-proctoring
Commits
a0b4621f
Commit
a0b4621f
authored
Aug 12, 2015
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add computed remaining time to the API result set
parent
f33e09d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
edx_proctoring/utils.py
+20
-0
edx_proctoring/views.py
+11
-11
No files found.
edx_proctoring/utils.py
View file @
a0b4621f
...
...
@@ -2,6 +2,9 @@
Helpers for the HTTP APIs
"""
import
pytz
from
datetime
import
datetime
,
timedelta
from
django.utils.translation
import
ugettext
as
_
from
rest_framework.views
import
APIView
from
rest_framework.authentication
import
SessionAuthentication
...
...
@@ -16,6 +19,23 @@ class AuthenticatedAPIView(APIView):
permission_classes
=
(
IsAuthenticated
,)
def
get_time_remaining_for_attempt
(
attempt
):
"""
Returns the remaining time (in seconds) on an attempt
"""
# need to adjust for allowances
expires_at
=
attempt
[
'started_at'
]
+
timedelta
(
minutes
=
attempt
[
'allowed_time_limit_mins'
])
now_utc
=
datetime
.
now
(
pytz
.
UTC
)
if
expires_at
>
now_utc
:
time_remaining_seconds
=
(
expires_at
-
now_utc
)
.
seconds
else
:
time_remaining_seconds
=
0
return
time_remaining_seconds
def
humanized_time
(
time_in_minutes
):
"""
Converts the given value in minutes to a more human readable format
...
...
edx_proctoring/views.py
View file @
a0b4621f
...
...
@@ -4,7 +4,7 @@ Proctored Exams HTTP-based API endpoints
import
logging
import
pytz
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
from
django.utils.decorators
import
method_decorator
from
django.conf
import
settings
...
...
@@ -42,7 +42,7 @@ from edx_proctoring.exceptions import (
from
edx_proctoring.serializers
import
ProctoredExamSerializer
from
edx_proctoring.models
import
ProctoredExamStudentAttemptStatus
from
.utils
import
AuthenticatedAPIView
from
.utils
import
AuthenticatedAPIView
,
get_time_remaining_for_attempt
ATTEMPTS_PER_PAGE
=
25
...
...
@@ -266,7 +266,9 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
attempt_id
=
attempt_id
)
)
raise
StudentExamAttemptDoesNotExistsException
(
err_msg
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
# make sure the the attempt belongs to the calling user_id
if
attempt
[
'user'
][
'id'
]
!=
request
.
user
.
id
:
...
...
@@ -291,6 +293,11 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
ProctoredExamStudentAttemptStatus
.
error
)
# add in the computed time remaining as a helper to a client app
time_remaining_seconds
=
get_time_remaining_for_attempt
(
attempt
)
attempt
[
'time_remaining_seconds'
]
=
time_remaining_seconds
return
Response
(
data
=
attempt
,
status
=
status
.
HTTP_200_OK
...
...
@@ -485,14 +492,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
exam
=
exam_info
[
'exam'
]
attempt
=
exam_info
[
'attempt'
]
# need to adjust for allowances
expires_at
=
attempt
[
'started_at'
]
+
timedelta
(
minutes
=
attempt
[
'allowed_time_limit_mins'
])
now_utc
=
datetime
.
now
(
pytz
.
UTC
)
if
expires_at
>
now_utc
:
time_remaining_seconds
=
(
expires_at
-
now_utc
)
.
seconds
else
:
time_remaining_seconds
=
0
time_remaining_seconds
=
get_time_remaining_for_attempt
(
attempt
)
proctoring_settings
=
getattr
(
settings
,
'PROCTORING_SETTINGS'
,
{})
low_threshold_pct
=
proctoring_settings
.
get
(
'low_threshold_pct'
,
.
2
)
...
...
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