Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api
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-analytics-data-api
Commits
0674b790
Commit
0674b790
authored
Aug 28, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19 from edx/geo-filter
Excluding non-ISO-3166-compliant data
parents
77c70aa1
c38e220a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
1 deletions
+33
-1
analytics_data_api/v0/models.py
+5
-1
analytics_data_api/v0/tests/test_models.py
+10
-0
analytics_data_api/v0/tests/test_views.py
+7
-0
analytics_data_api/v0/views/courses.py
+11
-0
No files found.
analytics_data_api/v0/models.py
View file @
0674b790
...
@@ -104,7 +104,11 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment):
...
@@ -104,7 +104,11 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment):
"""
"""
Returns a Country object representing the country in this model's country_code.
Returns a Country object representing the country in this model's country_code.
"""
"""
return
countries
.
get
(
self
.
country_code
)
try
:
return
countries
.
get
(
self
.
country_code
)
except
(
KeyError
,
ValueError
):
# Country code is not valid ISO-3166
return
None
class
Meta
(
BaseCourseEnrollment
.
Meta
):
class
Meta
(
BaseCourseEnrollment
.
Meta
):
db_table
=
'course_enrollment_location_current'
db_table
=
'course_enrollment_location_current'
...
...
analytics_data_api/v0/tests/test_models.py
View file @
0674b790
...
@@ -23,3 +23,13 @@ class CourseEnrollmentByCountryTests(TestCase):
...
@@ -23,3 +23,13 @@ class CourseEnrollmentByCountryTests(TestCase):
self
.
assertEqual
(
country
.
alpha2
,
'US'
)
self
.
assertEqual
(
country
.
alpha2
,
'US'
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
country
.
alpha2
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
country
.
alpha2
)
self
.
assertEqual
(
instance
.
country
,
country
)
self
.
assertEqual
(
instance
.
country
,
country
)
def
test_invalid_country
(
self
):
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
''
)
self
.
assertIsNone
(
instance
.
country
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
'A1'
)
self
.
assertIsNone
(
instance
.
country
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
'GobbledyGoop!'
)
self
.
assertIsNone
(
instance
.
country
)
analytics_data_api/v0/tests/test_views.py
View file @
0674b790
...
@@ -299,6 +299,7 @@ class CourseEnrollmentByLocationViewTests(TestCaseWithAuthentication, CourseEnro
...
@@ -299,6 +299,7 @@ class CourseEnrollmentByLocationViewTests(TestCaseWithAuthentication, CourseEnro
model
=
models
.
CourseEnrollmentByCountry
model
=
models
.
CourseEnrollmentByCountry
def
get_expected_response
(
self
,
*
args
):
def
get_expected_response
(
self
,
*
args
):
args
=
[
arg
for
arg
in
args
if
arg
.
country_code
not
in
[
''
,
'A1'
,
'A2'
,
'AP'
,
'EU'
,
'O1'
,
'UNKNOWN'
]]
args
=
sorted
(
args
,
key
=
lambda
item
:
(
item
.
date
,
item
.
course_id
,
item
.
country
.
alpha3
))
args
=
sorted
(
args
,
key
=
lambda
item
:
(
item
.
date
,
item
.
course_id
,
item
.
country
.
alpha3
))
return
[
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
...
@@ -313,3 +314,9 @@ class CourseEnrollmentByLocationViewTests(TestCaseWithAuthentication, CourseEnro
...
@@ -313,3 +314,9 @@ class CourseEnrollmentByLocationViewTests(TestCaseWithAuthentication, CourseEnro
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'US'
,
count
=
455
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'US'
,
count
=
455
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'CA'
,
count
=
356
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'CA'
,
count
=
356
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'IN'
,
count
=
12
,
date
=
cls
.
date
-
datetime
.
timedelta
(
days
=
29
))
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'IN'
,
count
=
12
,
date
=
cls
.
date
-
datetime
.
timedelta
(
days
=
29
))
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
''
,
count
=
356
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'A1'
,
count
=
1
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'A2'
,
count
=
2
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'AP'
,
count
=
1
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'EU'
,
count
=
4
,
date
=
cls
.
date
)
G
(
cls
.
model
,
course_id
=
cls
.
course_id
,
country_code
=
'O1'
,
count
=
7
,
date
=
cls
.
date
)
analytics_data_api/v0/views/courses.py
View file @
0674b790
...
@@ -214,3 +214,14 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
...
@@ -214,3 +214,14 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
serializer_class
=
serializers
.
CourseEnrollmentByCountrySerializer
serializer_class
=
serializers
.
CourseEnrollmentByCountrySerializer
model
=
models
.
CourseEnrollmentByCountry
model
=
models
.
CourseEnrollmentByCountry
def
get_queryset
(
self
):
queryset
=
super
(
CourseEnrollmentByLocationView
,
self
)
.
get_queryset
()
# Remove all items where country is None
items
=
[
item
for
item
in
queryset
.
all
()
if
item
.
country
is
not
None
]
# Note: We are returning a list, instead of a queryset. This is
# acceptable since the consuming code simply expects the returned
# value to be iterable, not necessarily a queryset.
return
items
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