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
522cdd21
Commit
522cdd21
authored
Jul 03, 2013
by
Miles Steele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor distributions (minor)
parent
0d6a12fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
24 deletions
+7
-24
lms/djangoapps/analytics/distributions.py
+5
-15
lms/djangoapps/analytics/tests/test_distributions.py
+2
-9
No files found.
lms/djangoapps/analytics/distributions.py
View file @
522cdd21
...
...
@@ -5,7 +5,9 @@ Profile Distributions
from
django.db.models
import
Count
from
student.models
import
CourseEnrollment
,
UserProfile
AVAILABLE_PROFILE_FEATURES
=
[
'gender'
,
'level_of_education'
,
'year_of_birth'
]
_EASY_CHOICE_FEATURES
=
(
'gender'
,
'level_of_education'
)
_OPEN_CHOICE_FEATURES
=
(
'year_of_birth'
,)
AVAILABLE_PROFILE_FEATURES
=
_EASY_CHOICE_FEATURES
+
_OPEN_CHOICE_FEATURES
def
profile_distribution
(
course_id
,
feature
):
...
...
@@ -26,24 +28,16 @@ def profile_distribution(course_id, feature):
OPEN_CHOICE - choices with a larger domain e.g. year_of_birth
"""
EASY_CHOICE_FEATURES
=
[
'gender'
,
'level_of_education'
]
OPEN_CHOICE_FEATURES
=
[
'year_of_birth'
]
def
raise_not_implemented
():
raise
NotImplementedError
(
"feature requested not implemented but is advertised in AVAILABLE_PROFILE_FEATURES {}"
.
format
(
feature
))
feature_results
=
{}
if
not
feature
in
AVAILABLE_PROFILE_FEATURES
:
raise
ValueError
(
"unsupported feature requested for distribution '{}'"
.
format
(
feature
))
if
feature
in
EASY_CHOICE_FEATURES
:
if
feature
in
_
EASY_CHOICE_FEATURES
:
if
feature
==
'gender'
:
raw_choices
=
UserProfile
.
GENDER_CHOICES
elif
feature
==
'level_of_education'
:
raw_choices
=
UserProfile
.
LEVEL_OF_EDUCATION_CHOICES
else
:
raise
raise_not_implemented
()
choices
=
[(
short
,
full
)
for
(
short
,
full
)
in
raw_choices
]
+
[(
'no_data'
,
'No Data'
)]
...
...
@@ -53,14 +47,12 @@ def profile_distribution(course_id, feature):
count
=
CourseEnrollment
.
objects
.
filter
(
course_id
=
course_id
,
user__profile__gender
=
short
)
.
count
()
elif
feature
==
'level_of_education'
:
count
=
CourseEnrollment
.
objects
.
filter
(
course_id
=
course_id
,
user__profile__level_of_education
=
short
)
.
count
()
else
:
raise
raise_not_implemented
()
data
[
short
]
=
count
feature_results
[
'data'
]
=
data
feature_results
[
'type'
]
=
'EASY_CHOICE'
feature_results
[
'display_names'
]
=
dict
(
choices
)
elif
feature
in
OPEN_CHOICE_FEATURES
:
elif
feature
in
_
OPEN_CHOICE_FEATURES
:
profiles
=
UserProfile
.
objects
.
filter
(
user__courseenrollment__course_id
=
course_id
)
query_distribution
=
profiles
.
values
(
feature
)
.
annotate
(
Count
(
feature
))
.
order_by
()
# query_distribution is of the form [{'featureval': 'value1', 'featureval__count': 4}, {'featureval': 'value2', 'featureval__count': 2}, ...]
...
...
@@ -77,7 +69,5 @@ def profile_distribution(course_id, feature):
feature_results
[
'data'
]
=
distribution
feature_results
[
'type'
]
=
'OPEN_CHOICE'
else
:
raise
raise_not_implemented
()
return
feature_results
lms/djangoapps/analytics/tests/test_distributions.py
View file @
522cdd21
...
...
@@ -14,10 +14,10 @@ class TestAnalyticsDistributions(TestCase):
def
setUp
(
self
):
self
.
course_id
=
'some/robot/course/id'
self
.
users
=
tuple
(
UserFactory
(
self
.
users
=
[
UserFactory
(
profile__gender
=
[
'm'
,
'f'
,
'o'
][
i
%
3
],
profile__year_of_birth
=
i
+
1930
)
for
i
in
xrange
(
30
)
)
)
for
i
in
xrange
(
30
)
]
self
.
ces
=
tuple
(
CourseEnrollment
.
objects
.
create
(
course_id
=
self
.
course_id
,
user
=
user
)
for
user
in
self
.
users
)
...
...
@@ -27,13 +27,6 @@ class TestAnalyticsDistributions(TestCase):
self
.
assertNotIn
(
feature
,
AVAILABLE_PROFILE_FEATURES
)
profile_distribution
(
self
.
course_id
,
feature
)
@raises
(
NotImplementedError
)
def
test_profile_distribution_not_implemented_feature
(
self
):
feature
=
'ROBOT_DO_NOT_USE_FEATURE'
AVAILABLE_PROFILE_FEATURES
.
append
(
feature
)
self
.
assertIn
(
feature
,
AVAILABLE_PROFILE_FEATURES
)
profile_distribution
(
self
.
course_id
,
feature
)
def
test_profile_distribution_easy_choice
(
self
):
feature
=
'gender'
self
.
assertIn
(
feature
,
AVAILABLE_PROFILE_FEATURES
)
...
...
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