Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
40038e7c
Commit
40038e7c
authored
Aug 13, 2014
by
Zia Fazal
Committed by
Jonathan Piacenti
Aug 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ziafazal/api-fix-bug-progress-tab: Made no of completions as percentage
support for coverage guard against no completions
parent
b69d526a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
lms/djangoapps/api_manager/courses/serializers.py
+13
-2
lms/djangoapps/api_manager/courses/tests.py
+2
-2
lms/djangoapps/api_manager/courses/views.py
+9
-5
No files found.
lms/djangoapps/api_manager/courses/serializers.py
View file @
40038e7c
...
...
@@ -34,7 +34,7 @@ class CourseLeadersSerializer(serializers.Serializer):
formats points_scored to two decimal points
"""
points_scored
=
obj
[
'points_scored'
]
or
0
return
round
(
points_scored
,
2
)
return
int
(
round
(
points_scored
)
)
class
CourseCompletionsLeadersSerializer
(
serializers
.
Serializer
):
...
...
@@ -43,7 +43,18 @@ class CourseCompletionsLeadersSerializer(serializers.Serializer):
username
=
serializers
.
CharField
(
source
=
'user__username'
)
title
=
serializers
.
CharField
(
source
=
'user__profile__title'
)
avatar_url
=
serializers
.
CharField
(
source
=
'user__profile__avatar_url'
)
completions
=
serializers
.
IntegerField
()
completions
=
serializers
.
SerializerMethodField
(
'get_completion_percentage'
)
def
get_completion_percentage
(
self
,
obj
):
"""
formats get completions as percentage
"""
total_completions
=
self
.
context
[
'total_completions'
]
or
0
completions
=
obj
[
'completions'
]
or
0
completion_percentage
=
0
if
total_completions
>
0
:
completion_percentage
=
int
(
round
(
100
*
completions
/
total_completions
))
return
completion_percentage
class
CourseSerializer
(
serializers
.
Serializer
):
...
...
lms/djangoapps/api_manager/courses/tests.py
View file @
40038e7c
...
...
@@ -1571,7 +1571,7 @@ class CoursesApiTests(TestCase):
self
.
assertEqual
(
len
(
response
.
data
[
'leaders'
]),
3
)
self
.
assertEqual
(
response
.
data
[
'course_avg'
],
3.4
)
self
.
assertEqual
(
response
.
data
[
'position'
],
2
)
self
.
assertEqual
(
response
.
data
[
'points'
],
4.
5
)
self
.
assertEqual
(
response
.
data
[
'points'
],
5
)
# Filter by user who has never accessed a course module
test_user
=
UserFactory
.
create
(
username
=
"testusernocoursemod"
)
...
...
@@ -1656,7 +1656,7 @@ class CoursesApiTests(TestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
response
.
data
[
'leaders'
]),
3
)
self
.
assertEqual
(
response
.
data
[
'position'
],
1
)
self
.
assertEqual
(
response
.
data
[
'completions'
],
1
0
)
self
.
assertEqual
(
response
.
data
[
'completions'
],
4
0
)
# test with bogus course
test_uri
=
'{}/{}/metrics/completions/leaders/'
.
format
(
self
.
base_courses_uri
,
self
.
test_bogus_course_id
)
...
...
lms/djangoapps/api_manager/courses/views.py
View file @
40038e7c
...
...
@@ -1558,7 +1558,7 @@ class CoursesLeadersList(SecureListAPIView):
filter
(
points__gt
=
user_points
)
.
exclude
(
student__id
=
user_id
)
.
count
()
# excluding user to overcome
# float comparison bug
data
[
'position'
]
=
users_above
+
1
data
[
'points'
]
=
user_points
data
[
'points'
]
=
int
(
round
(
user_points
))
points
=
queryset
.
aggregate
(
total
=
Sum
(
'grade'
))
if
points
and
points
[
'total'
]
is
not
None
:
...
...
@@ -1607,15 +1607,18 @@ class CoursesCompletionsLeadersList(SecureAPIView):
exclude_users
=
_get_aggregate_exclusion_user_ids
(
course_key
)
queryset
=
CourseModuleCompletion
.
objects
.
filter
(
course_id
=
course_key
)
\
.
exclude
(
user__in
=
exclude_users
)
total_completions
=
queryset
.
filter
(
user__is_active
=
True
)
.
count
()
if
user_id
:
user_completions
=
queryset
.
filter
(
user__id
=
user_id
)
.
count
()
completions_above_user
=
queryset
.
filter
(
user__is_active
=
True
)
.
values
(
'user__id'
)
\
.
annotate
(
completions
=
Count
(
'content_id'
))
.
filter
(
completions__gt
=
user_completions
)
.
count
()
data
[
'position'
]
=
completions_above_user
+
1
data
[
'completions'
]
=
user_completions
completion_percentage
=
0
if
total_completions
>
0
:
completion_percentage
=
int
(
round
(
100
*
user_completions
/
total_completions
))
data
[
'completions'
]
=
completion_percentage
total_completions
=
queryset
.
filter
(
user__is_active
=
True
)
.
count
()
total_users
=
CourseEnrollment
.
users_enrolled_in
(
course_key
)
.
exclude
(
id__in
=
exclude_users
)
.
count
()
if
total_users
:
course_avg
=
round
(
total_completions
/
float
(
total_users
),
1
)
...
...
@@ -1623,8 +1626,9 @@ class CoursesCompletionsLeadersList(SecureAPIView):
queryset
=
queryset
.
filter
(
user__is_active
=
True
)
.
values
(
'user__id'
,
'user__username'
,
'user__profile__title'
,
'user__profile__avatar_url'
)
\
.
annotate
(
completions
=
Count
(
'content_id'
))
.
order_by
(
'-completions'
)[:
count
]
serializer
=
CourseCompletionsLeadersSerializer
(
queryset
,
many
=
True
)
.
annotate
(
completions
=
Count
(
'content_id'
))
.
order_by
(
'-completions'
)[:
count
]
serializer
=
CourseCompletionsLeadersSerializer
(
queryset
,
many
=
True
,
context
=
{
'total_completions'
:
total_completions
})
data
[
'leaders'
]
=
serializer
.
data
# pylint: disable=E1101
return
Response
(
data
,
status
=
status
.
HTTP_200_OK
)
...
...
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